-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpmctrace_simple_test.c
67 lines (55 loc) · 2.07 KB
/
pmctrace_simple_test.c
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
/* ========================================================================
(C) Copyright 2024 by Molly Rocket, Inc., All Rights Reserved.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Please see https://computerenhance.com for more information
======================================================================== */
#include <stdio.h>
#include <stdint.h>
#define PMCTRACE_INCLUDE_IMPLEMENTATION 1
#include "pmctrace.h"
#include "pmctrace_counters.h"
int main(void)
{
pmctrace_pmc_definition_array PMCDefs =
{
{
PMCTrace_CYCLES_NOT_IN_HALT,
PMCTrace_RETIRED_INST,
PMCTrace_RETIRED_SSE_AVX_FLOPS,
}
};
printf("Starting trace...\n");
pmctrace_client Tracer = PMCTraceStartTracing(PMCDefs);
PMCTraceBeginRegion(&Tracer, 0);
printf("... This printf is measured only by Region[0].\n");
PMCTraceBeginRegion(&Tracer, 1);
printf("... This printf is measured by both.\n");
PMCTraceEndRegion(&Tracer, 0);
PMCTraceEndRegion(&Tracer, 1);
printf("Getting results...\n");
for(int ResultIndex = 0; ResultIndex < 2; ++ResultIndex)
{
pmctrace_result Result = PMCTraceGetOrWaitForResult(&Tracer, ResultIndex);
if(NoErrors(&Tracer))
{
printf("\n%llu TSC elapsed [%u context switch%s]\n",
Result.TSCElapsed, Result.ContextSwitchCount,
(Result.ContextSwitchCount != 1) ? "es" : "");
for(int CI = 0; CI < Result.PMCCount; ++CI)
{
printf(" %llu %s\n", Result.Counters[CI], PMCDefs.Defs[CI].PrintableName);
}
}
else
{
printf("CLIENT ERROR: %s\n", GetClientErrorMessage(&Tracer));
printf("SERVER ERROR: %s\n", GetServerErrorMessage(&Tracer));
break;
}
}
printf("Stopping trace...\n");
PMCTraceStopPMCTracing(&Tracer);
return 0;
}