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

Side by Side Diff: test/cctest/libplatform/test-tracing.cc

Issue 2190973003: [Tracing] V8 Tracing Controller - Add args and copy support (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Use V8_INLINE static for non-class functions Created 4 years, 4 months 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
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include <stdio.h> 4 #include <limits>
5 5
6 #include "include/libplatform/v8-tracing.h" 6 #include "include/libplatform/v8-tracing.h"
7 #include "src/tracing/trace-event.h" 7 #include "src/tracing/trace-event.h"
8 #include "test/cctest/cctest.h" 8 #include "test/cctest/cctest.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace platform { 11 namespace platform {
12 namespace tracing { 12 namespace tracing {
13 13
14 TEST(TestTraceConfig) { 14 TEST(TestTraceConfig) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 'Y', tracing_controller.GetCategoryGroupEnabled("v8-cat"), "Test1", 135 'Y', tracing_controller.GetCategoryGroupEnabled("v8-cat"), "Test1",
136 v8::internal::tracing::kGlobalScope, 43, 456, 0, NULL, NULL, NULL, 0, 136 v8::internal::tracing::kGlobalScope, 43, 456, 0, NULL, NULL, NULL, 0,
137 55, 66, 110, 55, 77, 88); 137 55, 66, 110, 55, 77, 88);
138 writer->AppendTraceEvent(&trace_object); 138 writer->AppendTraceEvent(&trace_object);
139 tracing_controller.StopTracing(); 139 tracing_controller.StopTracing();
140 } 140 }
141 141
142 std::string trace_str = stream.str(); 142 std::string trace_str = stream.str();
143 std::string expected_trace_str = 143 std::string expected_trace_str =
144 "{\"traceEvents\":[{\"pid\":11,\"tid\":22,\"ts\":100,\"tts\":50," 144 "{\"traceEvents\":[{\"pid\":11,\"tid\":22,\"ts\":100,\"tts\":50,"
145 "\"ph\":\"X\",\"cat\":\"v8-cat\",\"name\":\"Test0\",\"args\":{}," 145 "\"ph\":\"X\",\"cat\":\"v8-cat\",\"name\":\"Test0\",\"dur\":33,"
146 "\"dur\":33,\"tdur\":44},{\"pid\":55,\"tid\":66,\"ts\":110,\"tts\":55," 146 "\"tdur\":44,\"args\":{}},{\"pid\":55,\"tid\":66,\"ts\":110,\"tts\":55,"
147 "\"ph\":\"Y\",\"cat\":\"v8-cat\",\"name\":\"Test1\",\"args\":{},\"dur\":" 147 "\"ph\":\"Y\",\"cat\":\"v8-cat\",\"name\":\"Test1\",\"dur\":77,"
148 "77,\"tdur\":88}]}"; 148 "\"tdur\":88,\"args\":{}}]}";
149 149
150 CHECK_EQ(expected_trace_str, trace_str); 150 CHECK_EQ(expected_trace_str, trace_str);
151 151
152 i::V8::SetPlatformForTesting(old_platform); 152 i::V8::SetPlatformForTesting(old_platform);
153 } 153 }
154 154
155 TEST(TestTracingController) { 155 TEST(TestTracingController) {
156 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); 156 v8::Platform* old_platform = i::V8::GetCurrentPlatform();
157 v8::Platform* default_platform = v8::platform::CreateDefaultPlatform(); 157 v8::Platform* default_platform = v8::platform::CreateDefaultPlatform();
158 i::V8::SetPlatformForTesting(default_platform); 158 i::V8::SetPlatformForTesting(default_platform);
(...skipping 15 matching lines...) Expand all
174 TRACE_EVENT0("v8", "v8.Test3"); 174 TRACE_EVENT0("v8", "v8.Test3");
175 tracing_controller.StopTracing(); 175 tracing_controller.StopTracing();
176 176
177 CHECK_EQ(2, writer->events().size()); 177 CHECK_EQ(2, writer->events().size());
178 CHECK_EQ(std::string("v8.Test"), writer->events()[0]); 178 CHECK_EQ(std::string("v8.Test"), writer->events()[0]);
179 CHECK_EQ(std::string("v8.Test3"), writer->events()[1]); 179 CHECK_EQ(std::string("v8.Test3"), writer->events()[1]);
180 180
181 i::V8::SetPlatformForTesting(old_platform); 181 i::V8::SetPlatformForTesting(old_platform);
182 } 182 }
183 183
184 void GetJSONStrings(std::vector<std::string>& ret, std::string str,
185 std::string param, std::string start_delim,
186 std::string end_delim) {
187 size_t pos = str.find(param);
188 while (pos != std::string::npos) {
189 size_t start_pos = str.find(start_delim, pos + param.length());
190 size_t end_pos = str.find(end_delim, start_pos + 1);
191 CHECK_NE(start_pos, std::string::npos);
192 CHECK_NE(end_pos, std::string::npos);
193 ret.push_back(str.substr(start_pos + 1, end_pos - start_pos - 1));
194 pos = str.find(param, pos + 1);
195 }
196 }
197
198 TEST(TestTracingControllerMultipleArgsAndCopy) {
199 std::ostringstream stream;
200 v8::Platform* old_platform = i::V8::GetCurrentPlatform();
201 v8::Platform* default_platform = v8::platform::CreateDefaultPlatform();
202 i::V8::SetPlatformForTesting(default_platform);
203
204 uint64_t aa = 11;
205 unsigned int bb = 22;
206 uint16_t cc = 33;
207 unsigned char dd = 44;
208 int64_t ee = -55;
209 int ff = -66;
210 int16_t gg = -77;
211 signed char hh = -88;
212 bool ii1 = true;
213 bool ii2 = false;
214 double jj1 = 99.0;
215 double jj2 = 1e100;
216 double jj3 = std::numeric_limits<double>::quiet_NaN();
217 double jj4 = std::numeric_limits<double>::infinity();
218 double jj5 = -std::numeric_limits<double>::infinity();
219 void* kk = &aa;
220 const char* ll = "100";
221 std::string mm = "INIT";
222
223 // Create a scope for the tracing controller to terminate the trace writer.
224 {
225 TracingController tracing_controller;
226 platform::SetTracingController(default_platform, &tracing_controller);
227 TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream);
228
229 TraceBuffer* ring_buffer =
230 TraceBuffer::CreateTraceBufferRingBuffer(1, writer);
231 tracing_controller.Initialize(ring_buffer);
232 TraceConfig* trace_config = new TraceConfig();
233 trace_config->AddIncludedCategory("v8");
234 tracing_controller.StartTracing(trace_config);
235
236 TRACE_EVENT1("v8", "v8.Test.aa", "aa", aa);
237 TRACE_EVENT1("v8", "v8.Test.bb", "bb", bb);
238 TRACE_EVENT1("v8", "v8.Test.cc", "cc", cc);
239 TRACE_EVENT1("v8", "v8.Test.dd", "dd", dd);
240 TRACE_EVENT1("v8", "v8.Test.ee", "ee", ee);
241 TRACE_EVENT1("v8", "v8.Test.ff", "ff", ff);
242 TRACE_EVENT1("v8", "v8.Test.gg", "gg", gg);
243 TRACE_EVENT1("v8", "v8.Test.hh", "hh", hh);
244 TRACE_EVENT1("v8", "v8.Test.ii", "ii1", ii1);
245 TRACE_EVENT1("v8", "v8.Test.ii", "ii2", ii2);
246 TRACE_EVENT1("v8", "v8.Test.jj1", "jj1", jj1);
247 TRACE_EVENT1("v8", "v8.Test.jj2", "jj2", jj2);
248 TRACE_EVENT1("v8", "v8.Test.jj3", "jj3", jj3);
249 TRACE_EVENT1("v8", "v8.Test.jj4", "jj4", jj4);
250 TRACE_EVENT1("v8", "v8.Test.jj5", "jj5", jj5);
251 TRACE_EVENT1("v8", "v8.Test.kk", "kk", kk);
252 TRACE_EVENT1("v8", "v8.Test.ll", "ll", ll);
253 TRACE_EVENT1("v8", "v8.Test.mm", "mm", TRACE_STR_COPY(mm.c_str()));
254
255 TRACE_EVENT2("v8", "v8.Test2.1", "aa", aa, "ll", ll);
256 TRACE_EVENT2("v8", "v8.Test2.2", "mm1", TRACE_STR_COPY(mm.c_str()), "mm2",
257 TRACE_STR_COPY(mm.c_str()));
258
259 // Check copies are correct.
260 TRACE_EVENT_COPY_INSTANT0("v8", mm.c_str(), TRACE_EVENT_SCOPE_THREAD);
261 TRACE_EVENT_COPY_INSTANT1("v8", mm.c_str(), TRACE_EVENT_SCOPE_THREAD,
262 mm.c_str(), mm.c_str());
263 TRACE_EVENT_COPY_INSTANT2("v8", mm.c_str(), TRACE_EVENT_SCOPE_THREAD,
264 mm.c_str(), mm.c_str(), mm.c_str(), mm.c_str());
265 mm = "CHANGED";
266
267 tracing_controller.StopTracing();
268 }
269
270 std::string trace_str = stream.str();
271
272 std::vector<std::string> all_args, all_names, all_cats;
273 GetJSONStrings(all_args, trace_str, "\"args\"", "{", "}");
274 GetJSONStrings(all_names, trace_str, "\"name\"", "\"", "\"");
275 GetJSONStrings(all_cats, trace_str, "\"cat\"", "\"", "\"");
276
277 CHECK_EQ(all_args.size(), 23);
278 CHECK_EQ(all_args[0], "\"aa\":11");
279 CHECK_EQ(all_args[1], "\"bb\":22");
280 CHECK_EQ(all_args[2], "\"cc\":33");
281 CHECK_EQ(all_args[3], "\"dd\":44");
282 CHECK_EQ(all_args[4], "\"ee\":-55");
283 CHECK_EQ(all_args[5], "\"ff\":-66");
284 CHECK_EQ(all_args[6], "\"gg\":-77");
285 CHECK_EQ(all_args[7], "\"hh\":-88");
286 CHECK_EQ(all_args[8], "\"ii1\":true");
287 CHECK_EQ(all_args[9], "\"ii2\":false");
288 CHECK_EQ(all_args[10], "\"jj1\":99.0");
289 CHECK_EQ(all_args[11], "\"jj2\":1e+100");
290 CHECK_EQ(all_args[12], "\"jj3\":\"NaN\"");
291 CHECK_EQ(all_args[13], "\"jj4\":\"Infinity\"");
292 CHECK_EQ(all_args[14], "\"jj5\":\"-Infinity\"");
293 std::ostringstream pointer_stream;
294 pointer_stream << "\"kk\":\"" << &aa << "\"";
295 CHECK_EQ(all_args[15], pointer_stream.str());
296 CHECK_EQ(all_args[16], "\"ll\":\"100\"");
297 CHECK_EQ(all_args[17], "\"mm\":\"INIT\"");
298
299 CHECK_EQ(all_names[18], "v8.Test2.1");
300 CHECK_EQ(all_args[18], "\"aa\":11,\"ll\":\"100\"");
301 CHECK_EQ(all_args[19], "\"mm1\":\"INIT\",\"mm2\":\"INIT\"");
302
303 CHECK_EQ(all_names[20], "INIT");
304 CHECK_EQ(all_names[21], "INIT");
305 CHECK_EQ(all_args[21], "\"INIT\":\"INIT\"");
306 CHECK_EQ(all_names[22], "INIT");
307 CHECK_EQ(all_args[22], "\"INIT\":\"INIT\",\"INIT\":\"INIT\"");
308
309 i::V8::SetPlatformForTesting(old_platform);
310 }
311
184 } // namespace tracing 312 } // namespace tracing
185 } // namespace platform 313 } // namespace platform
186 } // namespace v8 314 } // namespace v8
OLDNEW
« src/libplatform/tracing/trace-object.cc ('K') | « src/libplatform/tracing/trace-writer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698