-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCTimerSamplerTest.java
More file actions
81 lines (68 loc) · 2.9 KB
/
Copy pathCTimerSamplerTest.java
File metadata and controls
81 lines (68 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.datadoghq.profiler.cpu;
import com.datadoghq.profiler.AbstractProfilerTest;
import com.datadoghq.profiler.CStackAwareAbstractProfilerTest;
import com.datadoghq.profiler.Platform;
import com.datadoghq.profiler.junit.CStack;
import com.datadoghq.profiler.junit.CStackInjector;
import com.datadoghq.profiler.junit.RetryTest;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junitpioneer.jupiter.RetryingTest;
import org.openjdk.jmc.common.item.IItem;
import org.openjdk.jmc.common.item.IItemCollection;
import org.openjdk.jmc.common.item.IItemIterable;
import org.openjdk.jmc.common.item.IMemberAccessor;
import org.openjdk.jmc.common.unit.IQuantity;
import org.openjdk.jmc.flightrecorder.jdk.JdkAttributes;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class CTimerSamplerTest extends CStackAwareAbstractProfilerTest {
private ProfiledCode profiledCode;
public CTimerSamplerTest(@CStack String cstack) {
super(cstack);
}
@Override
protected void before() {
profiledCode = new ProfiledCode(profiler);
}
@RetryTest(10)
@TestTemplate
@ValueSource(strings = {"vm", "vmx", "fp", "dwarf"})
public void test(@CStack String cstack) throws ExecutionException, InterruptedException {
// timer_create is available on Linux only
assumeTrue(Platform.isLinux());
for (int i = 0, id = 1; i < 100; i++, id += 3) {
profiledCode.method1(id);
}
stopProfiler();
verifyCStackSettings();
IItemCollection events = verifyEvents("datadog.ExecutionSample");
for (IItemIterable cpuSamples : events) {
IMemberAccessor<String, IItem> frameAccessor = JdkAttributes.STACK_TRACE_STRING.getAccessor(cpuSamples.getType());
for (IItem sample : cpuSamples) {
String stackTrace = frameAccessor.getMember(sample);
assertFalse(stackTrace.contains("jvmtiError"));
}
}
}
@Override
protected void after() throws Exception {
profiledCode.close();
}
@Override
protected String getProfilerCommand() {
// cpu=100us signal-based sampling is much more expensive under ASAN (the signal
// handler itself is ASAN-instrumented), which can inflate the sample count and,
// via the per-sample stack-trace materialization above, the test heap. Sample
// coarser under ASAN.
return isAsan() ? "cpu=1ms,event=ctimer" : "cpu=100us,event=ctimer";
}
}