MCPcopy Create free account
hub / github.com/async-profiler/async-profiler / enable

Method enable

src/tsc.cpp:17–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15u64 TSC::_frequency = NANOTIME_FREQ;
16
17void TSC::enable(Clock clock) {
18 if (!TSC_SUPPORTED || clock == CLK_MONOTONIC) {
19 _enabled = false;
20 return;
21 }
22
23 if (!_initialized) {
24 if (VM::loaded()) {
25 JNIEnv* env = VM::jni();
26
27 jfieldID jvm;
28 jmethodID getTicksFrequency, counterTime;
29 jclass cls = env->FindClass("jdk/jfr/internal/JVM");
30 if (cls != NULL
31 && ((jvm = env->GetStaticFieldID(cls, "jvm", "Ljdk/jfr/internal/JVM;")) != NULL)
32 && ((getTicksFrequency = env->GetMethodID(cls, "getTicksFrequency", "()J")) != NULL)
33 && ((counterTime = env->GetStaticMethodID(cls, "counterTime", "()J")) != NULL)) {
34 u64 frequency = env->CallLongMethod(env->GetStaticObjectField(cls, jvm), getTicksFrequency);
35 if (frequency > NANOTIME_FREQ) {
36 // Default 1GHz frequency might mean that rdtsc is not available
37 u64 jvm_ticks = env->CallStaticLongMethod(cls, counterTime);
38 _offset = rdtsc() - jvm_ticks;
39 _frequency = frequency;
40 _available = true;
41 }
42 }
43
44 env->ExceptionClear();
45 } else if (cpuHasGoodTimestampCounter()) {
46 _offset = 0;
47 _available = true;
48 }
49
50 _initialized = true;
51 }
52
53 _enabled = _available;
54}

Callers 2

RecordingMethod · 0.45
startMethod · 0.45

Calls 2

rdtscFunction · 0.85

Tested by

no test coverage detected