OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 using namespace trace_analyzer; | 104 using namespace trace_analyzer; |
105 ManualSetUp(); | 105 ManualSetUp(); |
106 | 106 |
107 TraceEvent event; | 107 TraceEvent event; |
108 event.thread.process_id = 3; | 108 event.thread.process_id = 3; |
109 event.thread.thread_id = 4; | 109 event.thread.thread_id = 4; |
110 event.timestamp = 1.5; | 110 event.timestamp = 1.5; |
111 event.phase = TRACE_EVENT_PHASE_BEGIN; | 111 event.phase = TRACE_EVENT_PHASE_BEGIN; |
112 event.category = "category"; | 112 event.category = "category"; |
113 event.name = "name"; | 113 event.name = "name"; |
| 114 event.id = "1"; |
114 event.arg_numbers["num"] = 7.0; | 115 event.arg_numbers["num"] = 7.0; |
115 event.arg_strings["str"] = "the string"; | 116 event.arg_strings["str"] = "the string"; |
116 | 117 |
117 // Other event with all different members: | 118 // Other event with all different members: |
118 TraceEvent other; | 119 TraceEvent other; |
119 other.thread.process_id = 5; | 120 other.thread.process_id = 5; |
120 other.thread.thread_id = 6; | 121 other.thread.thread_id = 6; |
121 other.timestamp = 2.5; | 122 other.timestamp = 2.5; |
122 other.phase = TRACE_EVENT_PHASE_END; | 123 other.phase = TRACE_EVENT_PHASE_END; |
123 other.category = "category2"; | 124 other.category = "category2"; |
124 other.name = "name2"; | 125 other.name = "name2"; |
| 126 other.id = "2"; |
125 other.arg_numbers["num2"] = 8.0; | 127 other.arg_numbers["num2"] = 8.0; |
126 other.arg_strings["str2"] = "the string 2"; | 128 other.arg_strings["str2"] = "the string 2"; |
127 | 129 |
128 event.other_event = &other; | 130 event.other_event = &other; |
129 ASSERT_TRUE(event.has_other_event()); | 131 ASSERT_TRUE(event.has_other_event()); |
130 double duration = event.GetAbsTimeToOtherEvent(); | 132 double duration = event.GetAbsTimeToOtherEvent(); |
131 | 133 |
132 Query event_pid = (Query(EVENT_PID) == Query::Int(event.thread.process_id)); | 134 Query event_pid = (Query(EVENT_PID) == Query::Int(event.thread.process_id)); |
133 Query event_tid = (Query(EVENT_TID) == Query::Int(event.thread.thread_id)); | 135 Query event_tid = (Query(EVENT_TID) == Query::Int(event.thread.thread_id)); |
134 Query event_time = (Query(EVENT_TIME) == Query::Double(event.timestamp)); | 136 Query event_time = (Query(EVENT_TIME) == Query::Double(event.timestamp)); |
135 Query event_duration = (Query(EVENT_DURATION) == Query::Double(duration)); | 137 Query event_duration = (Query(EVENT_DURATION) == Query::Double(duration)); |
136 Query event_phase = (Query(EVENT_PHASE) == Query::Phase(event.phase)); | 138 Query event_phase = (Query(EVENT_PHASE) == Query::Phase(event.phase)); |
137 Query event_category = | 139 Query event_category = |
138 (Query(EVENT_CATEGORY) == Query::String(event.category)); | 140 (Query(EVENT_CATEGORY) == Query::String(event.category)); |
139 Query event_name = (Query(EVENT_NAME) == Query::String(event.name)); | 141 Query event_name = (Query(EVENT_NAME) == Query::String(event.name)); |
| 142 Query event_id = (Query(EVENT_ID) == Query::String(event.id)); |
140 Query event_has_arg1 = Query(EVENT_HAS_NUMBER_ARG, "num"); | 143 Query event_has_arg1 = Query(EVENT_HAS_NUMBER_ARG, "num"); |
141 Query event_has_arg2 = Query(EVENT_HAS_STRING_ARG, "str"); | 144 Query event_has_arg2 = Query(EVENT_HAS_STRING_ARG, "str"); |
142 Query event_arg1 = | 145 Query event_arg1 = |
143 (Query(EVENT_ARG, "num") == Query::Double(event.arg_numbers["num"])); | 146 (Query(EVENT_ARG, "num") == Query::Double(event.arg_numbers["num"])); |
144 Query event_arg2 = | 147 Query event_arg2 = |
145 (Query(EVENT_ARG, "str") == Query::String(event.arg_strings["str"])); | 148 (Query(EVENT_ARG, "str") == Query::String(event.arg_strings["str"])); |
146 Query event_has_other = Query(EVENT_HAS_OTHER); | 149 Query event_has_other = Query(EVENT_HAS_OTHER); |
147 Query other_pid = (Query(OTHER_PID) == Query::Int(other.thread.process_id)); | 150 Query other_pid = (Query(OTHER_PID) == Query::Int(other.thread.process_id)); |
148 Query other_tid = (Query(OTHER_TID) == Query::Int(other.thread.thread_id)); | 151 Query other_tid = (Query(OTHER_TID) == Query::Int(other.thread.thread_id)); |
149 Query other_time = (Query(OTHER_TIME) == Query::Double(other.timestamp)); | 152 Query other_time = (Query(OTHER_TIME) == Query::Double(other.timestamp)); |
150 Query other_phase = (Query(OTHER_PHASE) == Query::Phase(other.phase)); | 153 Query other_phase = (Query(OTHER_PHASE) == Query::Phase(other.phase)); |
151 Query other_category = | 154 Query other_category = |
152 (Query(OTHER_CATEGORY) == Query::String(other.category)); | 155 (Query(OTHER_CATEGORY) == Query::String(other.category)); |
153 Query other_name = (Query(OTHER_NAME) == Query::String(other.name)); | 156 Query other_name = (Query(OTHER_NAME) == Query::String(other.name)); |
| 157 Query other_id = (Query(OTHER_ID) == Query::String(other.id)); |
154 Query other_has_arg1 = Query(OTHER_HAS_NUMBER_ARG, "num2"); | 158 Query other_has_arg1 = Query(OTHER_HAS_NUMBER_ARG, "num2"); |
155 Query other_has_arg2 = Query(OTHER_HAS_STRING_ARG, "str2"); | 159 Query other_has_arg2 = Query(OTHER_HAS_STRING_ARG, "str2"); |
156 Query other_arg1 = | 160 Query other_arg1 = |
157 (Query(OTHER_ARG, "num2") == Query::Double(other.arg_numbers["num2"])); | 161 (Query(OTHER_ARG, "num2") == Query::Double(other.arg_numbers["num2"])); |
158 Query other_arg2 = | 162 Query other_arg2 = |
159 (Query(OTHER_ARG, "str2") == Query::String(other.arg_strings["str2"])); | 163 (Query(OTHER_ARG, "str2") == Query::String(other.arg_strings["str2"])); |
160 | 164 |
161 EXPECT_TRUE(event_pid.Evaluate(event)); | 165 EXPECT_TRUE(event_pid.Evaluate(event)); |
162 EXPECT_TRUE(event_tid.Evaluate(event)); | 166 EXPECT_TRUE(event_tid.Evaluate(event)); |
163 EXPECT_TRUE(event_time.Evaluate(event)); | 167 EXPECT_TRUE(event_time.Evaluate(event)); |
164 EXPECT_TRUE(event_duration.Evaluate(event)); | 168 EXPECT_TRUE(event_duration.Evaluate(event)); |
165 EXPECT_TRUE(event_phase.Evaluate(event)); | 169 EXPECT_TRUE(event_phase.Evaluate(event)); |
166 EXPECT_TRUE(event_category.Evaluate(event)); | 170 EXPECT_TRUE(event_category.Evaluate(event)); |
167 EXPECT_TRUE(event_name.Evaluate(event)); | 171 EXPECT_TRUE(event_name.Evaluate(event)); |
| 172 EXPECT_TRUE(event_id.Evaluate(event)); |
168 EXPECT_TRUE(event_has_arg1.Evaluate(event)); | 173 EXPECT_TRUE(event_has_arg1.Evaluate(event)); |
169 EXPECT_TRUE(event_has_arg2.Evaluate(event)); | 174 EXPECT_TRUE(event_has_arg2.Evaluate(event)); |
170 EXPECT_TRUE(event_arg1.Evaluate(event)); | 175 EXPECT_TRUE(event_arg1.Evaluate(event)); |
171 EXPECT_TRUE(event_arg2.Evaluate(event)); | 176 EXPECT_TRUE(event_arg2.Evaluate(event)); |
172 EXPECT_TRUE(event_has_other.Evaluate(event)); | 177 EXPECT_TRUE(event_has_other.Evaluate(event)); |
173 EXPECT_TRUE(other_pid.Evaluate(event)); | 178 EXPECT_TRUE(other_pid.Evaluate(event)); |
174 EXPECT_TRUE(other_tid.Evaluate(event)); | 179 EXPECT_TRUE(other_tid.Evaluate(event)); |
175 EXPECT_TRUE(other_time.Evaluate(event)); | 180 EXPECT_TRUE(other_time.Evaluate(event)); |
176 EXPECT_TRUE(other_phase.Evaluate(event)); | 181 EXPECT_TRUE(other_phase.Evaluate(event)); |
177 EXPECT_TRUE(other_category.Evaluate(event)); | 182 EXPECT_TRUE(other_category.Evaluate(event)); |
178 EXPECT_TRUE(other_name.Evaluate(event)); | 183 EXPECT_TRUE(other_name.Evaluate(event)); |
| 184 EXPECT_TRUE(other_id.Evaluate(event)); |
179 EXPECT_TRUE(other_has_arg1.Evaluate(event)); | 185 EXPECT_TRUE(other_has_arg1.Evaluate(event)); |
180 EXPECT_TRUE(other_has_arg2.Evaluate(event)); | 186 EXPECT_TRUE(other_has_arg2.Evaluate(event)); |
181 EXPECT_TRUE(other_arg1.Evaluate(event)); | 187 EXPECT_TRUE(other_arg1.Evaluate(event)); |
182 EXPECT_TRUE(other_arg2.Evaluate(event)); | 188 EXPECT_TRUE(other_arg2.Evaluate(event)); |
183 | 189 |
184 // Evaluate event queries against other to verify the queries fail when the | 190 // Evaluate event queries against other to verify the queries fail when the |
185 // event members are wrong. | 191 // event members are wrong. |
186 EXPECT_FALSE(event_pid.Evaluate(other)); | 192 EXPECT_FALSE(event_pid.Evaluate(other)); |
187 EXPECT_FALSE(event_tid.Evaluate(other)); | 193 EXPECT_FALSE(event_tid.Evaluate(other)); |
188 EXPECT_FALSE(event_time.Evaluate(other)); | 194 EXPECT_FALSE(event_time.Evaluate(other)); |
189 EXPECT_FALSE(event_duration.Evaluate(other)); | 195 EXPECT_FALSE(event_duration.Evaluate(other)); |
190 EXPECT_FALSE(event_phase.Evaluate(other)); | 196 EXPECT_FALSE(event_phase.Evaluate(other)); |
191 EXPECT_FALSE(event_category.Evaluate(other)); | 197 EXPECT_FALSE(event_category.Evaluate(other)); |
192 EXPECT_FALSE(event_name.Evaluate(other)); | 198 EXPECT_FALSE(event_name.Evaluate(other)); |
| 199 EXPECT_FALSE(event_id.Evaluate(other)); |
193 EXPECT_FALSE(event_has_arg1.Evaluate(other)); | 200 EXPECT_FALSE(event_has_arg1.Evaluate(other)); |
194 EXPECT_FALSE(event_has_arg2.Evaluate(other)); | 201 EXPECT_FALSE(event_has_arg2.Evaluate(other)); |
195 EXPECT_FALSE(event_arg1.Evaluate(other)); | 202 EXPECT_FALSE(event_arg1.Evaluate(other)); |
196 EXPECT_FALSE(event_arg2.Evaluate(other)); | 203 EXPECT_FALSE(event_arg2.Evaluate(other)); |
197 EXPECT_FALSE(event_has_other.Evaluate(other)); | 204 EXPECT_FALSE(event_has_other.Evaluate(other)); |
198 } | 205 } |
199 | 206 |
200 TEST_F(TraceEventAnalyzerTest, BooleanOperators) { | 207 TEST_F(TraceEventAnalyzerTest, BooleanOperators) { |
201 using namespace trace_analyzer; | 208 using namespace trace_analyzer; |
202 ManualSetUp(); | 209 ManualSetUp(); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 analyzer->FindEvents(Query::MatchBeginWithEnd() && | 414 analyzer->FindEvents(Query::MatchBeginWithEnd() && |
408 Query(EVENT_DURATION) > Query::Int(duration_cutoff_us) && | 415 Query(EVENT_DURATION) > Query::Int(duration_cutoff_us) && |
409 (Query(EVENT_CATEGORY) == Query::String("cat1") || | 416 (Query(EVENT_CATEGORY) == Query::String("cat1") || |
410 Query(EVENT_CATEGORY) == Query::String("cat2") || | 417 Query(EVENT_CATEGORY) == Query::String("cat2") || |
411 Query(EVENT_CATEGORY) == Query::String("cat3")), &found); | 418 Query(EVENT_CATEGORY) == Query::String("cat3")), &found); |
412 ASSERT_EQ(2u, found.size()); | 419 ASSERT_EQ(2u, found.size()); |
413 EXPECT_STREQ("name1", found[0]->name.c_str()); | 420 EXPECT_STREQ("name1", found[0]->name.c_str()); |
414 EXPECT_STREQ("name3", found[1]->name.c_str()); | 421 EXPECT_STREQ("name3", found[1]->name.c_str()); |
415 } | 422 } |
416 | 423 |
417 // Test that arithmetic operators work. | 424 // Test AssociateBeginEndEvents |
418 TEST_F(TraceEventAnalyzerTest, BeginEndAssocations) { | 425 TEST_F(TraceEventAnalyzerTest, BeginEndAssocations) { |
419 using namespace trace_analyzer; | 426 using namespace trace_analyzer; |
420 ManualSetUp(); | 427 ManualSetUp(); |
421 | 428 |
422 BeginTracing(); | 429 BeginTracing(); |
423 { | 430 { |
424 TRACE_EVENT_END0("cat1", "name1"); // does not match out of order begin | 431 TRACE_EVENT_END0("cat1", "name1"); // does not match out of order begin |
425 TRACE_EVENT0("cat1", "name2"); | 432 TRACE_EVENT0("cat1", "name2"); |
426 TRACE_EVENT_INSTANT0("cat1", "name3"); | 433 TRACE_EVENT_INSTANT0("cat1", "name3"); |
427 TRACE_EVENT_BEGIN0("cat1", "name1"); | 434 TRACE_EVENT_BEGIN0("cat1", "name1"); |
428 } | 435 } |
429 EndTracing(); | 436 EndTracing(); |
430 | 437 |
431 scoped_ptr<TraceAnalyzer> | 438 scoped_ptr<TraceAnalyzer> |
432 analyzer(TraceAnalyzer::Create(output_.json_output)); | 439 analyzer(TraceAnalyzer::Create(output_.json_output)); |
433 ASSERT_TRUE(analyzer.get()); | 440 ASSERT_TRUE(analyzer.get()); |
434 analyzer->AssociateBeginEndEvents(); | 441 analyzer->AssociateBeginEndEvents(); |
435 | 442 |
436 TraceAnalyzer::TraceEventVector found; | 443 TraceAnalyzer::TraceEventVector found; |
437 analyzer->FindEvents(Query::MatchBeginWithEnd(), &found); | 444 analyzer->FindEvents(Query::MatchBeginWithEnd(), &found); |
438 ASSERT_EQ(1u, found.size()); | 445 ASSERT_EQ(1u, found.size()); |
439 EXPECT_STREQ("name2", found[0]->name.c_str()); | 446 EXPECT_STREQ("name2", found[0]->name.c_str()); |
440 } | 447 } |
441 | 448 |
| 449 // Test AssociateStartFinishEvents |
| 450 TEST_F(TraceEventAnalyzerTest, StartFinishAssocations) { |
| 451 using namespace trace_analyzer; |
| 452 ManualSetUp(); |
| 453 |
| 454 BeginTracing(); |
| 455 { |
| 456 TRACE_EVENT_FINISH0("cat1", "name1", 0xA); // does not match / out of order |
| 457 TRACE_EVENT_START0("cat1", "name1", 0xB); |
| 458 TRACE_EVENT_START0("cat1", "name1", 0xC); |
| 459 TRACE_EVENT_INSTANT0("cat1", "name1"); // noise |
| 460 TRACE_EVENT0("cat1", "name1"); // noise |
| 461 TRACE_EVENT_FINISH0("cat1", "name1", 0xB); |
| 462 TRACE_EVENT_FINISH0("cat1", "name1", 0xC); |
| 463 TRACE_EVENT_START0("cat1", "name1", 0xA); // does not match / out of order |
| 464 } |
| 465 EndTracing(); |
| 466 |
| 467 scoped_ptr<TraceAnalyzer> |
| 468 analyzer(TraceAnalyzer::Create(output_.json_output)); |
| 469 ASSERT_TRUE(analyzer.get()); |
| 470 analyzer->AssociateStartFinishEvents(); |
| 471 |
| 472 TraceAnalyzer::TraceEventVector found; |
| 473 analyzer->FindEvents(Query::MatchStartWithFinish(), &found); |
| 474 ASSERT_EQ(2u, found.size()); |
| 475 EXPECT_STRCASEEQ("B", found[0]->id.c_str()); |
| 476 EXPECT_STRCASEEQ("C", found[1]->id.c_str()); |
| 477 } |
| 478 |
442 // Test that the TraceAnalyzer custom associations work. | 479 // Test that the TraceAnalyzer custom associations work. |
443 TEST_F(TraceEventAnalyzerTest, CustomAssociations) { | 480 TEST_F(TraceEventAnalyzerTest, CustomAssociations) { |
444 using namespace trace_analyzer; | 481 using namespace trace_analyzer; |
445 ManualSetUp(); | 482 ManualSetUp(); |
446 | 483 |
447 // Add events that begin/end in pipelined ordering with unique ID parameter | 484 // Add events that begin/end in pipelined ordering with unique ID parameter |
448 // to match up the begin/end pairs. | 485 // to match up the begin/end pairs. |
449 BeginTracing(); | 486 BeginTracing(); |
450 { | 487 { |
451 TRACE_EVENT_INSTANT1("cat1", "end", "id", 1); // no begin match | 488 TRACE_EVENT_INSTANT1("cat1", "end", "id", 1); // no begin match |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 EXPECT_TRUE((Query::Double(1.0) == Query::Double(1.0f)).Evaluate(dummy)); | 560 EXPECT_TRUE((Query::Double(1.0) == Query::Double(1.0f)).Evaluate(dummy)); |
524 EXPECT_TRUE((Query::Bool(true) == Query::Int(1)).Evaluate(dummy)); | 561 EXPECT_TRUE((Query::Bool(true) == Query::Int(1)).Evaluate(dummy)); |
525 EXPECT_TRUE((Query::Bool(false) == Query::Int(0)).Evaluate(dummy)); | 562 EXPECT_TRUE((Query::Bool(false) == Query::Int(0)).Evaluate(dummy)); |
526 EXPECT_TRUE((Query::Bool(true) == Query::Double(1.0f)).Evaluate(dummy)); | 563 EXPECT_TRUE((Query::Bool(true) == Query::Double(1.0f)).Evaluate(dummy)); |
527 EXPECT_TRUE((Query::Bool(false) == Query::Double(0.0f)).Evaluate(dummy)); | 564 EXPECT_TRUE((Query::Bool(false) == Query::Double(0.0f)).Evaluate(dummy)); |
528 } | 565 } |
529 | 566 |
530 | 567 |
531 } // namespace trace_analyzer | 568 } // namespace trace_analyzer |
532 | 569 |
OLD | NEW |