1 // Copyright 2017 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "benchmarks.h"
6
7 #include <stdio.h>
8
9 #define NTRACE
10 #include <trace/event.h>
11 #include <trace-vthread/event_vthread.h>
12
13 #include "runner.h"
14
NullSetup()15 static void NullSetup() {}
NullTeardown()16 static void NullTeardown() {}
17
RunNoTraceBenchmarks()18 void RunNoTraceBenchmarks() {
19 RunAndMeasure(
20 "TRACE_ENABLED", "NTRACE",
21 [] {
22 ZX_DEBUG_ASSERT(!TRACE_ENABLED());
23 },
24 NullSetup, NullTeardown);
25
26 RunAndMeasure(
27 "TRACE_CATEGORY_ENABLED", "NTRACE",
28 [] {
29 ZX_DEBUG_ASSERT(!TRACE_CATEGORY_ENABLED("+enabled"));
30 },
31 NullSetup, NullTeardown);
32
33 RunAndMeasure(
34 "TRACE_DURATION_BEGIN macro with 0 arguments", "NTRACE",
35 [] {
36 TRACE_DURATION_BEGIN("+enabled", "name");
37 },
38 NullSetup, NullTeardown);
39
40 RunAndMeasure(
41 "TRACE_DURATION_BEGIN macro with 1 int32 argument", "NTRACE",
42 [] {
43 TRACE_DURATION_BEGIN("+enabled", "name",
44 "k1", 1);
45 },
46 NullSetup, NullTeardown);
47
48 RunAndMeasure(
49 "TRACE_DURATION_BEGIN macro with 4 int32 arguments", "NTRACE",
50 [] {
51 TRACE_DURATION_BEGIN("+enabled", "name",
52 "k1", 1, "k2", 2, "k3", 3, "k4", 4);
53 },
54 NullSetup, NullTeardown);
55
56 RunAndMeasure(
57 "TRACE_DURATION_BEGIN macro with 8 int32 arguments", "NTRACE",
58 [] {
59 TRACE_DURATION_BEGIN("+enabled", "name",
60 "k1", 1, "k2", 2, "k3", 3, "k4", 4,
61 "k5", 5, "k6", 6, "k7", 7, "k8", 8);
62 },
63 NullSetup, NullTeardown);
64
65 RunAndMeasure(
66 "TRACE_VTHREAD_DURATION_BEGIN macro with 0 arguments", "NTRACE",
67 [] {
68 TRACE_VTHREAD_DURATION_BEGIN("+enabled", "name", "vthread", 1, zx_ticks_get());
69 },
70 NullSetup, NullTeardown);
71 }
72