001 /* 002 * This file is part of the Jikes RVM project (http://jikesrvm.org). 003 * 004 * This file is licensed to You under the Eclipse Public License (EPL); 005 * You may not use this file except in compliance with the License. You 006 * may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/eclipse-1.0.php 009 * 010 * See the COPYRIGHT.txt file distributed with this work for information 011 * regarding copyright ownership. 012 */ 013 package org.jikesrvm.mm.mmtk; 014 015 import org.mmtk.utility.Constants; 016 import org.mmtk.utility.statistics.PerfEvent; 017 import org.jikesrvm.runtime.Time; 018 import static org.jikesrvm.runtime.SysCall.sysCall; 019 020 import org.vmmagic.pragma.*; 021 022 @Uninterruptible 023 public final class Statistics extends org.mmtk.vm.Statistics implements Constants { 024 025 /** 026 * Read nanoTime (high resolution, monotonically increasing clock). 027 * Has same semantics as java.lang.System.nanoTime(). 028 */ 029 @Override 030 public long nanoTime() { 031 return Time.nanoTime(); 032 } 033 034 /** 035 * Read a cycle counter (high resolution, non-monotonic clock). 036 * This method should be used with care as the cycle counters (especially on IA32 SMP machines) 037 * are not a reliably time source. 038 */ 039 @Override 040 public long cycles() { 041 return Time.cycles(); 042 } 043 044 @Override 045 public double nanosToMillis(long c) { 046 return (c)/1e6; 047 } 048 049 @Override 050 public double nanosToSecs(long c) { 051 return (c)/1e9; 052 } 053 054 @Override 055 public long millisToNanos(double t) { 056 return (long)(t * 1e6); 057 } 058 059 @Override 060 public long secsToNanos(double t) { 061 return (long)(t * 1e9); 062 } 063 064 private PerfEvent[] perfEvents; 065 066 @Override 067 @Interruptible 068 public void perfEventInit(String events) { 069 if (events.length() == 0) { 070 // no initialization needed 071 return; 072 } 073 // initialize perf event 074 String[] perfEventNames = events.split(","); 075 int n = perfEventNames.length; 076 sysCall.sysPerfEventInit(n); 077 perfEvents = new PerfEvent[n]; 078 for (int i = 0; i < n; i++) { 079 sysCall.sysPerfEventCreate(i, perfEventNames[i].concat("\0").getBytes()); 080 perfEvents[i] = new PerfEvent(i, perfEventNames[i]); 081 } 082 sysCall.sysPerfEventEnable(); 083 } 084 085 /** 086 * Read a performance event 087 */ 088 @Override 089 public void perfEventRead(int id, long[] values) { 090 sysCall.sysPerfEventRead(id, values); 091 } 092 } 093