OLD | NEW |
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 <limits> | 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 { |
(...skipping 26 matching lines...) Expand all Loading... |
37 trace_object.Initialize('X', &category_enabled_flag, "Test.Trace", | 37 trace_object.Initialize('X', &category_enabled_flag, "Test.Trace", |
38 "Test.Scope", 42, 123, 0, NULL, NULL, NULL, 0); | 38 "Test.Scope", 42, 123, 0, NULL, NULL, NULL, 0); |
39 CHECK_EQ('X', trace_object.phase()); | 39 CHECK_EQ('X', trace_object.phase()); |
40 CHECK_EQ(category_enabled_flag, *trace_object.category_enabled_flag()); | 40 CHECK_EQ(category_enabled_flag, *trace_object.category_enabled_flag()); |
41 CHECK_EQ(std::string("Test.Trace"), std::string(trace_object.name())); | 41 CHECK_EQ(std::string("Test.Trace"), std::string(trace_object.name())); |
42 CHECK_EQ(std::string("Test.Scope"), std::string(trace_object.scope())); | 42 CHECK_EQ(std::string("Test.Scope"), std::string(trace_object.scope())); |
43 CHECK_EQ(0, trace_object.duration()); | 43 CHECK_EQ(0, trace_object.duration()); |
44 CHECK_EQ(0, trace_object.cpu_duration()); | 44 CHECK_EQ(0, trace_object.cpu_duration()); |
45 } | 45 } |
46 | 46 |
| 47 class ConvertableToTraceFormatMock : public v8::ConvertableToTraceFormat { |
| 48 public: |
| 49 explicit ConvertableToTraceFormatMock(int value) : value_(value) {} |
| 50 |
| 51 void AppendAsTraceFormat(std::string* out) const override { |
| 52 *out += "[" + std::to_string(value_) + "," + std::to_string(value_) + "]"; |
| 53 } |
| 54 |
| 55 private: |
| 56 int value_; |
| 57 }; |
| 58 |
47 class MockTraceWriter : public TraceWriter { | 59 class MockTraceWriter : public TraceWriter { |
48 public: | 60 public: |
49 void AppendTraceEvent(TraceObject* trace_event) override { | 61 void AppendTraceEvent(TraceObject* trace_event) override { |
50 events_.push_back(trace_event->name()); | 62 events_.push_back(trace_event->name()); |
51 } | 63 } |
52 | 64 |
53 void Flush() override {} | 65 void Flush() override {} |
54 | 66 |
55 std::vector<std::string> events() { return events_; } | 67 std::vector<std::string> events() { return events_; } |
56 | 68 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 TRACE_EVENT2("v8", "v8.Test2.2", "mm1", TRACE_STR_COPY(mm.c_str()), "mm2", | 269 TRACE_EVENT2("v8", "v8.Test2.2", "mm1", TRACE_STR_COPY(mm.c_str()), "mm2", |
258 TRACE_STR_COPY(mmm.c_str())); | 270 TRACE_STR_COPY(mmm.c_str())); |
259 | 271 |
260 // Check copies are correct. | 272 // Check copies are correct. |
261 TRACE_EVENT_COPY_INSTANT0("v8", mm.c_str(), TRACE_EVENT_SCOPE_THREAD); | 273 TRACE_EVENT_COPY_INSTANT0("v8", mm.c_str(), TRACE_EVENT_SCOPE_THREAD); |
262 TRACE_EVENT_COPY_INSTANT2("v8", mm.c_str(), TRACE_EVENT_SCOPE_THREAD, "mm1", | 274 TRACE_EVENT_COPY_INSTANT2("v8", mm.c_str(), TRACE_EVENT_SCOPE_THREAD, "mm1", |
263 mm.c_str(), "mm2", mmm.c_str()); | 275 mm.c_str(), "mm2", mmm.c_str()); |
264 mm = "CHANGED"; | 276 mm = "CHANGED"; |
265 mmm = "CHANGED"; | 277 mmm = "CHANGED"; |
266 | 278 |
| 279 TRACE_EVENT_INSTANT1("v8", "v8.Test", TRACE_EVENT_SCOPE_THREAD, "a1", |
| 280 new ConvertableToTraceFormatMock(42)); |
| 281 TRACE_EVENT_INSTANT2("v8", "v8.Test", TRACE_EVENT_SCOPE_THREAD, "a1", |
| 282 new ConvertableToTraceFormatMock(42), "a2", |
| 283 new ConvertableToTraceFormatMock(123)); |
| 284 |
267 tracing_controller.StopTracing(); | 285 tracing_controller.StopTracing(); |
268 } | 286 } |
269 | 287 |
270 std::string trace_str = stream.str(); | 288 std::string trace_str = stream.str(); |
271 | 289 |
272 std::vector<std::string> all_args, all_names, all_cats; | 290 std::vector<std::string> all_args, all_names, all_cats; |
273 GetJSONStrings(all_args, trace_str, "\"args\"", "{", "}"); | 291 GetJSONStrings(all_args, trace_str, "\"args\"", "{", "}"); |
274 GetJSONStrings(all_names, trace_str, "\"name\"", "\"", "\""); | 292 GetJSONStrings(all_names, trace_str, "\"name\"", "\"", "\""); |
275 GetJSONStrings(all_cats, trace_str, "\"cat\"", "\"", "\""); | 293 GetJSONStrings(all_cats, trace_str, "\"cat\"", "\"", "\""); |
276 | 294 |
277 CHECK_EQ(all_args.size(), 22); | 295 CHECK_EQ(all_args.size(), 24); |
278 CHECK_EQ(all_args[0], "\"aa\":11"); | 296 CHECK_EQ(all_args[0], "\"aa\":11"); |
279 CHECK_EQ(all_args[1], "\"bb\":22"); | 297 CHECK_EQ(all_args[1], "\"bb\":22"); |
280 CHECK_EQ(all_args[2], "\"cc\":33"); | 298 CHECK_EQ(all_args[2], "\"cc\":33"); |
281 CHECK_EQ(all_args[3], "\"dd\":44"); | 299 CHECK_EQ(all_args[3], "\"dd\":44"); |
282 CHECK_EQ(all_args[4], "\"ee\":-55"); | 300 CHECK_EQ(all_args[4], "\"ee\":-55"); |
283 CHECK_EQ(all_args[5], "\"ff\":-66"); | 301 CHECK_EQ(all_args[5], "\"ff\":-66"); |
284 CHECK_EQ(all_args[6], "\"gg\":-77"); | 302 CHECK_EQ(all_args[6], "\"gg\":-77"); |
285 CHECK_EQ(all_args[7], "\"hh\":-88"); | 303 CHECK_EQ(all_args[7], "\"hh\":-88"); |
286 CHECK_EQ(all_args[8], "\"ii1\":true"); | 304 CHECK_EQ(all_args[8], "\"ii1\":true"); |
287 CHECK_EQ(all_args[9], "\"ii2\":false"); | 305 CHECK_EQ(all_args[9], "\"ii2\":false"); |
288 CHECK_EQ(all_args[10], "\"jj1\":99.0"); | 306 CHECK_EQ(all_args[10], "\"jj1\":99.0"); |
289 CHECK_EQ(all_args[11], "\"jj2\":1e+100"); | 307 CHECK_EQ(all_args[11], "\"jj2\":1e+100"); |
290 CHECK_EQ(all_args[12], "\"jj3\":\"NaN\""); | 308 CHECK_EQ(all_args[12], "\"jj3\":\"NaN\""); |
291 CHECK_EQ(all_args[13], "\"jj4\":\"Infinity\""); | 309 CHECK_EQ(all_args[13], "\"jj4\":\"Infinity\""); |
292 CHECK_EQ(all_args[14], "\"jj5\":\"-Infinity\""); | 310 CHECK_EQ(all_args[14], "\"jj5\":\"-Infinity\""); |
293 std::ostringstream pointer_stream; | 311 std::ostringstream pointer_stream; |
294 pointer_stream << "\"kk\":\"" << &aa << "\""; | 312 pointer_stream << "\"kk\":\"" << &aa << "\""; |
295 CHECK_EQ(all_args[15], pointer_stream.str()); | 313 CHECK_EQ(all_args[15], pointer_stream.str()); |
296 CHECK_EQ(all_args[16], "\"ll\":\"100\""); | 314 CHECK_EQ(all_args[16], "\"ll\":\"100\""); |
297 CHECK_EQ(all_args[17], "\"mm\":\"\\\"INIT\\\"\""); | 315 CHECK_EQ(all_args[17], "\"mm\":\"\\\"INIT\\\"\""); |
298 | 316 |
299 CHECK_EQ(all_names[18], "v8.Test2.1"); | 317 CHECK_EQ(all_names[18], "v8.Test2.1"); |
300 CHECK_EQ(all_args[18], "\"aa\":11,\"ll\":\"100\""); | 318 CHECK_EQ(all_args[18], "\"aa\":11,\"ll\":\"100\""); |
301 CHECK_EQ(all_args[19], "\"mm1\":\"INIT\",\"mm2\":\"\\\"INIT\\\"\""); | 319 CHECK_EQ(all_args[19], "\"mm1\":\"INIT\",\"mm2\":\"\\\"INIT\\\"\""); |
302 | 320 |
303 CHECK_EQ(all_names[20], "INIT"); | 321 CHECK_EQ(all_names[20], "INIT"); |
304 CHECK_EQ(all_names[21], "INIT"); | 322 CHECK_EQ(all_names[21], "INIT"); |
305 CHECK_EQ(all_args[21], "\"mm1\":\"INIT\",\"mm2\":\"\\\"INIT\\\"\""); | 323 CHECK_EQ(all_args[21], "\"mm1\":\"INIT\",\"mm2\":\"\\\"INIT\\\"\""); |
| 324 CHECK_EQ(all_args[22], "\"a1\":[42,42]"); |
| 325 CHECK_EQ(all_args[23], "\"a1\":[42,42],\"a2\":[123,123]"); |
306 | 326 |
307 i::V8::SetPlatformForTesting(old_platform); | 327 i::V8::SetPlatformForTesting(old_platform); |
308 } | 328 } |
309 | 329 |
310 } // namespace tracing | 330 } // namespace tracing |
311 } // namespace platform | 331 } // namespace platform |
312 } // namespace v8 | 332 } // namespace v8 |
OLD | NEW |