/* * Copyright (c) 2021, Datadog, Inc. 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.
*/
long sizeLeak1 = -1; long sizeLeak2 = -1; long sizeLeak3 = -1;
do { try (Recording recording = new Recording()) {
leak.clear();
recording.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
recording.start();
for (int i = 0; i < 1000; i++) { if (sizeLeak1 == -1) {
leak.add(new Leak1()); continue;
} if (sizeLeak2 == -1) {
leak.add(new Leak2()); continue;
} if (sizeLeak3 == -1) {
leak.add(new Leak3());
}
}
recording.stop();
List<RecordedEvent> events = Events.fromRecording(recording); for (RecordedEvent e : events) {
RecordedObject object = e.getValue("object");
RecordedClass type = object.getValue("type"); long objectSize = e.getLong("objectSize");
System.err.println("type = " + type.getName() + ", objectSize = " + e.getLong("objectSize")); if (objectSize <= 0) { thrownew Exception("Object size for " + type.getName() + " is lower or equal to 0");
} if (type.getName().equals(Leak1.class.getName()) && sizeLeak1 == -1) {
sizeLeak1 = objectSize;
} if (type.getName().equals(Leak2.class.getName()) && sizeLeak2 == -1) {
sizeLeak2 = objectSize;
} if (type.getName().equals(Leak3.class.getName()) && sizeLeak3 == -1) {
sizeLeak3 = objectSize;
}
}
}
} while (sizeLeak1 == -1 || sizeLeak2 == -1 || sizeLeak3 == -1);
if (sizeLeak3 <= sizeLeak2) { thrownew Exception("Object size for " + Leak3.class.getName() + " is lower or equal to size for" + Leak2.class.getName());
} if (sizeLeak2 <= sizeLeak1) { thrownew Exception("Object size for " + Leak2.class.getName() + " is lower or equal to size for" + Leak1.class.getName());
}
}
}
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.