1
1
package io .pyroscope .javaagent .config ;
2
2
3
+ import io .pyroscope .javaagent .EventType ;
3
4
import io .pyroscope .javaagent .PreConfigLogger ;
4
- import one .profiler .Events ;
5
5
import org .apache .logging .log4j .Level ;
6
6
7
7
import java .nio .ByteBuffer ;
@@ -21,38 +21,57 @@ public final class Config {
21
21
22
22
private static final String DEFAULT_SPY_NAME = "javaspy" ;
23
23
private static final Duration DEFAULT_PROFILING_INTERVAL = Duration .ofMillis (10 );
24
- private static final String DEFAULT_PROFILER_EVENT = Events .ITIMER ;
24
+ private static final EventType DEFAULT_PROFILER_EVENT = EventType .ITIMER ;
25
25
private static final Duration DEFAULT_UPLOAD_INTERVAL = Duration .ofSeconds (10 );
26
26
private static final String DEFAULT_SERVER_ADDRESS = "http://localhost:4040" ;
27
27
28
28
public final String spyName = DEFAULT_SPY_NAME ;
29
29
public final String applicationName ;
30
30
public final Duration profilingInterval ;
31
- public final String profilingEvent ;
31
+ public final EventType profilingEvent ;
32
32
public final Duration uploadInterval ;
33
33
public final Level logLevel ;
34
34
public final String serverAddress ;
35
35
public final String authToken ;
36
+ public final String timeseriesName ;
36
37
37
38
Config (final String applicationName ,
38
39
final Duration profilingInterval ,
39
- final String profilingEvent ,
40
+ final EventType profilingEvent ,
40
41
final Duration uploadInterval ,
41
42
final Level logLevel ,
42
43
final String serverAddress ,
43
- final String authToken ) {
44
+ final String authToken
45
+ ) {
44
46
this .applicationName = applicationName ;
45
47
this .profilingInterval = profilingInterval ;
46
48
this .profilingEvent = profilingEvent ;
47
49
this .uploadInterval = uploadInterval ;
48
50
this .logLevel = logLevel ;
49
51
this .serverAddress = serverAddress ;
50
52
this .authToken = authToken ;
53
+ this .timeseriesName = timeseriesName (applicationName , profilingEvent );
54
+ }
55
+
56
+ public long profilingIntervalInHertz () {
57
+ return durationToHertz (this .profilingInterval );
58
+ }
59
+
60
+ private static long durationToHertz (Duration duration ) {
61
+ Duration oneSecond = Duration .ofSeconds (1 );
62
+ return oneSecond .toNanos () / duration .toNanos ();
51
63
}
52
64
53
65
public static Config build () {
54
- return new Config (applicationName (), profilingInterval (),
55
- profilingEvent (), uploadInterval (), logLevel (), serverAddress (), authToken ());
66
+ return new Config (
67
+ applicationName (),
68
+ profilingInterval (),
69
+ profilingEvent (),
70
+ uploadInterval (),
71
+ logLevel (),
72
+ serverAddress (),
73
+ authToken ()
74
+ );
56
75
}
57
76
58
77
private static String applicationName () {
@@ -88,22 +107,24 @@ private static Duration profilingInterval() {
88
107
}
89
108
}
90
109
91
- private static String profilingEvent () {
92
- final String profilingIntervalStr = System .getenv (PYROSCOPE_PROFILER_EVENT_CONFIG );
93
- if (profilingIntervalStr == null || profilingIntervalStr .isEmpty ()) {
110
+ private String timeseriesName (String applicationName , EventType eventType ) {
111
+ return applicationName + "." + eventType .id ;
112
+ }
113
+
114
+ private static EventType profilingEvent () {
115
+ final String profilingEventStr =
116
+ System .getenv (PYROSCOPE_PROFILER_EVENT_CONFIG );
117
+ if (profilingEventStr == null || profilingEventStr .isEmpty ()) {
94
118
return DEFAULT_PROFILER_EVENT ;
95
119
}
96
120
97
- final String profilingIntervalStrLC = profilingIntervalStr .toLowerCase (Locale .ROOT );
98
- if (profilingIntervalStrLC .equals (Events .ITIMER )
99
- || profilingIntervalStrLC .equals (Events .CPU )
100
- || profilingIntervalStrLC .equals (Events .ALLOC )
101
- || profilingIntervalStrLC .equals (Events .LOCK )
102
- || profilingIntervalStrLC .equals (Events .WALL )) {
103
- return profilingIntervalStr ;
104
- } else {
121
+ final String lowerCaseTrimmed = profilingEventStr .trim ().toLowerCase ();
122
+
123
+ try {
124
+ return EventType .fromId (lowerCaseTrimmed );
125
+ } catch (IllegalArgumentException e ) {
105
126
PreConfigLogger .LOGGER .warn ("Invalid {} value {}, using {}" ,
106
- PYROSCOPE_PROFILER_EVENT_CONFIG , profilingIntervalStrLC , DEFAULT_PROFILER_EVENT );
127
+ PYROSCOPE_PROFILER_EVENT_CONFIG , profilingEventStr , DEFAULT_PROFILER_EVENT . id );
107
128
return DEFAULT_PROFILER_EVENT ;
108
129
}
109
130
}
0 commit comments