OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium 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 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
| 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" |
7 #include "base/macros.h" | 9 #include "base/macros.h" |
8 #include "base/trace_event/memory_dump_manager.h" | 10 #include "base/trace_event/memory_dump_manager.h" |
9 #include "base/trace_event/trace_config.h" | 11 #include "base/trace_event/trace_config.h" |
10 #include "base/trace_event/trace_config_memory_test_util.h" | 12 #include "base/trace_event/trace_config_memory_test_util.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 namespace base { | 15 namespace base { |
14 namespace trace_event { | 16 namespace trace_event { |
15 | 17 |
16 namespace { | 18 namespace { |
17 | 19 |
18 const char kDefaultTraceConfigString[] = | 20 const char kDefaultTraceConfigString[] = |
19 "{" | 21 "{" |
20 "\"enable_argument_filter\":false," | 22 "\"enable_argument_filter\":false," |
21 "\"enable_sampling\":false," | 23 "\"enable_sampling\":false," |
22 "\"enable_systrace\":false," | 24 "\"enable_systrace\":false," |
23 "\"excluded_categories\":[\"*Debug\",\"*Test\"]," | 25 "\"excluded_categories\":[\"*Debug\",\"*Test\"]," |
24 "\"record_mode\":\"record-until-full\"" | 26 "\"record_mode\":\"record-until-full\"" |
25 "}"; | 27 "}"; |
| 28 |
| 29 const char kCustomTraceConfigString[] = |
| 30 "{" |
| 31 "\"enable_argument_filter\":true," |
| 32 "\"enable_sampling\":true," |
| 33 "\"enable_systrace\":true," |
| 34 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"]," |
| 35 "\"included_categories\":[\"included\"," |
| 36 "\"inc_pattern*\"," |
| 37 "\"disabled-by-default-cc\"," |
| 38 "\"disabled-by-default-memory-infra\"]," |
| 39 "\"memory_dump_config\":{" |
| 40 "\"triggers\":[" |
| 41 "{\"mode\":\"light\",\"periodic_interval_ms\":50}," |
| 42 "{\"mode\":\"detailed\",\"periodic_interval_ms\":1000}" |
| 43 "]" |
| 44 "}," |
| 45 "\"record_mode\":\"record-continuously\"," |
| 46 "\"synthetic_delays\":[\"test.Delay1;16\",\"test.Delay2;32\"]" |
| 47 "}"; |
| 48 |
| 49 const char kCustomTraceConfigStringDevtoolsStyle[] = |
| 50 "{" |
| 51 "\"enableArgumentFilter\":true," |
| 52 "\"enableSampling\":true," |
| 53 "\"enableSystrace\":true," |
| 54 "\"excludedCategories\":[\"excluded\",\"exc_pattern*\"]," |
| 55 "\"includedCategories\":[\"included\"," |
| 56 "\"inc_pattern*\"," |
| 57 "\"disabled-by-default-cc\"," |
| 58 "\"disabled-by-default-memory-infra\"]," |
| 59 "\"memoryDumpConfig\":{" |
| 60 "\"triggers\":[" |
| 61 "{\"mode\":\"light\",\"periodicIntervalMs\":50}," |
| 62 "{\"mode\":\"detailed\",\"periodicIntervalMs\":1000}" |
| 63 "]" |
| 64 "}," |
| 65 "\"recordMode\":\"recordContinuously\"," |
| 66 "\"synthetic_delays\":[\"test.Delay1;16\",\"test.Delay2;32\"]" |
| 67 "}"; |
| 68 |
26 } // namespace | 69 } // namespace |
27 | 70 |
28 TEST(TraceConfigTest, TraceConfigFromValidLegacyFormat) { | 71 TEST(TraceConfigTest, TraceConfigFromValidLegacyFormat) { |
29 // From trace options strings | 72 // From trace options strings |
30 TraceConfig config("", "record-until-full"); | 73 TraceConfig config("", "record-until-full"); |
31 EXPECT_EQ(RECORD_UNTIL_FULL, config.GetTraceRecordMode()); | 74 EXPECT_EQ(RECORD_UNTIL_FULL, config.GetTraceRecordMode()); |
32 EXPECT_FALSE(config.IsSamplingEnabled()); | 75 EXPECT_FALSE(config.IsSamplingEnabled()); |
33 EXPECT_FALSE(config.IsSystraceEnabled()); | 76 EXPECT_FALSE(config.IsSystraceEnabled()); |
34 EXPECT_FALSE(config.IsArgumentFilterEnabled()); | 77 EXPECT_FALSE(config.IsArgumentFilterEnabled()); |
35 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str()); | 78 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str()); |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 EXPECT_EQ(0u, tc.memory_dump_config_.size()); | 566 EXPECT_EQ(0u, tc.memory_dump_config_.size()); |
524 } | 567 } |
525 | 568 |
526 TEST(TraceConfigTest, LegacyStringToMemoryDumpConfig) { | 569 TEST(TraceConfigTest, LegacyStringToMemoryDumpConfig) { |
527 TraceConfig tc(MemoryDumpManager::kTraceCategory, ""); | 570 TraceConfig tc(MemoryDumpManager::kTraceCategory, ""); |
528 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory)); | 571 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory)); |
529 EXPECT_NE(std::string::npos, tc.ToString().find("memory_dump_config")); | 572 EXPECT_NE(std::string::npos, tc.ToString().find("memory_dump_config")); |
530 EXPECT_EQ(2u, tc.memory_dump_config_.size()); | 573 EXPECT_EQ(2u, tc.memory_dump_config_.size()); |
531 } | 574 } |
532 | 575 |
| 576 TEST(TraceConfigTest, DevToolsToTracingStyleForDict) { |
| 577 scoped_ptr<Value> value = base::JSONReader::Read( |
| 578 kCustomTraceConfigStringDevtoolsStyle); |
| 579 scoped_ptr<base::DictionaryValue> devtools_style_dict( |
| 580 static_cast<base::DictionaryValue*>(value.release())); |
| 581 scoped_ptr<base::DictionaryValue> tracing_style_dict = |
| 582 TraceConfig::DevToolsToTracingStyle(devtools_style_dict); |
| 583 |
| 584 std::string tracing_style_str; |
| 585 base::JSONWriter::Write(*tracing_style_dict, &tracing_style_str); |
| 586 EXPECT_STREQ(kCustomTraceConfigString, tracing_style_str.c_str()); |
| 587 } |
| 588 |
| 589 TEST(TraceConfigTest, DevToolsToTracingStyleForString) { |
| 590 std::string tracing_style = TraceConfig::DevToolsToTracingStyle( |
| 591 kCustomTraceConfigStringDevtoolsStyle); |
| 592 |
| 593 EXPECT_STREQ(kCustomTraceConfigString, tracing_style.c_str()); |
| 594 } |
| 595 |
533 } // namespace trace_event | 596 } // namespace trace_event |
534 } // namespace base | 597 } // namespace base |
OLD | NEW |