/* * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
publicstaticvoid main(String... args) throws IOException, InterruptedException {
Recording r = new Recording();
r.enable(MyEvent.class).withThreshold(Duration.ofNanos(0)).withoutStackTrace();
r.start();
List<Thread> threads = new ArrayList<>(); for (int n = 0; n < THREAD_COUNT; n++) { Thread t = newThread(TestJavaEvent::emitEvents);
threads.add(t);
t.start();
} for (Thread t : threads) {
t.join();
}
r.stop(); // prettyPrint();
File file = Utils.createTempFile("test", ".jfr").toFile();
r.dump(file.toPath()); int eventCount = 0; for (RecordedEvent e : RecordingFile.readAllEvents(file.toPath())) { if (e.getEventType().getName().equals(MyEvent.class.getName())) {
eventCount++;
}
System.out.println(e);
}
System.out.println("Event count was " + eventCount + ", expected " + THREAD_COUNT * EVENTS_PER_THREAD);
r.close();
}
privatestaticvoid emitEvents() { for (int n = 0; n < EVENTS_PER_THREAD; n++) {
MyEvent event = new MyEvent();
event.begin();
event.end();
event.setFloatValue(1.12345f);
event.setDoubleValue(1.234567890);
event.setIntValue(123456);
event.setLongValue(1234567890);
event.setCharValue('c');
event.setByteValue((byte) 12);
event.setStringValue("1234567890");
event.setThreadValue(Thread.currentThread());
event.setClassValue(Class.class);
event.commit(); try { Thread.sleep(1);
} catch (InterruptedException e) { // TODO Auto-generated catch block
e.printStackTrace();
}
}
}
staticvoid prettyPrint() { for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) { for (AnnotationElement a : type.getAnnotationElements()) {
printAnnotation("", a);
}
System.out.print("class " + removePackage(type.getName()));
System.out.print(" extends Event");
System.out.println(" {");
List<ValueDescriptor> values = type.getFields(); for (int i = 0; i < values.size(); i++) {
ValueDescriptor v = values.get(i); for (AnnotationElement a : v.getAnnotationElements()) {
printAnnotation(" ", a);
}
System.out.println(" " + removePackage(v.getTypeName() + brackets(v.isArray())) + " "+ v.getName()); if (i != values.size() - 1) {
System.out.println();
}
}
System.out.println("}");
System.out.println();
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.