1 /* |
1 /* |
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
41 import java.lang.reflect.InvocationTargetException; |
41 import java.lang.reflect.InvocationTargetException; |
42 import java.lang.reflect.Method; |
42 import java.lang.reflect.Method; |
43 import java.lang.reflect.Modifier; |
43 import java.lang.reflect.Modifier; |
44 import java.nio.file.Path; |
44 import java.nio.file.Path; |
45 import java.time.Duration; |
45 import java.time.Duration; |
|
46 import java.time.Instant; |
46 import java.time.LocalDateTime; |
47 import java.time.LocalDateTime; |
47 import java.util.ArrayList; |
48 import java.util.ArrayList; |
48 import java.util.Arrays; |
49 import java.util.Arrays; |
49 import java.util.Collections; |
50 import java.util.Collections; |
50 import java.util.HashMap; |
51 import java.util.HashMap; |
63 import jdk.jfr.internal.settings.StackTraceSetting; |
64 import jdk.jfr.internal.settings.StackTraceSetting; |
64 import jdk.jfr.internal.settings.ThresholdSetting; |
65 import jdk.jfr.internal.settings.ThresholdSetting; |
65 |
66 |
66 public final class Utils { |
67 public final class Utils { |
67 |
68 |
|
69 private static final Object flushObject = new Object(); |
68 private static final String INFINITY = "infinity"; |
70 private static final String INFINITY = "infinity"; |
69 |
|
70 private static Boolean SAVE_GENERATED; |
|
71 |
|
72 public static final String EVENTS_PACKAGE_NAME = "jdk.jfr.events"; |
71 public static final String EVENTS_PACKAGE_NAME = "jdk.jfr.events"; |
73 public static final String INSTRUMENT_PACKAGE_NAME = "jdk.jfr.internal.instrument"; |
72 public static final String INSTRUMENT_PACKAGE_NAME = "jdk.jfr.internal.instrument"; |
74 public static final String HANDLERS_PACKAGE_NAME = "jdk.jfr.internal.handlers"; |
73 public static final String HANDLERS_PACKAGE_NAME = "jdk.jfr.internal.handlers"; |
75 public static final String REGISTER_EVENT = "registerEvent"; |
74 public static final String REGISTER_EVENT = "registerEvent"; |
76 public static final String ACCESS_FLIGHT_RECORDER = "accessFlightRecorder"; |
75 public static final String ACCESS_FLIGHT_RECORDER = "accessFlightRecorder"; |
77 |
|
78 private final static String LEGACY_EVENT_NAME_PREFIX = "com.oracle.jdk."; |
76 private final static String LEGACY_EVENT_NAME_PREFIX = "com.oracle.jdk."; |
|
77 |
|
78 private static Boolean SAVE_GENERATED; |
|
79 |
79 |
80 |
80 public static void checkAccessFlightRecorder() throws SecurityException { |
81 public static void checkAccessFlightRecorder() throws SecurityException { |
81 SecurityManager sm = System.getSecurityManager(); |
82 SecurityManager sm = System.getSecurityManager(); |
82 if (sm != null) { |
83 if (sm != null) { |
83 sm.checkPermission(new FlightRecorderPermission(ACCESS_FLIGHT_RECORDER)); |
84 sm.checkPermission(new FlightRecorderPermission(ACCESS_FLIGHT_RECORDER)); |
593 String pid = JVM.getJVM().getPid(); |
594 String pid = JVM.getJVM().getPid(); |
594 String date = Repository.REPO_DATE_FORMAT.format(LocalDateTime.now()); |
595 String date = Repository.REPO_DATE_FORMAT.format(LocalDateTime.now()); |
595 String idText = recording == null ? "" : "-id-" + Long.toString(recording.getId()); |
596 String idText = recording == null ? "" : "-id-" + Long.toString(recording.getId()); |
596 return "hotspot-" + "pid-" + pid + idText + "-" + date + ".jfr"; |
597 return "hotspot-" + "pid-" + pid + idText + "-" + date + ".jfr"; |
597 } |
598 } |
|
599 |
|
600 public static void takeNap(long millis) { |
|
601 try { |
|
602 Thread.sleep(millis); |
|
603 } catch (InterruptedException e) { |
|
604 // ok |
|
605 } |
|
606 } |
|
607 |
|
608 public static void notifyFlush() { |
|
609 synchronized (flushObject) { |
|
610 flushObject.notifyAll(); |
|
611 } |
|
612 } |
|
613 |
|
614 public static void waitFlush(long timeOut) { |
|
615 synchronized (flushObject) { |
|
616 try { |
|
617 flushObject.wait(timeOut); |
|
618 } catch (InterruptedException e) { |
|
619 // OK |
|
620 } |
|
621 } |
|
622 |
|
623 } |
|
624 |
|
625 public static long timeToNanos(Instant timestamp) { |
|
626 return timestamp.getEpochSecond() * 1_000_000_000L + timestamp.getNano(); |
|
627 } |
598 } |
628 } |