Flutter Engine
The Flutter Engine
Functions | Variables
TracingTest.cpp File Reference
#include "include/core/SkColorType.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkString.h"
#include "src/core/SkTraceEvent.h"
#include "tests/Test.h"
#include "tools/flags/CommandLineFlags.h"
#include <cstdint>

Go to the source code of this file.

Functions

static DEFINE_bool (slowTracingTest, false, "Artificially slow down tracing test to produce nicer JSON")
 
static void do_work (int howMuchWork)
 
static void test_trace_simple ()
 
static void test_trace_counters ()
 
static void test_trace_objects ()
 
 DEF_TEST (Tracing, reporter)
 

Variables

static SkScalar gTracingTestWorkSink = 1.0f
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( Tracing  ,
reporter   
)

Definition at line 190 of file TracingTest.cpp.

190 {
194}
static void test_trace_objects()
static void test_trace_counters()
static void test_trace_simple()
Definition: TracingTest.cpp:94

◆ DEFINE_bool()

static DEFINE_bool ( slowTracingTest  ,
false  ,
"Artificially slow down tracing test to produce nicer JSON"   
)
static

◆ do_work()

static void do_work ( int  howMuchWork)
static

Definition at line 85 of file TracingTest.cpp.

85 {
86 // Do busy work so the trace marker durations are large enough to be readable in trace viewer
87 if (FLAGS_slowTracingTest) {
88 for (int i = 0; i < howMuchWork * 100; ++i) {
90 }
91 }
92}
#define SkScalarSin(radians)
Definition: SkScalar.h:45
static SkScalar gTracingTestWorkSink
Definition: TracingTest.cpp:83

◆ test_trace_counters()

static void test_trace_counters ( )
static

Definition at line 117 of file TracingTest.cpp.

117 {
118 TRACE_EVENT0("skia", TRACE_FUNC);
119
120 {
121 TRACE_EVENT0("skia", "Single Counter");
122
123 // Counter macros allow recording a named value (which must be a 32-bit integer).
124 // The value will be graphed in the viewer.
125 for (int i = 0; i < 180; ++i) {
127 TRACE_COUNTER1("skia", "sin", SkScalarSin(rad) * 1000.0f + 1000.0f);
128 do_work(10);
129 }
130 }
131
132 {
133 TRACE_EVENT0("skia", "Independent Counters");
134
135 // Recording multiple counters with separate COUNTER1 macros will make separate graphs.
136 for (int i = 0; i < 180; ++i) {
138 TRACE_COUNTER1("skia", "sin", SkScalarSin(rad) * 1000.0f + 1000.0f);
139 TRACE_COUNTER1("skia", "cos", SkScalarCos(rad) * 1000.0f + 1000.0f);
140 do_work(10);
141 }
142 }
143
144 {
145 TRACE_EVENT0("skia", "Stacked Counters");
146
147 // Two counters can be recorded together with COUNTER2. They will be graphed together,
148 // as a stacked bar graph. The combined graph needs a name, as does each data series.
149 for (int i = 0; i < 180; ++i) {
151 TRACE_COUNTER2("skia", "trig",
152 "sin", SkScalarSin(rad) * 1000.0f + 1000.0f,
153 "cos", SkScalarCos(rad) * 1000.0f + 1000.0f);
154 do_work(10);
155 }
156 }
157}
#define SkDegreesToRadians(degrees)
Definition: SkScalar.h:77
#define SkIntToScalar(x)
Definition: SkScalar.h:57
#define SkScalarCos(radians)
Definition: SkScalar.h:46
#define TRACE_COUNTER1(category_group, name, value)
#define TRACE_COUNTER2(category_group, name, value1_name, value1_val, value2_name, value2_val)
#define TRACE_FUNC
Definition: SkTraceEvent.h:30
static void do_work(int howMuchWork)
Definition: TracingTest.cpp:85
float SkScalar
Definition: extension.cpp:12
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131

◆ test_trace_objects()

static void test_trace_objects ( )
static

Definition at line 159 of file TracingTest.cpp.

159 {
160 TRACE_EVENT0("skia", TRACE_FUNC);
161
162 // Objects can be tracked through time with the TRACE_EVENT_OBJECT_ macros.
163 // The macros in use (and their idiosyncracies) are commented in the TracingShape class above.
164
165 TracingCircle* circle = new TracingCircle(SkPoint::Make(20, 20), 15);
166 circle->traceSnapshot();
167 do_work(100);
168
169 // Make another object. Objects with the same base type are shown in the same row in the viewer.
170 TracingRect* rect = new TracingRect(SkRect::MakeWH(100, 50));
171 rect->traceSnapshot();
172 do_work(100);
173
174 // We can create multiple snapshots of objects to reflect their state over time.
175 circle->fCenter.offset(10, 10);
176 circle->traceSnapshot();
177
178 {
179 // Other events (duration or instant) can refer directly to objects. For Skia's JSON
180 // tracer, having an argument whose name starts with '#' will trigger the creation of JSON
181 // that links the event to the object (with a direct link to the most recent snapshot).
182 TRACE_EVENT1("skia", "Processing Shape", "#shape", circle);
183 do_work(100);
184 }
185
186 delete circle;
187 delete rect;
188}
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)
Definition: trace_event.h:141

◆ test_trace_simple()

static void test_trace_simple ( )
static

Definition at line 94 of file TracingTest.cpp.

94 {
95 // Simple event that lasts until the end of the current scope. TRACE_FUNC is an easy way
96 // to insert the current function name.
97 TRACE_EVENT0("skia", TRACE_FUNC);
98
99 {
100 // There are versions of the macro that take 1 or 2 named arguments. The arguments
101 // can be any simple type. Strings need to be static/literal - we just copy pointers.
102 // Argument names & values are shown when the event is selected in the viewer.
103 TRACE_EVENT1("skia", "Nested work",
104 "isBGRA", kN32_SkColorType == kBGRA_8888_SkColorType);
105 do_work(500);
106 }
107
108 {
109 // If you must copy a string as an argument value, use the TRACE_STR_COPY macro.
110 // This will instruct the tracing system (if one is active) to make a copy.
111 SkString message = SkStringPrintf("%s %s", "Hello", "World");
112 TRACE_EVENT1("skia", "Dynamic String", "message", TRACE_STR_COPY(message.c_str()));
113 do_work(500);
114 }
115}
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
#define TRACE_STR_COPY(str)
Definition: SkTraceEvent.h:63
Win32Message message

Variable Documentation

◆ gTracingTestWorkSink

SkScalar gTracingTestWorkSink = 1.0f
static

Definition at line 83 of file TracingTest.cpp.