| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/test/trace_event_analyzer.h" | 6 #include "base/test/trace_event_analyzer.h" |
| 7 #include "testing/gmock/include/gmock/gmock.h" | 7 #include "testing/gmock/include/gmock/gmock.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace trace_analyzer { | 10 namespace trace_analyzer { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 void TraceEventAnalyzerTest::EndTracing() { | 50 void TraceEventAnalyzerTest::EndTracing() { |
| 51 base::debug::TraceLog::GetInstance()->SetEnabled(false); | 51 base::debug::TraceLog::GetInstance()->SetEnabled(false); |
| 52 buffer_.Finish(); | 52 buffer_.Finish(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 TEST_F(TraceEventAnalyzerTest, NoEvents) { | 57 TEST_F(TraceEventAnalyzerTest, NoEvents) { |
| 58 using namespace trace_analyzer; | |
| 59 ManualSetUp(); | 58 ManualSetUp(); |
| 60 | 59 |
| 61 // Create an empty JSON event string: | 60 // Create an empty JSON event string: |
| 62 buffer_.Start(); | 61 buffer_.Start(); |
| 63 buffer_.Finish(); | 62 buffer_.Finish(); |
| 64 | 63 |
| 65 scoped_ptr<TraceAnalyzer> | 64 scoped_ptr<TraceAnalyzer> |
| 66 analyzer(TraceAnalyzer::Create(output_.json_output)); | 65 analyzer(TraceAnalyzer::Create(output_.json_output)); |
| 67 ASSERT_TRUE(analyzer.get()); | 66 ASSERT_TRUE(analyzer.get()); |
| 68 | 67 |
| 69 // Search for all events and verify that nothing is returned. | 68 // Search for all events and verify that nothing is returned. |
| 70 TraceEventVector found; | 69 TraceEventVector found; |
| 71 analyzer->FindEvents(Query::Bool(true), &found); | 70 analyzer->FindEvents(Query::Bool(true), &found); |
| 72 EXPECT_EQ(0u, found.size()); | 71 EXPECT_EQ(0u, found.size()); |
| 73 } | 72 } |
| 74 | 73 |
| 75 TEST_F(TraceEventAnalyzerTest, TraceEvent) { | 74 TEST_F(TraceEventAnalyzerTest, TraceEvent) { |
| 76 using namespace trace_analyzer; | |
| 77 ManualSetUp(); | 75 ManualSetUp(); |
| 78 | 76 |
| 79 int int_num = 2; | 77 int int_num = 2; |
| 80 double double_num = 3.5; | 78 double double_num = 3.5; |
| 81 const char* str = "the string"; | 79 const char* str = "the string"; |
| 82 | 80 |
| 83 TraceEvent event; | 81 TraceEvent event; |
| 84 event.arg_numbers["false"] = 0.0; | 82 event.arg_numbers["false"] = 0.0; |
| 85 event.arg_numbers["true"] = 1.0; | 83 event.arg_numbers["true"] = 1.0; |
| 86 event.arg_numbers["int"] = static_cast<double>(int_num); | 84 event.arg_numbers["int"] = static_cast<double>(int_num); |
| 87 event.arg_numbers["double"] = double_num; | 85 event.arg_numbers["double"] = double_num; |
| 88 event.arg_strings["string"] = str; | 86 event.arg_strings["string"] = str; |
| 89 | 87 |
| 90 ASSERT_TRUE(event.HasNumberArg("false")); | 88 ASSERT_TRUE(event.HasNumberArg("false")); |
| 91 ASSERT_TRUE(event.HasNumberArg("true")); | 89 ASSERT_TRUE(event.HasNumberArg("true")); |
| 92 ASSERT_TRUE(event.HasNumberArg("int")); | 90 ASSERT_TRUE(event.HasNumberArg("int")); |
| 93 ASSERT_TRUE(event.HasNumberArg("double")); | 91 ASSERT_TRUE(event.HasNumberArg("double")); |
| 94 ASSERT_TRUE(event.HasStringArg("string")); | 92 ASSERT_TRUE(event.HasStringArg("string")); |
| 95 ASSERT_FALSE(event.HasNumberArg("notfound")); | 93 ASSERT_FALSE(event.HasNumberArg("notfound")); |
| 96 ASSERT_FALSE(event.HasStringArg("notfound")); | 94 ASSERT_FALSE(event.HasStringArg("notfound")); |
| 97 | 95 |
| 98 EXPECT_FALSE(event.GetKnownArgAsBool("false")); | 96 EXPECT_FALSE(event.GetKnownArgAsBool("false")); |
| 99 EXPECT_TRUE(event.GetKnownArgAsBool("true")); | 97 EXPECT_TRUE(event.GetKnownArgAsBool("true")); |
| 100 EXPECT_EQ(int_num, event.GetKnownArgAsInt("int")); | 98 EXPECT_EQ(int_num, event.GetKnownArgAsInt("int")); |
| 101 EXPECT_EQ(double_num, event.GetKnownArgAsDouble("double")); | 99 EXPECT_EQ(double_num, event.GetKnownArgAsDouble("double")); |
| 102 EXPECT_STREQ(str, event.GetKnownArgAsString("string").c_str()); | 100 EXPECT_STREQ(str, event.GetKnownArgAsString("string").c_str()); |
| 103 } | 101 } |
| 104 | 102 |
| 105 TEST_F(TraceEventAnalyzerTest, QueryEventMember) { | 103 TEST_F(TraceEventAnalyzerTest, QueryEventMember) { |
| 106 using namespace trace_analyzer; | |
| 107 ManualSetUp(); | 104 ManualSetUp(); |
| 108 | 105 |
| 109 TraceEvent event; | 106 TraceEvent event; |
| 110 event.thread.process_id = 3; | 107 event.thread.process_id = 3; |
| 111 event.thread.thread_id = 4; | 108 event.thread.thread_id = 4; |
| 112 event.timestamp = 1.5; | 109 event.timestamp = 1.5; |
| 113 event.phase = TRACE_EVENT_PHASE_BEGIN; | 110 event.phase = TRACE_EVENT_PHASE_BEGIN; |
| 114 event.category = "category"; | 111 event.category = "category"; |
| 115 event.name = "name"; | 112 event.name = "name"; |
| 116 event.id = "1"; | 113 event.id = "1"; |
| 117 event.arg_numbers["num"] = 7.0; | 114 event.arg_numbers["num"] = 7.0; |
| 118 event.arg_strings["str"] = "the string"; | 115 event.arg_strings["str"] = "the string"; |
| 119 | 116 |
| 120 // Other event with all different members: | 117 // Other event with all different members: |
| 121 TraceEvent other; | 118 TraceEvent other; |
| 122 other.thread.process_id = 5; | 119 other.thread.process_id = 5; |
| 123 other.thread.thread_id = 6; | 120 other.thread.thread_id = 6; |
| 124 other.timestamp = 2.5; | 121 other.timestamp = 2.5; |
| 125 other.phase = TRACE_EVENT_PHASE_END; | 122 other.phase = TRACE_EVENT_PHASE_END; |
| 126 other.category = "category2"; | 123 other.category = "category2"; |
| 127 other.name = "name2"; | 124 other.name = "name2"; |
| 128 other.id = "2"; | 125 other.id = "2"; |
| 129 other.arg_numbers["num2"] = 8.0; | 126 other.arg_numbers["num2"] = 8.0; |
| 130 other.arg_strings["str2"] = "the string 2"; | 127 other.arg_strings["str2"] = "the string 2"; |
| 131 | 128 |
| 132 event.other_event = &other; | 129 event.other_event = &other; |
| 133 ASSERT_TRUE(event.has_other_event()); | 130 ASSERT_TRUE(event.has_other_event()); |
| 134 double duration = event.GetAbsTimeToOtherEvent(); | 131 double duration = event.GetAbsTimeToOtherEvent(); |
| 135 | 132 |
| 136 Query event_pid = (Query(EVENT_PID) == Query::Int(event.thread.process_id)); | 133 Query event_pid = (Query::EventPid() == Query::Int(event.thread.process_id)); |
| 137 Query event_tid = (Query(EVENT_TID) == Query::Int(event.thread.thread_id)); | 134 Query event_tid = (Query::EventTid() == Query::Int(event.thread.thread_id)); |
| 138 Query event_time = (Query(EVENT_TIME) == Query::Double(event.timestamp)); | 135 Query event_time = (Query::EventTime() == Query::Double(event.timestamp)); |
| 139 Query event_duration = (Query(EVENT_DURATION) == Query::Double(duration)); | 136 Query event_duration = (Query::EventDuration() == Query::Double(duration)); |
| 140 Query event_phase = (Query(EVENT_PHASE) == Query::Phase(event.phase)); | 137 Query event_phase = (Query::EventPhase() == Query::Phase(event.phase)); |
| 141 Query event_category = | 138 Query event_category = |
| 142 (Query(EVENT_CATEGORY) == Query::String(event.category)); | 139 (Query::EventCategory() == Query::String(event.category)); |
| 143 Query event_name = (Query(EVENT_NAME) == Query::String(event.name)); | 140 Query event_name = (Query::EventName() == Query::String(event.name)); |
| 144 Query event_id = (Query(EVENT_ID) == Query::String(event.id)); | 141 Query event_id = (Query::EventId() == Query::String(event.id)); |
| 145 Query event_has_arg1 = Query(EVENT_HAS_NUMBER_ARG, "num"); | 142 Query event_has_arg1 = Query::EventHasNumberArg("num"); |
| 146 Query event_has_arg2 = Query(EVENT_HAS_STRING_ARG, "str"); | 143 Query event_has_arg2 = Query::EventHasStringArg("str"); |
| 147 Query event_arg1 = | 144 Query event_arg1 = |
| 148 (Query(EVENT_ARG, "num") == Query::Double(event.arg_numbers["num"])); | 145 (Query::EventArg("num") == Query::Double(event.arg_numbers["num"])); |
| 149 Query event_arg2 = | 146 Query event_arg2 = |
| 150 (Query(EVENT_ARG, "str") == Query::String(event.arg_strings["str"])); | 147 (Query::EventArg("str") == Query::String(event.arg_strings["str"])); |
| 151 Query event_has_other = Query(EVENT_HAS_OTHER); | 148 Query event_has_other = Query::EventHasOther(); |
| 152 Query other_pid = (Query(OTHER_PID) == Query::Int(other.thread.process_id)); | 149 Query other_pid = (Query::OtherPid() == Query::Int(other.thread.process_id)); |
| 153 Query other_tid = (Query(OTHER_TID) == Query::Int(other.thread.thread_id)); | 150 Query other_tid = (Query::OtherTid() == Query::Int(other.thread.thread_id)); |
| 154 Query other_time = (Query(OTHER_TIME) == Query::Double(other.timestamp)); | 151 Query other_time = (Query::OtherTime() == Query::Double(other.timestamp)); |
| 155 Query other_phase = (Query(OTHER_PHASE) == Query::Phase(other.phase)); | 152 Query other_phase = (Query::OtherPhase() == Query::Phase(other.phase)); |
| 156 Query other_category = | 153 Query other_category = |
| 157 (Query(OTHER_CATEGORY) == Query::String(other.category)); | 154 (Query::OtherCategory() == Query::String(other.category)); |
| 158 Query other_name = (Query(OTHER_NAME) == Query::String(other.name)); | 155 Query other_name = (Query::OtherName() == Query::String(other.name)); |
| 159 Query other_id = (Query(OTHER_ID) == Query::String(other.id)); | 156 Query other_id = (Query::OtherId() == Query::String(other.id)); |
| 160 Query other_has_arg1 = Query(OTHER_HAS_NUMBER_ARG, "num2"); | 157 Query other_has_arg1 = Query::OtherHasNumberArg("num2"); |
| 161 Query other_has_arg2 = Query(OTHER_HAS_STRING_ARG, "str2"); | 158 Query other_has_arg2 = Query::OtherHasStringArg("str2"); |
| 162 Query other_arg1 = | 159 Query other_arg1 = |
| 163 (Query(OTHER_ARG, "num2") == Query::Double(other.arg_numbers["num2"])); | 160 (Query::OtherArg("num2") == Query::Double(other.arg_numbers["num2"])); |
| 164 Query other_arg2 = | 161 Query other_arg2 = |
| 165 (Query(OTHER_ARG, "str2") == Query::String(other.arg_strings["str2"])); | 162 (Query::OtherArg("str2") == Query::String(other.arg_strings["str2"])); |
| 166 | 163 |
| 167 EXPECT_TRUE(event_pid.Evaluate(event)); | 164 EXPECT_TRUE(event_pid.Evaluate(event)); |
| 168 EXPECT_TRUE(event_tid.Evaluate(event)); | 165 EXPECT_TRUE(event_tid.Evaluate(event)); |
| 169 EXPECT_TRUE(event_time.Evaluate(event)); | 166 EXPECT_TRUE(event_time.Evaluate(event)); |
| 170 EXPECT_TRUE(event_duration.Evaluate(event)); | 167 EXPECT_TRUE(event_duration.Evaluate(event)); |
| 171 EXPECT_TRUE(event_phase.Evaluate(event)); | 168 EXPECT_TRUE(event_phase.Evaluate(event)); |
| 172 EXPECT_TRUE(event_category.Evaluate(event)); | 169 EXPECT_TRUE(event_category.Evaluate(event)); |
| 173 EXPECT_TRUE(event_name.Evaluate(event)); | 170 EXPECT_TRUE(event_name.Evaluate(event)); |
| 174 EXPECT_TRUE(event_id.Evaluate(event)); | 171 EXPECT_TRUE(event_id.Evaluate(event)); |
| 175 EXPECT_TRUE(event_has_arg1.Evaluate(event)); | 172 EXPECT_TRUE(event_has_arg1.Evaluate(event)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 200 EXPECT_FALSE(event_name.Evaluate(other)); | 197 EXPECT_FALSE(event_name.Evaluate(other)); |
| 201 EXPECT_FALSE(event_id.Evaluate(other)); | 198 EXPECT_FALSE(event_id.Evaluate(other)); |
| 202 EXPECT_FALSE(event_has_arg1.Evaluate(other)); | 199 EXPECT_FALSE(event_has_arg1.Evaluate(other)); |
| 203 EXPECT_FALSE(event_has_arg2.Evaluate(other)); | 200 EXPECT_FALSE(event_has_arg2.Evaluate(other)); |
| 204 EXPECT_FALSE(event_arg1.Evaluate(other)); | 201 EXPECT_FALSE(event_arg1.Evaluate(other)); |
| 205 EXPECT_FALSE(event_arg2.Evaluate(other)); | 202 EXPECT_FALSE(event_arg2.Evaluate(other)); |
| 206 EXPECT_FALSE(event_has_other.Evaluate(other)); | 203 EXPECT_FALSE(event_has_other.Evaluate(other)); |
| 207 } | 204 } |
| 208 | 205 |
| 209 TEST_F(TraceEventAnalyzerTest, BooleanOperators) { | 206 TEST_F(TraceEventAnalyzerTest, BooleanOperators) { |
| 210 using namespace trace_analyzer; | |
| 211 ManualSetUp(); | 207 ManualSetUp(); |
| 212 | 208 |
| 213 BeginTracing(); | 209 BeginTracing(); |
| 214 { | 210 { |
| 215 TRACE_EVENT_INSTANT1("cat1", "name1", "num", 1); | 211 TRACE_EVENT_INSTANT1("cat1", "name1", "num", 1); |
| 216 TRACE_EVENT_INSTANT1("cat1", "name2", "num", 2); | 212 TRACE_EVENT_INSTANT1("cat1", "name2", "num", 2); |
| 217 TRACE_EVENT_INSTANT1("cat2", "name3", "num", 3); | 213 TRACE_EVENT_INSTANT1("cat2", "name3", "num", 3); |
| 218 TRACE_EVENT_INSTANT1("cat2", "name4", "num", 4); | 214 TRACE_EVENT_INSTANT1("cat2", "name4", "num", 4); |
| 219 } | 215 } |
| 220 EndTracing(); | 216 EndTracing(); |
| 221 | 217 |
| 222 scoped_ptr<TraceAnalyzer> | 218 scoped_ptr<TraceAnalyzer> |
| 223 analyzer(TraceAnalyzer::Create(output_.json_output)); | 219 analyzer(TraceAnalyzer::Create(output_.json_output)); |
| 224 ASSERT_TRUE(!!analyzer.get()); | 220 ASSERT_TRUE(!!analyzer.get()); |
| 225 | 221 |
| 226 TraceEventVector found; | 222 TraceEventVector found; |
| 227 | 223 |
| 228 // == | 224 // == |
| 229 | 225 |
| 230 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat1"), &found); | 226 analyzer->FindEvents(Query::EventCategory() == Query::String("cat1"), &found); |
| 231 ASSERT_EQ(2u, found.size()); | 227 ASSERT_EQ(2u, found.size()); |
| 232 EXPECT_STREQ("name1", found[0]->name.c_str()); | 228 EXPECT_STREQ("name1", found[0]->name.c_str()); |
| 233 EXPECT_STREQ("name2", found[1]->name.c_str()); | 229 EXPECT_STREQ("name2", found[1]->name.c_str()); |
| 234 | 230 |
| 235 analyzer->FindEvents(Query(EVENT_ARG, "num") == Query::Int(2), &found); | 231 analyzer->FindEvents(Query::EventArg("num") == Query::Int(2), &found); |
| 236 ASSERT_EQ(1u, found.size()); | 232 ASSERT_EQ(1u, found.size()); |
| 237 EXPECT_STREQ("name2", found[0]->name.c_str()); | 233 EXPECT_STREQ("name2", found[0]->name.c_str()); |
| 238 | 234 |
| 239 // != | 235 // != |
| 240 | 236 |
| 241 analyzer->FindEvents(Query(EVENT_CATEGORY) != Query::String("cat1"), &found); | 237 analyzer->FindEvents(Query::EventCategory() != Query::String("cat1"), &found); |
| 242 ASSERT_EQ(2u, found.size()); | 238 ASSERT_EQ(2u, found.size()); |
| 243 EXPECT_STREQ("name3", found[0]->name.c_str()); | 239 EXPECT_STREQ("name3", found[0]->name.c_str()); |
| 244 EXPECT_STREQ("name4", found[1]->name.c_str()); | 240 EXPECT_STREQ("name4", found[1]->name.c_str()); |
| 245 | 241 |
| 246 analyzer->FindEvents(Query(EVENT_ARG, "num") != Query::Int(2), &found); | 242 analyzer->FindEvents(Query::EventArg("num") != Query::Int(2), &found); |
| 247 ASSERT_EQ(3u, found.size()); | 243 ASSERT_EQ(3u, found.size()); |
| 248 EXPECT_STREQ("name1", found[0]->name.c_str()); | 244 EXPECT_STREQ("name1", found[0]->name.c_str()); |
| 249 EXPECT_STREQ("name3", found[1]->name.c_str()); | 245 EXPECT_STREQ("name3", found[1]->name.c_str()); |
| 250 EXPECT_STREQ("name4", found[2]->name.c_str()); | 246 EXPECT_STREQ("name4", found[2]->name.c_str()); |
| 251 | 247 |
| 252 // < | 248 // < |
| 253 analyzer->FindEvents(Query(EVENT_ARG, "num") < Query::Int(2), &found); | 249 analyzer->FindEvents(Query::EventArg("num") < Query::Int(2), &found); |
| 254 ASSERT_EQ(1u, found.size()); | 250 ASSERT_EQ(1u, found.size()); |
| 255 EXPECT_STREQ("name1", found[0]->name.c_str()); | 251 EXPECT_STREQ("name1", found[0]->name.c_str()); |
| 256 | 252 |
| 257 // <= | 253 // <= |
| 258 analyzer->FindEvents(Query(EVENT_ARG, "num") <= Query::Int(2), &found); | 254 analyzer->FindEvents(Query::EventArg("num") <= Query::Int(2), &found); |
| 259 ASSERT_EQ(2u, found.size()); | 255 ASSERT_EQ(2u, found.size()); |
| 260 EXPECT_STREQ("name1", found[0]->name.c_str()); | 256 EXPECT_STREQ("name1", found[0]->name.c_str()); |
| 261 EXPECT_STREQ("name2", found[1]->name.c_str()); | 257 EXPECT_STREQ("name2", found[1]->name.c_str()); |
| 262 | 258 |
| 263 // > | 259 // > |
| 264 analyzer->FindEvents(Query(EVENT_ARG, "num") > Query::Int(3), &found); | 260 analyzer->FindEvents(Query::EventArg("num") > Query::Int(3), &found); |
| 265 ASSERT_EQ(1u, found.size()); | 261 ASSERT_EQ(1u, found.size()); |
| 266 EXPECT_STREQ("name4", found[0]->name.c_str()); | 262 EXPECT_STREQ("name4", found[0]->name.c_str()); |
| 267 | 263 |
| 268 // >= | 264 // >= |
| 269 analyzer->FindEvents(Query(EVENT_ARG, "num") >= Query::Int(4), &found); | 265 analyzer->FindEvents(Query::EventArg("num") >= Query::Int(4), &found); |
| 270 ASSERT_EQ(1u, found.size()); | 266 ASSERT_EQ(1u, found.size()); |
| 271 EXPECT_STREQ("name4", found[0]->name.c_str()); | 267 EXPECT_STREQ("name4", found[0]->name.c_str()); |
| 272 | 268 |
| 273 // && | 269 // && |
| 274 analyzer->FindEvents(Query(EVENT_NAME) != Query::String("name1") && | 270 analyzer->FindEvents(Query::EventName() != Query::String("name1") && |
| 275 Query(EVENT_ARG, "num") < Query::Int(3), &found); | 271 Query::EventArg("num") < Query::Int(3), &found); |
| 276 ASSERT_EQ(1u, found.size()); | 272 ASSERT_EQ(1u, found.size()); |
| 277 EXPECT_STREQ("name2", found[0]->name.c_str()); | 273 EXPECT_STREQ("name2", found[0]->name.c_str()); |
| 278 | 274 |
| 279 // || | 275 // || |
| 280 analyzer->FindEvents(Query(EVENT_NAME) == Query::String("name1") || | 276 analyzer->FindEvents(Query::EventName() == Query::String("name1") || |
| 281 Query(EVENT_ARG, "num") == Query::Int(3), &found); | 277 Query::EventArg("num") == Query::Int(3), &found); |
| 282 ASSERT_EQ(2u, found.size()); | 278 ASSERT_EQ(2u, found.size()); |
| 283 EXPECT_STREQ("name1", found[0]->name.c_str()); | 279 EXPECT_STREQ("name1", found[0]->name.c_str()); |
| 284 EXPECT_STREQ("name3", found[1]->name.c_str()); | 280 EXPECT_STREQ("name3", found[1]->name.c_str()); |
| 285 | 281 |
| 286 // ! | 282 // ! |
| 287 analyzer->FindEvents(!(Query(EVENT_NAME) == Query::String("name1") || | 283 analyzer->FindEvents(!(Query::EventName() == Query::String("name1") || |
| 288 Query(EVENT_ARG, "num") == Query::Int(3)), &found); | 284 Query::EventArg("num") == Query::Int(3)), &found); |
| 289 ASSERT_EQ(2u, found.size()); | 285 ASSERT_EQ(2u, found.size()); |
| 290 EXPECT_STREQ("name2", found[0]->name.c_str()); | 286 EXPECT_STREQ("name2", found[0]->name.c_str()); |
| 291 EXPECT_STREQ("name4", found[1]->name.c_str()); | 287 EXPECT_STREQ("name4", found[1]->name.c_str()); |
| 292 } | 288 } |
| 293 | 289 |
| 294 TEST_F(TraceEventAnalyzerTest, ArithmeticOperators) { | 290 TEST_F(TraceEventAnalyzerTest, ArithmeticOperators) { |
| 295 using namespace trace_analyzer; | |
| 296 ManualSetUp(); | 291 ManualSetUp(); |
| 297 | 292 |
| 298 BeginTracing(); | 293 BeginTracing(); |
| 299 { | 294 { |
| 300 // These events are searched for: | 295 // These events are searched for: |
| 301 TRACE_EVENT_INSTANT2("cat1", "math1", "a", 10, "b", 5); | 296 TRACE_EVENT_INSTANT2("cat1", "math1", "a", 10, "b", 5); |
| 302 TRACE_EVENT_INSTANT2("cat1", "math2", "a", 10, "b", 10); | 297 TRACE_EVENT_INSTANT2("cat1", "math2", "a", 10, "b", 10); |
| 303 // Extra events that never match, for noise: | 298 // Extra events that never match, for noise: |
| 304 TRACE_EVENT_INSTANT2("noise", "math3", "a", 1, "b", 3); | 299 TRACE_EVENT_INSTANT2("noise", "math3", "a", 1, "b", 3); |
| 305 TRACE_EVENT_INSTANT2("noise", "math4", "c", 10, "d", 5); | 300 TRACE_EVENT_INSTANT2("noise", "math4", "c", 10, "d", 5); |
| 306 } | 301 } |
| 307 EndTracing(); | 302 EndTracing(); |
| 308 | 303 |
| 309 scoped_ptr<TraceAnalyzer> | 304 scoped_ptr<TraceAnalyzer> |
| 310 analyzer(TraceAnalyzer::Create(output_.json_output)); | 305 analyzer(TraceAnalyzer::Create(output_.json_output)); |
| 311 ASSERT_TRUE(analyzer.get()); | 306 ASSERT_TRUE(analyzer.get()); |
| 312 | 307 |
| 313 TraceEventVector found; | 308 TraceEventVector found; |
| 314 | 309 |
| 315 // Verify that arithmetic operators function: | 310 // Verify that arithmetic operators function: |
| 316 | 311 |
| 317 // + | 312 // + |
| 318 analyzer->FindEvents(Query(EVENT_ARG, "a") + Query(EVENT_ARG, "b") == | 313 analyzer->FindEvents(Query::EventArg("a") + Query::EventArg("b") == |
| 319 Query::Int(20), &found); | 314 Query::Int(20), &found); |
| 320 EXPECT_EQ(1u, found.size()); | 315 EXPECT_EQ(1u, found.size()); |
| 321 EXPECT_STREQ("math2", found.front()->name.c_str()); | 316 EXPECT_STREQ("math2", found.front()->name.c_str()); |
| 322 | 317 |
| 323 // - | 318 // - |
| 324 analyzer->FindEvents(Query(EVENT_ARG, "a") - Query(EVENT_ARG, "b") == | 319 analyzer->FindEvents(Query::EventArg("a") - Query::EventArg("b") == |
| 325 Query::Int(5), &found); | 320 Query::Int(5), &found); |
| 326 EXPECT_EQ(1u, found.size()); | 321 EXPECT_EQ(1u, found.size()); |
| 327 EXPECT_STREQ("math1", found.front()->name.c_str()); | 322 EXPECT_STREQ("math1", found.front()->name.c_str()); |
| 328 | 323 |
| 329 // * | 324 // * |
| 330 analyzer->FindEvents(Query(EVENT_ARG, "a") * Query(EVENT_ARG, "b") == | 325 analyzer->FindEvents(Query::EventArg("a") * Query::EventArg("b") == |
| 331 Query::Int(50), &found); | 326 Query::Int(50), &found); |
| 332 EXPECT_EQ(1u, found.size()); | 327 EXPECT_EQ(1u, found.size()); |
| 333 EXPECT_STREQ("math1", found.front()->name.c_str()); | 328 EXPECT_STREQ("math1", found.front()->name.c_str()); |
| 334 | 329 |
| 335 // / | 330 // / |
| 336 analyzer->FindEvents(Query(EVENT_ARG, "a") / Query(EVENT_ARG, "b") == | 331 analyzer->FindEvents(Query::EventArg("a") / Query::EventArg("b") == |
| 337 Query::Int(2), &found); | 332 Query::Int(2), &found); |
| 338 EXPECT_EQ(1u, found.size()); | 333 EXPECT_EQ(1u, found.size()); |
| 339 EXPECT_STREQ("math1", found.front()->name.c_str()); | 334 EXPECT_STREQ("math1", found.front()->name.c_str()); |
| 340 | 335 |
| 341 // % | 336 // % |
| 342 analyzer->FindEvents(Query(EVENT_ARG, "a") % Query(EVENT_ARG, "b") == | 337 analyzer->FindEvents(Query::EventArg("a") % Query::EventArg("b") == |
| 343 Query::Int(0), &found); | 338 Query::Int(0), &found); |
| 344 EXPECT_EQ(2u, found.size()); | 339 EXPECT_EQ(2u, found.size()); |
| 345 | 340 |
| 346 // - (negate) | 341 // - (negate) |
| 347 analyzer->FindEvents(-Query(EVENT_ARG, "b") == Query::Int(-10), &found); | 342 analyzer->FindEvents(-Query::EventArg("b") == Query::Int(-10), &found); |
| 348 EXPECT_EQ(1u, found.size()); | 343 EXPECT_EQ(1u, found.size()); |
| 349 EXPECT_STREQ("math2", found.front()->name.c_str()); | 344 EXPECT_STREQ("math2", found.front()->name.c_str()); |
| 350 } | 345 } |
| 351 | 346 |
| 352 TEST_F(TraceEventAnalyzerTest, StringPattern) { | 347 TEST_F(TraceEventAnalyzerTest, StringPattern) { |
| 353 using namespace trace_analyzer; | |
| 354 ManualSetUp(); | 348 ManualSetUp(); |
| 355 | 349 |
| 356 BeginTracing(); | 350 BeginTracing(); |
| 357 { | 351 { |
| 358 TRACE_EVENT_INSTANT0("cat1", "name1"); | 352 TRACE_EVENT_INSTANT0("cat1", "name1"); |
| 359 TRACE_EVENT_INSTANT0("cat1", "name2"); | 353 TRACE_EVENT_INSTANT0("cat1", "name2"); |
| 360 TRACE_EVENT_INSTANT0("cat1", "no match"); | 354 TRACE_EVENT_INSTANT0("cat1", "no match"); |
| 361 TRACE_EVENT_INSTANT0("cat1", "name3x"); | 355 TRACE_EVENT_INSTANT0("cat1", "name3x"); |
| 362 } | 356 } |
| 363 EndTracing(); | 357 EndTracing(); |
| 364 | 358 |
| 365 scoped_ptr<TraceAnalyzer> | 359 scoped_ptr<TraceAnalyzer> |
| 366 analyzer(TraceAnalyzer::Create(output_.json_output)); | 360 analyzer(TraceAnalyzer::Create(output_.json_output)); |
| 367 ASSERT_TRUE(analyzer.get()); | 361 ASSERT_TRUE(analyzer.get()); |
| 368 | 362 |
| 369 TraceEventVector found; | 363 TraceEventVector found; |
| 370 | 364 |
| 371 analyzer->FindEvents(Query(EVENT_NAME) == Query::Pattern("name?"), &found); | 365 analyzer->FindEvents(Query::EventName() == Query::Pattern("name?"), &found); |
| 372 ASSERT_EQ(2u, found.size()); | 366 ASSERT_EQ(2u, found.size()); |
| 373 EXPECT_STREQ("name1", found[0]->name.c_str()); | 367 EXPECT_STREQ("name1", found[0]->name.c_str()); |
| 374 EXPECT_STREQ("name2", found[1]->name.c_str()); | 368 EXPECT_STREQ("name2", found[1]->name.c_str()); |
| 375 | 369 |
| 376 analyzer->FindEvents(Query(EVENT_NAME) == Query::Pattern("name*"), &found); | 370 analyzer->FindEvents(Query::EventName() == Query::Pattern("name*"), &found); |
| 377 ASSERT_EQ(3u, found.size()); | 371 ASSERT_EQ(3u, found.size()); |
| 378 EXPECT_STREQ("name1", found[0]->name.c_str()); | 372 EXPECT_STREQ("name1", found[0]->name.c_str()); |
| 379 EXPECT_STREQ("name2", found[1]->name.c_str()); | 373 EXPECT_STREQ("name2", found[1]->name.c_str()); |
| 380 EXPECT_STREQ("name3x", found[2]->name.c_str()); | 374 EXPECT_STREQ("name3x", found[2]->name.c_str()); |
| 381 | 375 |
| 382 analyzer->FindEvents(Query(EVENT_NAME) != Query::Pattern("name*"), &found); | 376 analyzer->FindEvents(Query::EventName() != Query::Pattern("name*"), &found); |
| 383 ASSERT_EQ(1u, found.size()); | 377 ASSERT_EQ(1u, found.size()); |
| 384 EXPECT_STREQ("no match", found[0]->name.c_str()); | 378 EXPECT_STREQ("no match", found[0]->name.c_str()); |
| 385 } | 379 } |
| 386 | 380 |
| 387 // Test that duration queries work. | 381 // Test that duration queries work. |
| 388 TEST_F(TraceEventAnalyzerTest, Duration) { | 382 TEST_F(TraceEventAnalyzerTest, Duration) { |
| 389 using namespace trace_analyzer; | |
| 390 ManualSetUp(); | 383 ManualSetUp(); |
| 391 | 384 |
| 392 const base::TimeDelta kSleepTime = base::TimeDelta::FromMilliseconds(200); | 385 const base::TimeDelta kSleepTime = base::TimeDelta::FromMilliseconds(200); |
| 393 // We will search for events that have a duration of greater than 90% of the | 386 // We will search for events that have a duration of greater than 90% of the |
| 394 // sleep time, so that there is no flakiness. | 387 // sleep time, so that there is no flakiness. |
| 395 int duration_cutoff_us = (kSleepTime.InMicroseconds() * 9) / 10; | 388 int duration_cutoff_us = (kSleepTime.InMicroseconds() * 9) / 10; |
| 396 | 389 |
| 397 BeginTracing(); | 390 BeginTracing(); |
| 398 { | 391 { |
| 399 TRACE_EVENT0("cat1", "name1"); // found by duration query | 392 TRACE_EVENT0("cat1", "name1"); // found by duration query |
| 400 TRACE_EVENT0("noise", "name2"); // not searched for, just noise | 393 TRACE_EVENT0("noise", "name2"); // not searched for, just noise |
| 401 { | 394 { |
| 402 TRACE_EVENT0("cat2", "name3"); // found by duration query | 395 TRACE_EVENT0("cat2", "name3"); // found by duration query |
| 403 TRACE_EVENT_INSTANT0("noise", "name4"); // not searched for, just noise | 396 TRACE_EVENT_INSTANT0("noise", "name4"); // not searched for, just noise |
| 404 base::PlatformThread::Sleep(kSleepTime); | 397 base::PlatformThread::Sleep(kSleepTime); |
| 405 TRACE_EVENT0("cat2", "name5"); // not found (duration too short) | 398 TRACE_EVENT0("cat2", "name5"); // not found (duration too short) |
| 406 } | 399 } |
| 407 } | 400 } |
| 408 EndTracing(); | 401 EndTracing(); |
| 409 | 402 |
| 410 scoped_ptr<TraceAnalyzer> | 403 scoped_ptr<TraceAnalyzer> |
| 411 analyzer(TraceAnalyzer::Create(output_.json_output)); | 404 analyzer(TraceAnalyzer::Create(output_.json_output)); |
| 412 ASSERT_TRUE(analyzer.get()); | 405 ASSERT_TRUE(analyzer.get()); |
| 413 analyzer->AssociateBeginEndEvents(); | 406 analyzer->AssociateBeginEndEvents(); |
| 414 | 407 |
| 415 TraceEventVector found; | 408 TraceEventVector found; |
| 416 analyzer->FindEvents(Query::MatchBeginWithEnd() && | 409 analyzer->FindEvents( |
| 417 Query(EVENT_DURATION) > Query::Int(duration_cutoff_us) && | 410 Query::MatchBeginWithEnd() && |
| 418 (Query(EVENT_CATEGORY) == Query::String("cat1") || | 411 Query::EventDuration() > Query::Int(duration_cutoff_us) && |
| 419 Query(EVENT_CATEGORY) == Query::String("cat2") || | 412 (Query::EventCategory() == Query::String("cat1") || |
| 420 Query(EVENT_CATEGORY) == Query::String("cat3")), &found); | 413 Query::EventCategory() == Query::String("cat2") || |
| 414 Query::EventCategory() == Query::String("cat3")), |
| 415 &found); |
| 421 ASSERT_EQ(2u, found.size()); | 416 ASSERT_EQ(2u, found.size()); |
| 422 EXPECT_STREQ("name1", found[0]->name.c_str()); | 417 EXPECT_STREQ("name1", found[0]->name.c_str()); |
| 423 EXPECT_STREQ("name3", found[1]->name.c_str()); | 418 EXPECT_STREQ("name3", found[1]->name.c_str()); |
| 424 } | 419 } |
| 425 | 420 |
| 426 // Test AssociateBeginEndEvents | 421 // Test AssociateBeginEndEvents |
| 427 TEST_F(TraceEventAnalyzerTest, BeginEndAssocations) { | 422 TEST_F(TraceEventAnalyzerTest, BeginEndAssocations) { |
| 428 using namespace trace_analyzer; | |
| 429 ManualSetUp(); | 423 ManualSetUp(); |
| 430 | 424 |
| 431 BeginTracing(); | 425 BeginTracing(); |
| 432 { | 426 { |
| 433 TRACE_EVENT_END0("cat1", "name1"); // does not match out of order begin | 427 TRACE_EVENT_END0("cat1", "name1"); // does not match out of order begin |
| 434 TRACE_EVENT0("cat1", "name2"); | 428 TRACE_EVENT0("cat1", "name2"); |
| 435 TRACE_EVENT_INSTANT0("cat1", "name3"); | 429 TRACE_EVENT_INSTANT0("cat1", "name3"); |
| 436 TRACE_EVENT_BEGIN0("cat1", "name1"); | 430 TRACE_EVENT_BEGIN0("cat1", "name1"); |
| 437 } | 431 } |
| 438 EndTracing(); | 432 EndTracing(); |
| 439 | 433 |
| 440 scoped_ptr<TraceAnalyzer> | 434 scoped_ptr<TraceAnalyzer> |
| 441 analyzer(TraceAnalyzer::Create(output_.json_output)); | 435 analyzer(TraceAnalyzer::Create(output_.json_output)); |
| 442 ASSERT_TRUE(analyzer.get()); | 436 ASSERT_TRUE(analyzer.get()); |
| 443 analyzer->AssociateBeginEndEvents(); | 437 analyzer->AssociateBeginEndEvents(); |
| 444 | 438 |
| 445 TraceEventVector found; | 439 TraceEventVector found; |
| 446 analyzer->FindEvents(Query::MatchBeginWithEnd(), &found); | 440 analyzer->FindEvents(Query::MatchBeginWithEnd(), &found); |
| 447 ASSERT_EQ(1u, found.size()); | 441 ASSERT_EQ(1u, found.size()); |
| 448 EXPECT_STREQ("name2", found[0]->name.c_str()); | 442 EXPECT_STREQ("name2", found[0]->name.c_str()); |
| 449 } | 443 } |
| 450 | 444 |
| 451 // Test MergeAssociatedEventArgs | 445 // Test MergeAssociatedEventArgs |
| 452 TEST_F(TraceEventAnalyzerTest, MergeAssociatedEventArgs) { | 446 TEST_F(TraceEventAnalyzerTest, MergeAssociatedEventArgs) { |
| 453 using namespace trace_analyzer; | |
| 454 ManualSetUp(); | 447 ManualSetUp(); |
| 455 | 448 |
| 456 const char* arg_string = "arg_string"; | 449 const char* arg_string = "arg_string"; |
| 457 BeginTracing(); | 450 BeginTracing(); |
| 458 { | 451 { |
| 459 TRACE_EVENT1("cat1", "name1", "arg", arg_string); | 452 TRACE_EVENT1("cat1", "name1", "arg", arg_string); |
| 460 } | 453 } |
| 461 EndTracing(); | 454 EndTracing(); |
| 462 | 455 |
| 463 scoped_ptr<TraceAnalyzer> | 456 scoped_ptr<TraceAnalyzer> |
| 464 analyzer(TraceAnalyzer::Create(output_.json_output)); | 457 analyzer(TraceAnalyzer::Create(output_.json_output)); |
| 465 ASSERT_TRUE(analyzer.get()); | 458 ASSERT_TRUE(analyzer.get()); |
| 466 analyzer->AssociateBeginEndEvents(); | 459 analyzer->AssociateBeginEndEvents(); |
| 467 | 460 |
| 468 TraceEventVector found; | 461 TraceEventVector found; |
| 469 analyzer->FindEvents(Query(EVENT_NAME) == Query::String("name1") && | 462 analyzer->FindEvents(Query::EventName() == Query::String("name1") && |
| 470 Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_END), &found); | 463 Query::EventPhase() == Query::Phase(TRACE_EVENT_PHASE_END), &found); |
| 471 ASSERT_EQ(1u, found.size()); | 464 ASSERT_EQ(1u, found.size()); |
| 472 std::string arg_actual; | 465 std::string arg_actual; |
| 473 EXPECT_FALSE(found[0]->GetArgAsString("arg", &arg_actual)); | 466 EXPECT_FALSE(found[0]->GetArgAsString("arg", &arg_actual)); |
| 474 | 467 |
| 475 analyzer->MergeAssociatedEventArgs(); | 468 analyzer->MergeAssociatedEventArgs(); |
| 476 EXPECT_TRUE(found[0]->GetArgAsString("arg", &arg_actual)); | 469 EXPECT_TRUE(found[0]->GetArgAsString("arg", &arg_actual)); |
| 477 EXPECT_STREQ(arg_string, arg_actual.c_str()); | 470 EXPECT_STREQ(arg_string, arg_actual.c_str()); |
| 478 } | 471 } |
| 479 | 472 |
| 480 // Test AssociateStartFinishEvents | 473 // Test AssociateStartFinishEvents |
| 481 TEST_F(TraceEventAnalyzerTest, StartFinishAssocations) { | 474 TEST_F(TraceEventAnalyzerTest, StartFinishAssocations) { |
| 482 using namespace trace_analyzer; | |
| 483 ManualSetUp(); | 475 ManualSetUp(); |
| 484 | 476 |
| 485 BeginTracing(); | 477 BeginTracing(); |
| 486 { | 478 { |
| 487 TRACE_EVENT_FINISH0("cat1", "name1", 0xA); // does not match / out of order | 479 TRACE_EVENT_FINISH0("cat1", "name1", 0xA); // does not match / out of order |
| 488 TRACE_EVENT_START0("cat1", "name1", 0xB); | 480 TRACE_EVENT_START0("cat1", "name1", 0xB); |
| 489 TRACE_EVENT_START0("cat1", "name1", 0xC); | 481 TRACE_EVENT_START0("cat1", "name1", 0xC); |
| 490 TRACE_EVENT_INSTANT0("cat1", "name1"); // noise | 482 TRACE_EVENT_INSTANT0("cat1", "name1"); // noise |
| 491 TRACE_EVENT0("cat1", "name1"); // noise | 483 TRACE_EVENT0("cat1", "name1"); // noise |
| 492 TRACE_EVENT_FINISH0("cat1", "name1", 0xB); | 484 TRACE_EVENT_FINISH0("cat1", "name1", 0xB); |
| 493 TRACE_EVENT_FINISH0("cat1", "name1", 0xC); | 485 TRACE_EVENT_FINISH0("cat1", "name1", 0xC); |
| 494 TRACE_EVENT_START0("cat1", "name1", 0xA); // does not match / out of order | 486 TRACE_EVENT_START0("cat1", "name1", 0xA); // does not match / out of order |
| 495 } | 487 } |
| 496 EndTracing(); | 488 EndTracing(); |
| 497 | 489 |
| 498 scoped_ptr<TraceAnalyzer> | 490 scoped_ptr<TraceAnalyzer> |
| 499 analyzer(TraceAnalyzer::Create(output_.json_output)); | 491 analyzer(TraceAnalyzer::Create(output_.json_output)); |
| 500 ASSERT_TRUE(analyzer.get()); | 492 ASSERT_TRUE(analyzer.get()); |
| 501 analyzer->AssociateStartFinishEvents(); | 493 analyzer->AssociateStartFinishEvents(); |
| 502 | 494 |
| 503 TraceEventVector found; | 495 TraceEventVector found; |
| 504 analyzer->FindEvents(Query::MatchStartWithFinish(), &found); | 496 analyzer->FindEvents(Query::MatchStartWithFinish(), &found); |
| 505 ASSERT_EQ(2u, found.size()); | 497 ASSERT_EQ(2u, found.size()); |
| 506 EXPECT_STRCASEEQ("B", found[0]->id.c_str()); | 498 EXPECT_STRCASEEQ("B", found[0]->id.c_str()); |
| 507 EXPECT_STRCASEEQ("C", found[1]->id.c_str()); | 499 EXPECT_STRCASEEQ("C", found[1]->id.c_str()); |
| 508 } | 500 } |
| 509 | 501 |
| 510 // Test that the TraceAnalyzer custom associations work. | 502 // Test that the TraceAnalyzer custom associations work. |
| 511 TEST_F(TraceEventAnalyzerTest, CustomAssociations) { | 503 TEST_F(TraceEventAnalyzerTest, CustomAssociations) { |
| 512 using namespace trace_analyzer; | |
| 513 ManualSetUp(); | 504 ManualSetUp(); |
| 514 | 505 |
| 515 // Add events that begin/end in pipelined ordering with unique ID parameter | 506 // Add events that begin/end in pipelined ordering with unique ID parameter |
| 516 // to match up the begin/end pairs. | 507 // to match up the begin/end pairs. |
| 517 BeginTracing(); | 508 BeginTracing(); |
| 518 { | 509 { |
| 519 TRACE_EVENT_INSTANT1("cat1", "end", "id", 1); // no begin match | 510 TRACE_EVENT_INSTANT1("cat1", "end", "id", 1); // no begin match |
| 520 TRACE_EVENT_INSTANT1("cat2", "begin", "id", 2); // end is cat4 | 511 TRACE_EVENT_INSTANT1("cat2", "begin", "id", 2); // end is cat4 |
| 521 TRACE_EVENT_INSTANT1("cat3", "begin", "id", 3); // end is cat5 | 512 TRACE_EVENT_INSTANT1("cat3", "begin", "id", 3); // end is cat5 |
| 522 TRACE_EVENT_INSTANT1("cat4", "end", "id", 2); | 513 TRACE_EVENT_INSTANT1("cat4", "end", "id", 2); |
| 523 TRACE_EVENT_INSTANT1("cat5", "end", "id", 3); | 514 TRACE_EVENT_INSTANT1("cat5", "end", "id", 3); |
| 524 TRACE_EVENT_INSTANT1("cat6", "begin", "id", 1); // no end match | 515 TRACE_EVENT_INSTANT1("cat6", "begin", "id", 1); // no end match |
| 525 } | 516 } |
| 526 EndTracing(); | 517 EndTracing(); |
| 527 | 518 |
| 528 scoped_ptr<TraceAnalyzer> | 519 scoped_ptr<TraceAnalyzer> |
| 529 analyzer(TraceAnalyzer::Create(output_.json_output)); | 520 analyzer(TraceAnalyzer::Create(output_.json_output)); |
| 530 ASSERT_TRUE(analyzer.get()); | 521 ASSERT_TRUE(analyzer.get()); |
| 531 | 522 |
| 532 // begin, end, and match queries to find proper begin/end pairs. | 523 // begin, end, and match queries to find proper begin/end pairs. |
| 533 Query begin(Query(EVENT_NAME) == Query::String("begin")); | 524 Query begin(Query::EventName() == Query::String("begin")); |
| 534 Query end(Query(EVENT_NAME) == Query::String("end")); | 525 Query end(Query::EventName() == Query::String("end")); |
| 535 Query match(Query(EVENT_ARG, "id") == Query(OTHER_ARG, "id")); | 526 Query match(Query::EventArg("id") == Query::OtherArg("id")); |
| 536 analyzer->AssociateEvents(begin, end, match); | 527 analyzer->AssociateEvents(begin, end, match); |
| 537 | 528 |
| 538 TraceEventVector found; | 529 TraceEventVector found; |
| 539 | 530 |
| 540 // cat1 has no other_event. | 531 // cat1 has no other_event. |
| 541 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat1") && | 532 analyzer->FindEvents(Query::EventCategory() == Query::String("cat1") && |
| 542 Query(EVENT_HAS_OTHER), &found); | 533 Query::EventHasOther(), &found); |
| 543 EXPECT_EQ(0u, found.size()); | 534 EXPECT_EQ(0u, found.size()); |
| 544 | 535 |
| 545 // cat1 has no other_event. | 536 // cat1 has no other_event. |
| 546 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat1") && | 537 analyzer->FindEvents(Query::EventCategory() == Query::String("cat1") && |
| 547 !Query(EVENT_HAS_OTHER), &found); | 538 !Query::EventHasOther(), &found); |
| 548 EXPECT_EQ(1u, found.size()); | 539 EXPECT_EQ(1u, found.size()); |
| 549 | 540 |
| 550 // cat6 has no other_event. | 541 // cat6 has no other_event. |
| 551 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat6") && | 542 analyzer->FindEvents(Query::EventCategory() == Query::String("cat6") && |
| 552 !Query(EVENT_HAS_OTHER), &found); | 543 !Query::EventHasOther(), &found); |
| 553 EXPECT_EQ(1u, found.size()); | 544 EXPECT_EQ(1u, found.size()); |
| 554 | 545 |
| 555 // cat2 and cat4 are a associated. | 546 // cat2 and cat4 are a associated. |
| 556 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat2") && | 547 analyzer->FindEvents(Query::EventCategory() == Query::String("cat2") && |
| 557 Query(OTHER_CATEGORY) == Query::String("cat4"), &found); | 548 Query::OtherCategory() == Query::String("cat4"), &found); |
| 558 EXPECT_EQ(1u, found.size()); | 549 EXPECT_EQ(1u, found.size()); |
| 559 | 550 |
| 560 // cat4 and cat2 are a associated. | 551 // cat4 and cat2 are a associated. |
| 561 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat4") && | 552 analyzer->FindEvents(Query::EventCategory() == Query::String("cat4") && |
| 562 Query(OTHER_CATEGORY) == Query::String("cat2"), &found); | 553 Query::OtherCategory() == Query::String("cat2"), &found); |
| 563 EXPECT_EQ(1u, found.size()); | 554 EXPECT_EQ(1u, found.size()); |
| 564 | 555 |
| 565 // cat3 and cat5 are a associated. | 556 // cat3 and cat5 are a associated. |
| 566 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat3") && | 557 analyzer->FindEvents(Query::EventCategory() == Query::String("cat3") && |
| 567 Query(OTHER_CATEGORY) == Query::String("cat5"), &found); | 558 Query::OtherCategory() == Query::String("cat5"), &found); |
| 568 EXPECT_EQ(1u, found.size()); | 559 EXPECT_EQ(1u, found.size()); |
| 569 | 560 |
| 570 // cat5 and cat3 are a associated. | 561 // cat5 and cat3 are a associated. |
| 571 analyzer->FindEvents(Query(EVENT_CATEGORY) == Query::String("cat5") && | 562 analyzer->FindEvents(Query::EventCategory() == Query::String("cat5") && |
| 572 Query(OTHER_CATEGORY) == Query::String("cat3"), &found); | 563 Query::OtherCategory() == Query::String("cat3"), &found); |
| 573 EXPECT_EQ(1u, found.size()); | 564 EXPECT_EQ(1u, found.size()); |
| 574 } | 565 } |
| 575 | 566 |
| 576 // Verify that Query literals and types are properly casted. | 567 // Verify that Query literals and types are properly casted. |
| 577 TEST_F(TraceEventAnalyzerTest, Literals) { | 568 TEST_F(TraceEventAnalyzerTest, Literals) { |
| 578 using namespace trace_analyzer; | |
| 579 ManualSetUp(); | 569 ManualSetUp(); |
| 580 | 570 |
| 581 // Since these queries don't refer to the event data, the dummy event below | 571 // Since these queries don't refer to the event data, the dummy event below |
| 582 // will never be accessed. | 572 // will never be accessed. |
| 583 TraceEvent dummy; | 573 TraceEvent dummy; |
| 584 char char_num = 5; | 574 char char_num = 5; |
| 585 short short_num = -5; | 575 short short_num = -5; |
| 586 EXPECT_TRUE((Query::Double(5.0) == Query::Int(char_num)).Evaluate(dummy)); | 576 EXPECT_TRUE((Query::Double(5.0) == Query::Int(char_num)).Evaluate(dummy)); |
| 587 EXPECT_TRUE((Query::Double(-5.0) == Query::Int(short_num)).Evaluate(dummy)); | 577 EXPECT_TRUE((Query::Double(-5.0) == Query::Int(short_num)).Evaluate(dummy)); |
| 588 EXPECT_TRUE((Query::Double(1.0) == Query::Uint(1u)).Evaluate(dummy)); | 578 EXPECT_TRUE((Query::Double(1.0) == Query::Uint(1u)).Evaluate(dummy)); |
| 589 EXPECT_TRUE((Query::Double(1.0) == Query::Int(1)).Evaluate(dummy)); | 579 EXPECT_TRUE((Query::Double(1.0) == Query::Int(1)).Evaluate(dummy)); |
| 590 EXPECT_TRUE((Query::Double(-1.0) == Query::Int(-1)).Evaluate(dummy)); | 580 EXPECT_TRUE((Query::Double(-1.0) == Query::Int(-1)).Evaluate(dummy)); |
| 591 EXPECT_TRUE((Query::Double(1.0) == Query::Double(1.0f)).Evaluate(dummy)); | 581 EXPECT_TRUE((Query::Double(1.0) == Query::Double(1.0f)).Evaluate(dummy)); |
| 592 EXPECT_TRUE((Query::Bool(true) == Query::Int(1)).Evaluate(dummy)); | 582 EXPECT_TRUE((Query::Bool(true) == Query::Int(1)).Evaluate(dummy)); |
| 593 EXPECT_TRUE((Query::Bool(false) == Query::Int(0)).Evaluate(dummy)); | 583 EXPECT_TRUE((Query::Bool(false) == Query::Int(0)).Evaluate(dummy)); |
| 594 EXPECT_TRUE((Query::Bool(true) == Query::Double(1.0f)).Evaluate(dummy)); | 584 EXPECT_TRUE((Query::Bool(true) == Query::Double(1.0f)).Evaluate(dummy)); |
| 595 EXPECT_TRUE((Query::Bool(false) == Query::Double(0.0f)).Evaluate(dummy)); | 585 EXPECT_TRUE((Query::Bool(false) == Query::Double(0.0f)).Evaluate(dummy)); |
| 596 } | 586 } |
| 597 | 587 |
| 598 // Test GetRateStats. | 588 // Test GetRateStats. |
| 599 TEST_F(TraceEventAnalyzerTest, RateStats) { | 589 TEST_F(TraceEventAnalyzerTest, RateStats) { |
| 600 using namespace trace_analyzer; | |
| 601 | |
| 602 std::vector<TraceEvent> events; | 590 std::vector<TraceEvent> events; |
| 603 events.reserve(100); | 591 events.reserve(100); |
| 604 TraceEventVector event_ptrs; | 592 TraceEventVector event_ptrs; |
| 605 TraceEvent event; | 593 TraceEvent event; |
| 606 event.timestamp = 0.0; | 594 event.timestamp = 0.0; |
| 607 double little_delta = 1.0; | 595 double little_delta = 1.0; |
| 608 double big_delta = 10.0; | 596 double big_delta = 10.0; |
| 609 RateStats stats; | 597 RateStats stats; |
| 610 | 598 |
| 611 for (int i = 0; i < 10; ++i) { | 599 for (int i = 0; i < 10; ++i) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 633 TraceEventVector few_event_ptrs; | 621 TraceEventVector few_event_ptrs; |
| 634 few_event_ptrs.push_back(&event); | 622 few_event_ptrs.push_back(&event); |
| 635 few_event_ptrs.push_back(&event); | 623 few_event_ptrs.push_back(&event); |
| 636 ASSERT_FALSE(GetRateStats(few_event_ptrs, &stats)); | 624 ASSERT_FALSE(GetRateStats(few_event_ptrs, &stats)); |
| 637 few_event_ptrs.push_back(&event); | 625 few_event_ptrs.push_back(&event); |
| 638 ASSERT_TRUE(GetRateStats(few_event_ptrs, &stats)); | 626 ASSERT_TRUE(GetRateStats(few_event_ptrs, &stats)); |
| 639 } | 627 } |
| 640 | 628 |
| 641 // Test FindFirstOf and FindLastOf. | 629 // Test FindFirstOf and FindLastOf. |
| 642 TEST_F(TraceEventAnalyzerTest, FindOf) { | 630 TEST_F(TraceEventAnalyzerTest, FindOf) { |
| 643 using namespace trace_analyzer; | |
| 644 | |
| 645 size_t num_events = 100; | 631 size_t num_events = 100; |
| 646 size_t index = 0; | 632 size_t index = 0; |
| 647 TraceEventVector event_ptrs; | 633 TraceEventVector event_ptrs; |
| 648 EXPECT_FALSE(FindFirstOf(event_ptrs, Query::Bool(true), 0, &index)); | 634 EXPECT_FALSE(FindFirstOf(event_ptrs, Query::Bool(true), 0, &index)); |
| 649 EXPECT_FALSE(FindFirstOf(event_ptrs, Query::Bool(true), 10, &index)); | 635 EXPECT_FALSE(FindFirstOf(event_ptrs, Query::Bool(true), 10, &index)); |
| 650 EXPECT_FALSE(FindLastOf(event_ptrs, Query::Bool(true), 0, &index)); | 636 EXPECT_FALSE(FindLastOf(event_ptrs, Query::Bool(true), 0, &index)); |
| 651 EXPECT_FALSE(FindLastOf(event_ptrs, Query::Bool(true), 10, &index)); | 637 EXPECT_FALSE(FindLastOf(event_ptrs, Query::Bool(true), 10, &index)); |
| 652 | 638 |
| 653 std::vector<TraceEvent> events; | 639 std::vector<TraceEvent> events; |
| 654 events.resize(num_events); | 640 events.resize(num_events); |
| 655 for (size_t i = 0; i < events.size(); ++i) | 641 for (size_t i = 0; i < events.size(); ++i) |
| 656 event_ptrs.push_back(&events[i]); | 642 event_ptrs.push_back(&events[i]); |
| 657 size_t bam_index = num_events/2; | 643 size_t bam_index = num_events/2; |
| 658 events[bam_index].name = "bam"; | 644 events[bam_index].name = "bam"; |
| 659 Query query_bam = Query(EVENT_NAME) == Query::String(events[bam_index].name); | 645 Query query_bam = Query::EventName() == Query::String(events[bam_index].name); |
| 660 | 646 |
| 661 // FindFirstOf | 647 // FindFirstOf |
| 662 EXPECT_FALSE(FindFirstOf(event_ptrs, Query::Bool(false), 0, &index)); | 648 EXPECT_FALSE(FindFirstOf(event_ptrs, Query::Bool(false), 0, &index)); |
| 663 EXPECT_TRUE(FindFirstOf(event_ptrs, Query::Bool(true), 0, &index)); | 649 EXPECT_TRUE(FindFirstOf(event_ptrs, Query::Bool(true), 0, &index)); |
| 664 EXPECT_EQ(0u, index); | 650 EXPECT_EQ(0u, index); |
| 665 EXPECT_TRUE(FindFirstOf(event_ptrs, Query::Bool(true), 5, &index)); | 651 EXPECT_TRUE(FindFirstOf(event_ptrs, Query::Bool(true), 5, &index)); |
| 666 EXPECT_EQ(5u, index); | 652 EXPECT_EQ(5u, index); |
| 667 | 653 |
| 668 EXPECT_FALSE(FindFirstOf(event_ptrs, query_bam, bam_index + 1, &index)); | 654 EXPECT_FALSE(FindFirstOf(event_ptrs, query_bam, bam_index + 1, &index)); |
| 669 EXPECT_TRUE(FindFirstOf(event_ptrs, query_bam, 0, &index)); | 655 EXPECT_TRUE(FindFirstOf(event_ptrs, query_bam, 0, &index)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 681 | 667 |
| 682 EXPECT_FALSE(FindLastOf(event_ptrs, query_bam, bam_index - 1, &index)); | 668 EXPECT_FALSE(FindLastOf(event_ptrs, query_bam, bam_index - 1, &index)); |
| 683 EXPECT_TRUE(FindLastOf(event_ptrs, query_bam, num_events, &index)); | 669 EXPECT_TRUE(FindLastOf(event_ptrs, query_bam, num_events, &index)); |
| 684 EXPECT_EQ(bam_index, index); | 670 EXPECT_EQ(bam_index, index); |
| 685 EXPECT_TRUE(FindLastOf(event_ptrs, query_bam, bam_index, &index)); | 671 EXPECT_TRUE(FindLastOf(event_ptrs, query_bam, bam_index, &index)); |
| 686 EXPECT_EQ(bam_index, index); | 672 EXPECT_EQ(bam_index, index); |
| 687 } | 673 } |
| 688 | 674 |
| 689 // Test FindClosest. | 675 // Test FindClosest. |
| 690 TEST_F(TraceEventAnalyzerTest, FindClosest) { | 676 TEST_F(TraceEventAnalyzerTest, FindClosest) { |
| 691 using namespace trace_analyzer; | |
| 692 | |
| 693 size_t index_1 = 0; | 677 size_t index_1 = 0; |
| 694 size_t index_2 = 0; | 678 size_t index_2 = 0; |
| 695 TraceEventVector event_ptrs; | 679 TraceEventVector event_ptrs; |
| 696 EXPECT_FALSE(FindClosest(event_ptrs, Query::Bool(true), 0, | 680 EXPECT_FALSE(FindClosest(event_ptrs, Query::Bool(true), 0, |
| 697 &index_1, &index_2)); | 681 &index_1, &index_2)); |
| 698 | 682 |
| 699 size_t num_events = 5; | 683 size_t num_events = 5; |
| 700 std::vector<TraceEvent> events; | 684 std::vector<TraceEvent> events; |
| 701 events.resize(num_events); | 685 events.resize(num_events); |
| 702 for (size_t i = 0; i < events.size(); ++i) { | 686 for (size_t i = 0; i < events.size(); ++i) { |
| 703 // timestamps go up exponentially so the lower index is always closer in | 687 // timestamps go up exponentially so the lower index is always closer in |
| 704 // time than the higher index. | 688 // time than the higher index. |
| 705 events[i].timestamp = static_cast<double>(i) * static_cast<double>(i); | 689 events[i].timestamp = static_cast<double>(i) * static_cast<double>(i); |
| 706 event_ptrs.push_back(&events[i]); | 690 event_ptrs.push_back(&events[i]); |
| 707 } | 691 } |
| 708 events[0].name = "one"; | 692 events[0].name = "one"; |
| 709 events[2].name = "two"; | 693 events[2].name = "two"; |
| 710 events[4].name = "three"; | 694 events[4].name = "three"; |
| 711 Query query_named = Query(EVENT_NAME) != Query::String(""); | 695 Query query_named = Query::EventName() != Query::String(""); |
| 712 Query query_one = Query(EVENT_NAME) == Query::String("one"); | 696 Query query_one = Query::EventName() == Query::String("one"); |
| 713 | 697 |
| 714 // Only one event matches query_one, so two closest can't be found. | 698 // Only one event matches query_one, so two closest can't be found. |
| 715 EXPECT_FALSE(FindClosest(event_ptrs, query_one, 0, &index_1, &index_2)); | 699 EXPECT_FALSE(FindClosest(event_ptrs, query_one, 0, &index_1, &index_2)); |
| 716 | 700 |
| 717 EXPECT_TRUE(FindClosest(event_ptrs, query_one, 3, &index_1, NULL)); | 701 EXPECT_TRUE(FindClosest(event_ptrs, query_one, 3, &index_1, NULL)); |
| 718 EXPECT_EQ(0u, index_1); | 702 EXPECT_EQ(0u, index_1); |
| 719 | 703 |
| 720 EXPECT_TRUE(FindClosest(event_ptrs, query_named, 1, &index_1, &index_2)); | 704 EXPECT_TRUE(FindClosest(event_ptrs, query_named, 1, &index_1, &index_2)); |
| 721 EXPECT_EQ(0u, index_1); | 705 EXPECT_EQ(0u, index_1); |
| 722 EXPECT_EQ(2u, index_2); | 706 EXPECT_EQ(2u, index_2); |
| 723 | 707 |
| 724 EXPECT_TRUE(FindClosest(event_ptrs, query_named, 4, &index_1, &index_2)); | 708 EXPECT_TRUE(FindClosest(event_ptrs, query_named, 4, &index_1, &index_2)); |
| 725 EXPECT_EQ(4u, index_1); | 709 EXPECT_EQ(4u, index_1); |
| 726 EXPECT_EQ(2u, index_2); | 710 EXPECT_EQ(2u, index_2); |
| 727 | 711 |
| 728 EXPECT_TRUE(FindClosest(event_ptrs, query_named, 3, &index_1, &index_2)); | 712 EXPECT_TRUE(FindClosest(event_ptrs, query_named, 3, &index_1, &index_2)); |
| 729 EXPECT_EQ(2u, index_1); | 713 EXPECT_EQ(2u, index_1); |
| 730 EXPECT_EQ(0u, index_2); | 714 EXPECT_EQ(0u, index_2); |
| 731 } | 715 } |
| 732 | 716 |
| 733 // Test CountMatches. | 717 // Test CountMatches. |
| 734 TEST_F(TraceEventAnalyzerTest, CountMatches) { | 718 TEST_F(TraceEventAnalyzerTest, CountMatches) { |
| 735 using namespace trace_analyzer; | |
| 736 | |
| 737 TraceEventVector event_ptrs; | 719 TraceEventVector event_ptrs; |
| 738 EXPECT_EQ(0u, CountMatches(event_ptrs, Query::Bool(true), 0, 10)); | 720 EXPECT_EQ(0u, CountMatches(event_ptrs, Query::Bool(true), 0, 10)); |
| 739 | 721 |
| 740 size_t num_events = 5; | 722 size_t num_events = 5; |
| 741 size_t num_named = 3; | 723 size_t num_named = 3; |
| 742 std::vector<TraceEvent> events; | 724 std::vector<TraceEvent> events; |
| 743 events.resize(num_events); | 725 events.resize(num_events); |
| 744 for (size_t i = 0; i < events.size(); ++i) | 726 for (size_t i = 0; i < events.size(); ++i) |
| 745 event_ptrs.push_back(&events[i]); | 727 event_ptrs.push_back(&events[i]); |
| 746 events[0].name = "one"; | 728 events[0].name = "one"; |
| 747 events[2].name = "two"; | 729 events[2].name = "two"; |
| 748 events[4].name = "three"; | 730 events[4].name = "three"; |
| 749 Query query_named = Query(EVENT_NAME) != Query::String(""); | 731 Query query_named = Query::EventName() != Query::String(""); |
| 750 Query query_one = Query(EVENT_NAME) == Query::String("one"); | 732 Query query_one = Query::EventName() == Query::String("one"); |
| 751 | 733 |
| 752 EXPECT_EQ(0u, CountMatches(event_ptrs, Query::Bool(false))); | 734 EXPECT_EQ(0u, CountMatches(event_ptrs, Query::Bool(false))); |
| 753 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); | 735 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); |
| 754 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), | 736 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), |
| 755 1, num_events)); | 737 1, num_events)); |
| 756 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); | 738 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); |
| 757 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); | 739 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); |
| 758 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); | 740 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); |
| 759 } | 741 } |
| 760 | 742 |
| 761 | 743 |
| 762 } // namespace trace_analyzer | 744 } // namespace trace_analyzer |
| OLD | NEW |