• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "src/tracing/test/tracing_module.h"
18 
19 #include "protos/perfetto/trace/track_event/log_message.pbzero.h"
20 #include "src/tracing/test/tracing_module_categories.h"
21 
22 #include <stdio.h>
23 
24 // This file is for checking that multiple sets of trace event categories can be
25 // combined into the same program.
26 
27 PERFETTO_TRACK_EVENT_STATIC_STORAGE();
28 
29 namespace tracing_module {
30 
InitializeCategories()31 void InitializeCategories() {
32   TrackEvent::Register();
33 }
34 
EmitTrackEvents()35 void EmitTrackEvents() {
36   TRACE_EVENT_BEGIN("cat1", "DisabledEventFromModule");
37   TRACE_EVENT_END("cat1");
38   TRACE_EVENT_BEGIN("cat4", "DisabledEventFromModule");
39   TRACE_EVENT_END("cat4");
40   TRACE_EVENT_BEGIN("cat9", "DisabledEventFromModule");
41   TRACE_EVENT_END("cat9");
42   TRACE_EVENT_BEGIN("foo", "FooEventFromModule");
43   TRACE_EVENT_END("foo");
44 }
45 
GetIncrementalState()46 perfetto::internal::TrackEventIncrementalState* GetIncrementalState() {
47   perfetto::internal::TrackEventIncrementalState* state = nullptr;
48   TrackEvent::Trace([&state](TrackEvent::TraceContext ctx) {
49     state = ctx.GetIncrementalState();
50   });
51   return state;
52 }
53 
FunctionWithOneTrackEvent()54 void FunctionWithOneTrackEvent() {
55   TRACE_EVENT_BEGIN("cat1", "DisabledEventFromModule");
56   // Simulates the non-tracing work of this function, which should take priority
57   // over the above trace event in terms of instruction scheduling.
58   puts("Hello");
59 }
60 
FunctionWithOneTrackEventWithTypedArgument()61 void FunctionWithOneTrackEventWithTypedArgument() {
62   TRACE_EVENT_BEGIN("cat1", "EventWithArg", [](perfetto::EventContext ctx) {
63     auto log = ctx.event()->set_log_message();
64     log->set_body_iid(0x42);
65   });
66   // Simulates the non-tracing work of this function, which should take priority
67   // over the above trace event in terms of instruction scheduling.
68   puts("Hello");
69 }
70 
FunctionWithOneScopedTrackEvent()71 void FunctionWithOneScopedTrackEvent() {
72   TRACE_EVENT("cat1", "ScopedEventFromModule");
73   // Simulates the non-tracing work of this function, which should take priority
74   // over the above trace event in terms of instruction scheduling.
75   puts("Hello");
76 }
77 
FunctionWithOneTrackEventWithDebugAnnotations()78 void FunctionWithOneTrackEventWithDebugAnnotations() {
79   TRACE_EVENT_BEGIN("cat1", "EventWithAnnotations", "p1", 42, "p2", .5f);
80   // Simulates the non-tracing work of this function, which should take priority
81   // over the above trace event in terms of instruction scheduling.
82   puts("Hello");
83 }
84 
FunctionWithOneTrackEventWithCustomTrack()85 void FunctionWithOneTrackEventWithCustomTrack() {
86   TRACE_EVENT_BEGIN("cat1", "EventWithTrack", perfetto::Track(8086));
87   // Simulates the non-tracing work of this function, which should take priority
88   // over the above trace event in terms of instruction scheduling.
89   puts("Hello");
90 }
91 
FunctionWithOneLegacyEvent()92 void FunctionWithOneLegacyEvent() {
93   TRACE_EVENT_BEGIN("cat1", "LegacyEventWithArgs", "arg1", 42, "arg2", .5f);
94   // Simulates the non-tracing work of this function, which should take priority
95   // over the above trace event in terms of instruction scheduling.
96   puts("Hello");
97 }
98 
FunctionWithOneScopedLegacyEvent()99 void FunctionWithOneScopedLegacyEvent() {
100   TRACE_EVENT("cat1", "ScopedLegacyEventWithArgs", "arg1", 42, "arg2", .5f);
101   // Simulates the non-tracing work of this function, which should take priority
102   // over the above trace event in terms of instruction scheduling.
103   puts("Hello");
104 }
105 
FunctionWithOneCounterEvent()106 void FunctionWithOneCounterEvent() {
107   TRACE_COUNTER("cat1", "CounterName", 4096);
108   // Simulates the non-tracing work of this function, which should take priority
109   // over the above trace event in terms of instruction scheduling.
110   puts("Hello");
111 }
112 
113 }  // namespace tracing_module
114