/* * Copyright (c) 2022, 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.
*/
// Verification
List<RecordedEvent> full = RecordingFile.readAllEvents(file);
List<Path> chunkFiles = new ArrayList<>(Files.list(directory).toList());
Collections.sort(chunkFiles); int total = 0; for (Path chunkFile : chunkFiles) {
System.out.println("Veryfying chunk: " + chunkFile + " " + total); try (RecordingFile f = new RecordingFile(chunkFile)) { int index = 0; while (f.hasMoreEvents()) {
RecordedEvent event = f.readEvent();
assertStressEvent(event, f, index);
assertEventEquals(full.get(total + index), event, index);
index++;
}
total += index;
}
}
System.out.println("Event count: " + total);
}
}
staticvoid assertStressEvent(RecordedEvent event, RecordingFile f, int index) throws IOException {
String name = event.getEventType().getName(); if (name.equals("String") || name.equals("Thread") || name.equals("Clazz")) {
String fieldName = name.toLowerCase();
Object value = event.getValue(fieldName); if (value == null) {
writeFailureFile(f, index); thrownew AssertionError("Null found in " + name + " event. Event number " + index);
}
RecordedStackTrace stackTrace = event.getStackTrace(); if (stackTrace == null) {
writeFailureFile(f, index); thrownew AssertionError("Stack trace was null. Event number " + index);
}
}
}
privatestaticvoid writeFailureFile(RecordingFile f, int index) throws IOException {
Path file = Path.of("failure.jfr");
AtomicInteger count = new AtomicInteger();
f.write(file, e-> count.incrementAndGet() == index + 1);
System.out.println("Failure file with only event " + index + " written to: " + file);
}
staticvoid assertEventEquals(RecordedEvent a, RecordedEvent b, int index) { if (a.getEventType().getId() != b.getEventType().getId()) {
printRecordedObjects(a, b); thrownew AssertionError("Event types don't match. Event number " + index);
} for (ValueDescriptor field : a.getEventType().getFields()) {
String n = field.getName(); if (!isEqual(a.getValue(n), b.getValue(n))) {
printRecordedObjects(a, b); thrownew AssertionError("Events don't match. Event number " + index);
}
}
}
privatestaticvoid printRecordedObjects(RecordedObject a, RecordedObject b) {
System.out.println("Object A:");
System.out.println(a);
System.out.println("Object B:");
System.out.println(b);
}
privatestaticboolean isEqual(Object a, Object b) { if (a == null && b == null) { returntrue;
} if (a == null || b == null) {
System.out.println("One value null");
System.out.println("Value A: " + a);
System.out.println("Value B: " + b); returnfalse;
} if (a.getClass() != b.getClass()) {
System.out.println("Not same class"); returnfalse;
} if (a instanceofDouble d1 && b instanceofDouble d2) { returnDouble.doubleToRawLongBits(d1) == Double.doubleToRawLongBits(d2);
} if (a instanceofFloat f1 && b instanceofFloat f2) { returnFloat.floatToRawIntBits(f1) == Float.floatToRawIntBits(f2);
} if (a instanceof String || a instanceof Number || a instanceofBoolean) { return Objects.equals(a, b);
} // Thread name may change, so sufficient to compare ID if (a instanceof RecordedThread t1 && b instanceof RecordedThread t2) { return t1.getId() == t2.getId();
} if (a instanceof RecordedObject r1 && b instanceof RecordedObject r2) { for (ValueDescriptor field : r1.getFields()) {
String n = field.getName(); if (!isEqual(r1.getValue(n), r2.getValue(n))) {
System.out.println("Field " + n + " doesn't match");
System.out.println("Value A: " + r1.getValue(n));
System.out.println("Value B: " + r2.getValue(n)); returnfalse;
}
} returntrue;
} if (a.getClass().isArray()) {
Object[] array = (Object[]) a;
Object[] brray = (Object[]) b; if (array.length != brray.length) {
System.out.println("Array size doesn't match"); returnfalse;
} for (int i = 0; i < array.length; i++) { if (!isEqual(array[i], brray[i])) {
System.out.println("Array contents doesn't match"); returnfalse;
}
} returntrue;
} thrownew AssertionError("Unknown object type " + a.getClass() + " found");
}
@Override protectedvoid stress() throws Exception {
String text = String.valueOf(counter) + "012345678901234567890"; // Repeat string so characters are stored in check point event for (int i = 0; i < 10; i++) {
StringEvent e = new StringEvent();
e.string = text;
e.commit();
}
counter++; Thread.sleep(1);
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
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.