OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
11 #include "base/test/trace_event_analyzer.h" | 11 #include "base/test/trace_event_analyzer.h" |
12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
13 #include "base/trace_event/trace_buffer.h" | 13 #include "base/trace_event/trace_buffer.h" |
| 14 #include "base/trace_event/trace_event_argument.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace trace_analyzer { | 18 namespace trace_analyzer { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 class TraceEventAnalyzerTest : public testing::Test { | 22 class TraceEventAnalyzerTest : public testing::Test { |
22 public: | 23 public: |
23 void ManualSetUp(); | 24 void ManualSetUp(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 int int_num = 2; | 92 int int_num = 2; |
92 double double_num = 3.5; | 93 double double_num = 3.5; |
93 const char str[] = "the string"; | 94 const char str[] = "the string"; |
94 | 95 |
95 TraceEvent event; | 96 TraceEvent event; |
96 event.arg_numbers["false"] = 0.0; | 97 event.arg_numbers["false"] = 0.0; |
97 event.arg_numbers["true"] = 1.0; | 98 event.arg_numbers["true"] = 1.0; |
98 event.arg_numbers["int"] = static_cast<double>(int_num); | 99 event.arg_numbers["int"] = static_cast<double>(int_num); |
99 event.arg_numbers["double"] = double_num; | 100 event.arg_numbers["double"] = double_num; |
100 event.arg_strings["string"] = str; | 101 event.arg_strings["string"] = str; |
| 102 event.arg_values["dict"] = make_scoped_ptr(new base::DictionaryValue()); |
101 | 103 |
102 ASSERT_TRUE(event.HasNumberArg("false")); | 104 ASSERT_TRUE(event.HasNumberArg("false")); |
103 ASSERT_TRUE(event.HasNumberArg("true")); | 105 ASSERT_TRUE(event.HasNumberArg("true")); |
104 ASSERT_TRUE(event.HasNumberArg("int")); | 106 ASSERT_TRUE(event.HasNumberArg("int")); |
105 ASSERT_TRUE(event.HasNumberArg("double")); | 107 ASSERT_TRUE(event.HasNumberArg("double")); |
106 ASSERT_TRUE(event.HasStringArg("string")); | 108 ASSERT_TRUE(event.HasStringArg("string")); |
107 ASSERT_FALSE(event.HasNumberArg("notfound")); | 109 ASSERT_FALSE(event.HasNumberArg("notfound")); |
108 ASSERT_FALSE(event.HasStringArg("notfound")); | 110 ASSERT_FALSE(event.HasStringArg("notfound")); |
| 111 ASSERT_TRUE(event.HasArg("dict")); |
| 112 ASSERT_FALSE(event.HasArg("notfound")); |
109 | 113 |
110 EXPECT_FALSE(event.GetKnownArgAsBool("false")); | 114 EXPECT_FALSE(event.GetKnownArgAsBool("false")); |
111 EXPECT_TRUE(event.GetKnownArgAsBool("true")); | 115 EXPECT_TRUE(event.GetKnownArgAsBool("true")); |
112 EXPECT_EQ(int_num, event.GetKnownArgAsInt("int")); | 116 EXPECT_EQ(int_num, event.GetKnownArgAsInt("int")); |
113 EXPECT_EQ(double_num, event.GetKnownArgAsDouble("double")); | 117 EXPECT_EQ(double_num, event.GetKnownArgAsDouble("double")); |
114 EXPECT_STREQ(str, event.GetKnownArgAsString("string").c_str()); | 118 EXPECT_STREQ(str, event.GetKnownArgAsString("string").c_str()); |
| 119 |
| 120 scoped_ptr<base::Value> arg; |
| 121 EXPECT_TRUE(event.GetArgAsValue("dict", &arg)); |
| 122 EXPECT_EQ(base::Value::TYPE_DICTIONARY, arg->GetType()); |
115 } | 123 } |
116 | 124 |
117 TEST_F(TraceEventAnalyzerTest, QueryEventMember) { | 125 TEST_F(TraceEventAnalyzerTest, QueryEventMember) { |
118 ManualSetUp(); | 126 ManualSetUp(); |
119 | 127 |
120 TraceEvent event; | 128 TraceEvent event; |
121 event.thread.process_id = 3; | 129 event.thread.process_id = 3; |
122 event.thread.thread_id = 4; | 130 event.thread.thread_id = 4; |
123 event.timestamp = 1.5; | 131 event.timestamp = 1.5; |
124 event.phase = TRACE_EVENT_PHASE_BEGIN; | 132 event.phase = TRACE_EVENT_PHASE_BEGIN; |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 | 896 |
889 EXPECT_EQ(0u, CountMatches(event_ptrs, Query::Bool(false))); | 897 EXPECT_EQ(0u, CountMatches(event_ptrs, Query::Bool(false))); |
890 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); | 898 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); |
891 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), | 899 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), |
892 1, num_events)); | 900 1, num_events)); |
893 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); | 901 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); |
894 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); | 902 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); |
895 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); | 903 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); |
896 } | 904 } |
897 | 905 |
| 906 TEST_F(TraceEventAnalyzerTest, ComplexArgument) { |
| 907 ManualSetUp(); |
| 908 |
| 909 BeginTracing(); |
| 910 { |
| 911 scoped_ptr<base::trace_event::TracedValue> value( |
| 912 new base::trace_event::TracedValue); |
| 913 value->SetString("property", "value"); |
| 914 TRACE_EVENT1("cat", "name", "arg", std::move(value)); |
| 915 } |
| 916 EndTracing(); |
| 917 |
| 918 scoped_ptr<TraceAnalyzer> analyzer( |
| 919 TraceAnalyzer::Create(output_.json_output)); |
| 920 ASSERT_TRUE(analyzer.get()); |
| 921 |
| 922 TraceEventVector events; |
| 923 analyzer->FindEvents(Query::EventName() == Query::String("name"), &events); |
| 924 |
| 925 EXPECT_EQ(1u, events.size()); |
| 926 EXPECT_EQ("cat", events[0]->category); |
| 927 EXPECT_EQ("name", events[0]->name); |
| 928 EXPECT_TRUE(events[0]->HasArg("arg")); |
| 929 |
| 930 scoped_ptr<base::Value> arg; |
| 931 events[0]->GetArgAsValue("arg", &arg); |
| 932 base::DictionaryValue* arg_dict; |
| 933 EXPECT_TRUE(arg->GetAsDictionary(&arg_dict)); |
| 934 std::string property; |
| 935 EXPECT_TRUE(arg_dict->GetString("property", &property)); |
| 936 EXPECT_EQ("value", property); |
| 937 } |
898 | 938 |
899 } // namespace trace_analyzer | 939 } // namespace trace_analyzer |
OLD | NEW |