|
29 | 29 |
|
30 | 30 | import com.datadog.profiling.controller.OngoingRecording; |
31 | 31 | import com.datadog.profiling.utils.ProfilingMode; |
32 | | -import com.datadog.profiling.utils.Timestamper; |
33 | 32 | import com.datadoghq.profiler.ContextSetter; |
34 | 33 | import com.datadoghq.profiler.JavaProfiler; |
35 | 34 | import datadog.trace.api.profiling.RecordingData; |
@@ -97,7 +96,7 @@ public static DatadogProfiler newInstance(ConfigProvider configProvider) { |
97 | 96 |
|
98 | 97 | private final List<String> orderedContextAttributes; |
99 | 98 |
|
100 | | - private final double queueTimeThresholdNanos; |
| 99 | + private final long queueTimeThresholdMillis; |
101 | 100 |
|
102 | 101 | private DatadogProfiler(ConfigProvider configProvider) { |
103 | 102 | this(configProvider, getContextAttributes(configProvider)); |
@@ -134,11 +133,10 @@ private DatadogProfiler(ConfigProvider configProvider) { |
134 | 133 | orderedContextAttributes.add(RESOURCE); |
135 | 134 | } |
136 | 135 | this.contextSetter = new ContextSetter(profiler, orderedContextAttributes); |
137 | | - this.queueTimeThresholdNanos = |
138 | | - 1_000_000D |
139 | | - * configProvider.getLong( |
140 | | - PROFILING_QUEUEING_TIME_THRESHOLD_MILLIS, |
141 | | - PROFILING_QUEUEING_TIME_THRESHOLD_MILLIS_DEFAULT); |
| 136 | + this.queueTimeThresholdMillis = |
| 137 | + configProvider.getLong( |
| 138 | + PROFILING_QUEUEING_TIME_THRESHOLD_MILLIS, |
| 139 | + PROFILING_QUEUEING_TIME_THRESHOLD_MILLIS_DEFAULT); |
142 | 140 | } |
143 | 141 |
|
144 | 142 | void addThread() { |
@@ -377,34 +375,21 @@ public void recordSetting(String name, String value, String unit) { |
377 | 375 | } |
378 | 376 |
|
379 | 377 | public QueueTimeTracker newQueueTimeTracker() { |
380 | | - return new QueueTimeTracker(this, timestamper().timestamp()); |
| 378 | + return new QueueTimeTracker(this, profiler.getCurrentTicks()); |
381 | 379 | } |
382 | 380 |
|
383 | | - void recordQueueTimeEvent(long startTicks, Object task, Class<?> scheduler, Thread origin) { |
| 381 | + void recordQueueTimeEvent( |
| 382 | + long startMillis, long startTicks, Object task, Class<?> scheduler, Thread origin) { |
384 | 383 | if (profiler != null) { |
385 | | - Timestamper timestamper = timestamper(); |
386 | | - long endTicks = timestamper.timestamp(); |
387 | | - double durationNanos = timestamper.toNanosConversionFactor() * (endTicks - startTicks); |
388 | | - if (durationNanos >= queueTimeThresholdNanos) { |
| 384 | + if (System.currentTimeMillis() - startMillis >= queueTimeThresholdMillis) { |
389 | 385 | // note: because this type traversal can update secondary_super_cache (see JDK-8180450) |
390 | 386 | // we avoid doing this unless we are absolutely certain we will record the event |
391 | 387 | Class<?> taskType = TaskWrapper.getUnwrappedType(task); |
392 | 388 | if (taskType != null) { |
| 389 | + long endTicks = profiler.getCurrentTicks(); |
393 | 390 | profiler.recordQueueTime(startTicks, endTicks, taskType, scheduler, origin); |
394 | 391 | } |
395 | 392 | } |
396 | 393 | } |
397 | 394 | } |
398 | | - |
399 | | - private Timestamper timestamper() { |
400 | | - // FIXME intended to be injectable, but still a singleton for currently pragmatic reasons. |
401 | | - // We need a way to make the Controller responsible for creating the context integration |
402 | | - // for the tracer, which also allows the context integration to be constant in the tracer, |
403 | | - // as well as allowing for the various late initialisation needs for JFR on certain JDK |
404 | | - // versions |
405 | | - // note that this access does not risk using the default version so long as queue time is |
406 | | - // guarded |
407 | | - // by checking if JFR is ready (this currently happens in QueueTimeHelper, so this is safe) |
408 | | - return Timestamper.timestamper(); |
409 | | - } |
410 | 395 | } |
0 commit comments