25 import java.io.PrintWriter;
26 import utils.HrtStopwatch;
28 import java.lang.management.ThreadMXBean;
29 import java.lang.management.ManagementFactory;
33 static protected final PrintWriter out =
new PrintWriter(System.out,
true);
35 static protected final PrintWriter err =
new PrintWriter(System.err,
true);
41 out.print(
"loading libary ...");
44 System.loadLibrary(name);
45 }
catch (UnsatisfiedLinkError e) {
48 path = System.getProperty(
"java.library.path");
49 }
catch (Exception ex) {
50 path =
"<exception caught: " + ex.getMessage() +
">";
52 err.println(
"failed loading library '"
53 + name +
"'; java.library.path='" + path +
"'");
55 }
catch (SecurityException e) {
56 err.println(
"failed loading library '"
57 + name +
"'; caught exception: " + e);
60 out.println(
" [" + name +
"]");
63 static public native
void aNativeMethod();
65 static public volatile long dummy;
66 static public void do_something(
long count)
69 for (i = 0; i < count; i++)
74 static public void main(
String[] args)
76 out.println(
"--> JniInstrumentationTest.main()");
78 ThreadMXBean tmxb = ManagementFactory.getThreadMXBean();
79 assert (tmxb.isCurrentThreadCpuTimeSupported());
80 long t0 = tmxb.getCurrentThreadCpuTime();
87 out.println(
"init libutils stopwatch...");
88 HrtStopwatch.init(10);
91 out.println(
"marking time Java ...");
92 int g0 = HrtStopwatch.pushmark();
96 int g3 = HrtStopwatch.pushmark();
97 out.println(
"... marked time Java");
100 out.println(
"amount of times Java:");
101 double rt0 = HrtStopwatch.rtmicros(g3, g0);
102 out.println(
"[g" + g0 +
"..g" + g3 +
"] real = " + rt0 +
" us");
103 double rt1 = HrtStopwatch.rtmicros(2, 1);
104 out.println(
"[g2..g1] real = " + rt1 +
" us");
105 double ct0 = HrtStopwatch.ctmicros(g3, g0);
106 out.println(
"[g" + g0 +
"..g" + g3 +
"] cpu = " + ct0 +
" us");
107 double ct1 = HrtStopwatch.ctmicros(2, 1);
108 out.println(
"[g2..g1] cpu = " + ct1 +
" us");
110 do_something(10000000);
112 long t1 = tmxb.getCurrentThreadCpuTime();
114 out.println(
"amount of times TMB:");
115 out.println(
"[t0..t1] cpu = " + ((t1 - t0)/1000.0) +
" us");
118 out.println(
"closing libutils stopwatch...");
119 HrtStopwatch.close();
121 out.println(
"<-- JniInstrumentationTest.main()");