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 20 matching lines...) Expand all Loading... |
31 TEST(TestTraceObject) { | 31 TEST(TestTraceObject) { |
32 TraceObject trace_object; | 32 TraceObject trace_object; |
33 uint8_t category_enabled_flag = 41; | 33 uint8_t category_enabled_flag = 41; |
34 trace_object.Initialize('X', &category_enabled_flag, "Test.Trace", | 34 trace_object.Initialize('X', &category_enabled_flag, "Test.Trace", |
35 "Test.Scope", 42, 123, 0, nullptr, nullptr, nullptr, | 35 "Test.Scope", 42, 123, 0, nullptr, nullptr, nullptr, |
36 nullptr, 0); | 36 nullptr, 0); |
37 CHECK_EQ('X', trace_object.phase()); | 37 CHECK_EQ('X', trace_object.phase()); |
38 CHECK_EQ(category_enabled_flag, *trace_object.category_enabled_flag()); | 38 CHECK_EQ(category_enabled_flag, *trace_object.category_enabled_flag()); |
39 CHECK_EQ(std::string("Test.Trace"), std::string(trace_object.name())); | 39 CHECK_EQ(std::string("Test.Trace"), std::string(trace_object.name())); |
40 CHECK_EQ(std::string("Test.Scope"), std::string(trace_object.scope())); | 40 CHECK_EQ(std::string("Test.Scope"), std::string(trace_object.scope())); |
41 CHECK_EQ(0, trace_object.duration()); | 41 CHECK_EQ(0u, trace_object.duration()); |
42 CHECK_EQ(0, trace_object.cpu_duration()); | 42 CHECK_EQ(0u, trace_object.cpu_duration()); |
43 } | 43 } |
44 | 44 |
45 class ConvertableToTraceFormatMock : public v8::ConvertableToTraceFormat { | 45 class ConvertableToTraceFormatMock : public v8::ConvertableToTraceFormat { |
46 public: | 46 public: |
47 explicit ConvertableToTraceFormatMock(int value) : value_(value) {} | 47 explicit ConvertableToTraceFormatMock(int value) : value_(value) {} |
48 void AppendAsTraceFormat(std::string* out) const override { | 48 void AppendAsTraceFormat(std::string* out) const override { |
49 *out += "[" + std::to_string(value_) + "," + std::to_string(value_) + "]"; | 49 *out += "[" + std::to_string(value_) + "," + std::to_string(value_) + "]"; |
50 } | 50 } |
51 | 51 |
52 private: | 52 private: |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 TraceConfig* trace_config = new TraceConfig(); | 179 TraceConfig* trace_config = new TraceConfig(); |
180 trace_config->AddIncludedCategory("v8"); | 180 trace_config->AddIncludedCategory("v8"); |
181 tracing_controller.StartTracing(trace_config); | 181 tracing_controller.StartTracing(trace_config); |
182 | 182 |
183 TRACE_EVENT0("v8", "v8.Test"); | 183 TRACE_EVENT0("v8", "v8.Test"); |
184 // cat category is not included in default config | 184 // cat category is not included in default config |
185 TRACE_EVENT0("cat", "v8.Test2"); | 185 TRACE_EVENT0("cat", "v8.Test2"); |
186 TRACE_EVENT0("v8", "v8.Test3"); | 186 TRACE_EVENT0("v8", "v8.Test3"); |
187 tracing_controller.StopTracing(); | 187 tracing_controller.StopTracing(); |
188 | 188 |
189 CHECK_EQ(2, writer->events().size()); | 189 CHECK_EQ(2u, writer->events().size()); |
190 CHECK_EQ(std::string("v8.Test"), writer->events()[0]); | 190 CHECK_EQ(std::string("v8.Test"), writer->events()[0]); |
191 CHECK_EQ(std::string("v8.Test3"), writer->events()[1]); | 191 CHECK_EQ(std::string("v8.Test3"), writer->events()[1]); |
192 | 192 |
193 i::V8::SetPlatformForTesting(old_platform); | 193 i::V8::SetPlatformForTesting(old_platform); |
194 } | 194 } |
195 | 195 |
196 void GetJSONStrings(std::vector<std::string>& ret, std::string str, | 196 void GetJSONStrings(std::vector<std::string>& ret, std::string str, |
197 std::string param, std::string start_delim, | 197 std::string param, std::string start_delim, |
198 std::string end_delim) { | 198 std::string end_delim) { |
199 size_t pos = str.find(param); | 199 size_t pos = str.find(param); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 tracing_controller.StopTracing(); | 287 tracing_controller.StopTracing(); |
288 } | 288 } |
289 | 289 |
290 std::string trace_str = stream.str(); | 290 std::string trace_str = stream.str(); |
291 | 291 |
292 std::vector<std::string> all_args, all_names, all_cats; | 292 std::vector<std::string> all_args, all_names, all_cats; |
293 GetJSONStrings(all_args, trace_str, "\"args\"", "{", "}"); | 293 GetJSONStrings(all_args, trace_str, "\"args\"", "{", "}"); |
294 GetJSONStrings(all_names, trace_str, "\"name\"", "\"", "\""); | 294 GetJSONStrings(all_names, trace_str, "\"name\"", "\"", "\""); |
295 GetJSONStrings(all_cats, trace_str, "\"cat\"", "\"", "\""); | 295 GetJSONStrings(all_cats, trace_str, "\"cat\"", "\"", "\""); |
296 | 296 |
297 CHECK_EQ(all_args.size(), 24); | 297 CHECK_EQ(all_args.size(), 24u); |
298 CHECK_EQ(all_args[0], "\"aa\":11"); | 298 CHECK_EQ(all_args[0], "\"aa\":11"); |
299 CHECK_EQ(all_args[1], "\"bb\":22"); | 299 CHECK_EQ(all_args[1], "\"bb\":22"); |
300 CHECK_EQ(all_args[2], "\"cc\":33"); | 300 CHECK_EQ(all_args[2], "\"cc\":33"); |
301 CHECK_EQ(all_args[3], "\"dd\":44"); | 301 CHECK_EQ(all_args[3], "\"dd\":44"); |
302 CHECK_EQ(all_args[4], "\"ee\":-55"); | 302 CHECK_EQ(all_args[4], "\"ee\":-55"); |
303 CHECK_EQ(all_args[5], "\"ff\":-66"); | 303 CHECK_EQ(all_args[5], "\"ff\":-66"); |
304 CHECK_EQ(all_args[6], "\"gg\":-77"); | 304 CHECK_EQ(all_args[6], "\"gg\":-77"); |
305 CHECK_EQ(all_args[7], "\"hh\":-88"); | 305 CHECK_EQ(all_args[7], "\"hh\":-88"); |
306 CHECK_EQ(all_args[8], "\"ii1\":true"); | 306 CHECK_EQ(all_args[8], "\"ii1\":true"); |
307 CHECK_EQ(all_args[9], "\"ii2\":false"); | 307 CHECK_EQ(all_args[9], "\"ii2\":false"); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 398 |
399 CHECK_EQ(1, observer.enabled_count); | 399 CHECK_EQ(1, observer.enabled_count); |
400 CHECK_EQ(1, observer.disabled_count); | 400 CHECK_EQ(1, observer.disabled_count); |
401 | 401 |
402 i::V8::SetPlatformForTesting(old_platform); | 402 i::V8::SetPlatformForTesting(old_platform); |
403 } | 403 } |
404 | 404 |
405 } // namespace tracing | 405 } // namespace tracing |
406 } // namespace platform | 406 } // namespace platform |
407 } // namespace v8 | 407 } // namespace v8 |
OLD | NEW |