Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: test/cctest/test-trace-event.cc

Issue 988893003: Implement tracing interface for v8 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove trace-event-common.h and use DEPs instead, remove src/v8.h from trace-event.h, file a bug fo… Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project 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 #include <stdlib.h>
5
6 #include "src/v8.h"
7
8 #include "src/list.h"
9 #include "src/list-inl.h"
10 #include "test/cctest/cctest.h"
11
12 using v8::IdleTask;
13 using v8::Task;
14 using v8::Isolate;
15
16 #include "src/tracing/trace-event.h"
17
18 #define GET_TRACE_OBJECTS_LIST platform.GetMockTraceObjects()
19
20 #define GET_TRACE_OBJECT(Index) GET_TRACE_OBJECTS_LIST->at(Index)
21
22
23 struct MockTraceObject {
24 char phase;
25 const char* name;
26 uint64_t id;
27 uint64_t bind_id;
28 int num_args;
29 unsigned int flags;
30 MockTraceObject(char phase, const char* name, uint64_t id, uint64_t bind_id,
31 int num_args, int flags)
32 : phase(phase),
33 name(name),
34 id(id),
35 bind_id(bind_id),
36 num_args(num_args),
37 flags(flags) {}
38 };
39
40 typedef v8::internal::List<MockTraceObject*> MockTraceObjectList;
41
42 class MockTracingPlatform : public v8::Platform {
43 public:
44 explicit MockTracingPlatform(v8::Platform* platform) {}
45 virtual ~MockTracingPlatform() {
46 for (int i = 0; i < trace_object_list_.length(); ++i) {
47 delete trace_object_list_[i];
48 }
49 trace_object_list_.Clear();
50 }
51 void CallOnBackgroundThread(Task* task,
52 ExpectedRuntime expected_runtime) override {}
53
54 void CallOnForegroundThread(Isolate* isolate, Task* task) override {}
55
56 void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
57 double delay_in_seconds) override {}
58
59 double MonotonicallyIncreasingTime() override { return 0.0; }
60
61 void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) override {}
62
63 bool IdleTasksEnabled(Isolate* isolate) override { return false; }
64
65 bool PendingIdleTask() { return false; }
66
67 void PerformIdleTask(double idle_time_in_seconds) {}
68
69 bool PendingDelayedTask() { return false; }
70
71 void PerformDelayedTask() {}
72
73 uint64_t AddTraceEvent(char phase, const uint8_t* category_enabled_flag,
74 const char* name, uint64_t id, uint64_t bind_id,
75 int num_args, const char** arg_names,
76 const uint8_t* arg_types, const uint64_t* arg_values,
77 unsigned int flags) override {
78 MockTraceObject* to =
79 new MockTraceObject(phase, name, id, bind_id, num_args, flags);
80 trace_object_list_.Add(to);
81 return 0;
82 }
83
84 void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
85 const char* name, uint64_t handle) override {}
86
87 const uint8_t* GetCategoryGroupEnabled(const char* name) override {
88 if (strcmp(name, "v8-cat")) {
89 static uint8_t no = 0;
90 return &no;
91 } else {
92 static uint8_t yes = 0x7;
93 return &yes;
94 }
95 }
96
97 const char* GetCategoryGroupName(
98 const uint8_t* category_enabled_flag) override {
99 static const char dummy[] = "dummy";
100 return dummy;
101 }
102
103 MockTraceObjectList* GetMockTraceObjects() { return &trace_object_list_; }
104
105 private:
106 MockTraceObjectList trace_object_list_;
107 };
108
109
110 TEST(TraceEventDisabledCategory) {
111 v8::Platform* old_platform = i::V8::GetCurrentPlatform();
112 MockTracingPlatform platform(old_platform);
113 i::V8::SetPlatformForTesting(&platform);
114
115 // Disabled category, will not add events.
116 TRACE_EVENT_BEGIN0("cat", "e1");
117 TRACE_EVENT_END0("cat", "e1");
118 CHECK_EQ(0, GET_TRACE_OBJECTS_LIST->length());
119
120 i::V8::SetPlatformForTesting(old_platform);
121 }
122
123
124 TEST(TraceEventNoArgs) {
125 v8::Platform* old_platform = i::V8::GetCurrentPlatform();
126 MockTracingPlatform platform(old_platform);
127 i::V8::SetPlatformForTesting(&platform);
128
129 // Enabled category will add 2 events.
130 TRACE_EVENT_BEGIN0("v8-cat", "e1");
131 TRACE_EVENT_END0("v8-cat", "e1");
132
133 CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->length());
134 CHECK_EQ('B', GET_TRACE_OBJECT(0)->phase);
135 CHECK_EQ("e1", GET_TRACE_OBJECT(0)->name);
136 CHECK_EQ(0, GET_TRACE_OBJECT(0)->num_args);
137
138 CHECK_EQ('E', GET_TRACE_OBJECT(1)->phase);
139 CHECK_EQ("e1", GET_TRACE_OBJECT(1)->name);
140 CHECK_EQ(0, GET_TRACE_OBJECT(1)->num_args);
141
142 i::V8::SetPlatformForTesting(old_platform);
143 }
144
145
146 TEST(TraceEventWithOneArg) {
147 v8::Platform* old_platform = i::V8::GetCurrentPlatform();
148 MockTracingPlatform platform(old_platform);
149 i::V8::SetPlatformForTesting(&platform);
150
151 TRACE_EVENT_BEGIN1("v8-cat", "e1", "arg1", 42);
152 TRACE_EVENT_END1("v8-cat", "e1", "arg1", 42);
153 TRACE_EVENT_BEGIN1("v8-cat", "e2", "arg1", "abc");
154 TRACE_EVENT_END1("v8-cat", "e2", "arg1", "abc");
155
156 CHECK_EQ(4, GET_TRACE_OBJECTS_LIST->length());
157
158 CHECK_EQ(1, GET_TRACE_OBJECT(0)->num_args);
159 CHECK_EQ(1, GET_TRACE_OBJECT(1)->num_args);
160 CHECK_EQ(1, GET_TRACE_OBJECT(2)->num_args);
161 CHECK_EQ(1, GET_TRACE_OBJECT(3)->num_args);
162
163 i::V8::SetPlatformForTesting(old_platform);
164 }
165
166
167 TEST(TraceEventWithTwoArgs) {
168 v8::Platform* old_platform = i::V8::GetCurrentPlatform();
169 MockTracingPlatform platform(old_platform);
170 i::V8::SetPlatformForTesting(&platform);
171
172 TRACE_EVENT_BEGIN2("v8-cat", "e1", "arg1", 42, "arg2", "abc");
173 TRACE_EVENT_END2("v8-cat", "e1", "arg1", 42, "arg2", "abc");
174 TRACE_EVENT_BEGIN2("v8-cat", "e2", "arg1", "abc", "arg2", 43);
175 TRACE_EVENT_END2("v8-cat", "e2", "arg1", "abc", "arg2", 43);
176
177 CHECK_EQ(4, GET_TRACE_OBJECTS_LIST->length());
178
179 CHECK_EQ(2, GET_TRACE_OBJECT(0)->num_args);
180 CHECK_EQ(2, GET_TRACE_OBJECT(1)->num_args);
181 CHECK_EQ(2, GET_TRACE_OBJECT(2)->num_args);
182 CHECK_EQ(2, GET_TRACE_OBJECT(3)->num_args);
183
184 i::V8::SetPlatformForTesting(old_platform);
185 }
186
187
188 TEST(ScopedTraceEvent) {
189 v8::Platform* old_platform = i::V8::GetCurrentPlatform();
190 MockTracingPlatform platform(old_platform);
191 i::V8::SetPlatformForTesting(&platform);
192
193 { TRACE_EVENT0("v8-cat", "e"); }
194
195 CHECK_EQ(1, GET_TRACE_OBJECTS_LIST->length());
196 CHECK_EQ(0, GET_TRACE_OBJECT(0)->num_args);
197
198 { TRACE_EVENT1("v8-cat", "e1", "arg1", "abc"); }
199
200 CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->length());
201 CHECK_EQ(1, GET_TRACE_OBJECT(1)->num_args);
202
203 { TRACE_EVENT2("v8-cat", "e1", "arg1", "abc", "arg2", 42); }
204
205 CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->length());
206 CHECK_EQ(2, GET_TRACE_OBJECT(2)->num_args);
207
208 i::V8::SetPlatformForTesting(old_platform);
209 }
210
211
212 TEST(TestEventWithFlow) {
213 v8::Platform* old_platform = i::V8::GetCurrentPlatform();
214 MockTracingPlatform platform(old_platform);
215 i::V8::SetPlatformForTesting(&platform);
216
217 static uint64_t bind_id = 21;
218 {
219 TRACE_EVENT_WITH_FLOW0("v8-cat", "f1", bind_id, TRACE_EVENT_FLAG_FLOW_OUT);
220 }
221 {
222 TRACE_EVENT_WITH_FLOW0(
223 "v8-cat", "f2", bind_id,
224 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT);
225 }
226 { TRACE_EVENT_WITH_FLOW0("v8-cat", "f3", bind_id, TRACE_EVENT_FLAG_FLOW_IN); }
227
228 CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->length());
229 CHECK_EQ(bind_id, GET_TRACE_OBJECT(0)->bind_id);
230 CHECK_EQ(TRACE_EVENT_FLAG_FLOW_OUT, GET_TRACE_OBJECT(0)->flags);
231 CHECK_EQ(bind_id, GET_TRACE_OBJECT(1)->bind_id);
232 CHECK_EQ(TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
233 GET_TRACE_OBJECT(1)->flags);
234 CHECK_EQ(bind_id, GET_TRACE_OBJECT(2)->bind_id);
235 CHECK_EQ(TRACE_EVENT_FLAG_FLOW_IN, GET_TRACE_OBJECT(2)->flags);
236
237 i::V8::SetPlatformForTesting(old_platform);
238 }
239
240
241 TEST(TestEventWithId) {
242 v8::Platform* old_platform = i::V8::GetCurrentPlatform();
243 MockTracingPlatform platform(old_platform);
244 i::V8::SetPlatformForTesting(&platform);
245
246 static uint64_t event_id = 21;
247 TRACE_EVENT_ASYNC_BEGIN0("v8-cat", "a1", event_id);
248 TRACE_EVENT_ASYNC_END0("v8-cat", "a1", event_id);
249
250 CHECK_EQ(2, GET_TRACE_OBJECTS_LIST->length());
251 CHECK_EQ(TRACE_EVENT_PHASE_ASYNC_BEGIN, GET_TRACE_OBJECT(0)->phase);
252 CHECK_EQ(event_id, GET_TRACE_OBJECT(0)->id);
253 CHECK_EQ(TRACE_EVENT_PHASE_ASYNC_END, GET_TRACE_OBJECT(1)->phase);
254 CHECK_EQ(event_id, GET_TRACE_OBJECT(1)->id);
255
256 i::V8::SetPlatformForTesting(old_platform);
257 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698