blob: a3b1fa861821487ee8f4409731854d2dcc8b1cd5 (
plain)
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
|
// a plain, un-instrumented target for the sampling profiler: NOTHING added to the
// build, no flags, no linked runtime. functions do enough work (tens of ms) that
// the sampler catches them. compile normally: clang++ -g sample_demo.cpp -o sample_demo
#include <cstdio>
// a spin of roughly the requested milliseconds of busywork
static volatile long sink = 0;
static void burn(int ms)
{
// ~2 million iterations per ms is a rough guess; exact timing does not matter
for (long i = 0; i < ms * 800000L; ++i)
sink += i % 7;
}
static void deep(int round)
{
burn(25 + round % 3 * 15);
}
static void phase_b(int round)
{
burn(20);
deep(round);
}
static void phase_a(int round)
{
burn(40);
}
int main()
{
for (int round = 0; round < 400; ++round)
{
phase_a(round);
phase_b(round);
if (round % 10 == 0)
{
printf("round %d\n", round);
fflush(stdout);
}
}
puts("done");
return 0;
}
|