Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: base/test/trace_event_analyzer_unittest.cc

Issue 12252058: Add a |scope| argument to TRACE_EVENT_INSTANT* and require its presence. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use flags to record scope Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/debug/trace_event_unittest.h" 6 #include "base/debug/trace_event_unittest.h"
7 #include "base/test/trace_event_analyzer.h" 7 #include "base/test/trace_event_analyzer.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 EXPECT_FALSE(event_arg1.Evaluate(other)); 197 EXPECT_FALSE(event_arg1.Evaluate(other));
198 EXPECT_FALSE(event_arg2.Evaluate(other)); 198 EXPECT_FALSE(event_arg2.Evaluate(other));
199 EXPECT_FALSE(event_has_other.Evaluate(other)); 199 EXPECT_FALSE(event_has_other.Evaluate(other));
200 } 200 }
201 201
202 TEST_F(TraceEventAnalyzerTest, BooleanOperators) { 202 TEST_F(TraceEventAnalyzerTest, BooleanOperators) {
203 ManualSetUp(); 203 ManualSetUp();
204 204
205 BeginTracing(); 205 BeginTracing();
206 { 206 {
207 TRACE_EVENT_INSTANT1("cat1", "name1", "num", 1); 207 TRACE_EVENT_INSTANT1("cat1", "name1", TRACE_EVENT_SCOPE_THREAD, "num", 1);
208 TRACE_EVENT_INSTANT1("cat1", "name2", "num", 2); 208 TRACE_EVENT_INSTANT1("cat1", "name2", TRACE_EVENT_SCOPE_THREAD, "num", 2);
209 TRACE_EVENT_INSTANT1("cat2", "name3", "num", 3); 209 TRACE_EVENT_INSTANT1("cat2", "name3", TRACE_EVENT_SCOPE_THREAD, "num", 3);
210 TRACE_EVENT_INSTANT1("cat2", "name4", "num", 4); 210 TRACE_EVENT_INSTANT1("cat2", "name4", TRACE_EVENT_SCOPE_THREAD, "num", 4);
211 } 211 }
212 EndTracing(); 212 EndTracing();
213 213
214 scoped_ptr<TraceAnalyzer> 214 scoped_ptr<TraceAnalyzer>
215 analyzer(TraceAnalyzer::Create(output_.json_output)); 215 analyzer(TraceAnalyzer::Create(output_.json_output));
216 ASSERT_TRUE(!!analyzer.get()); 216 ASSERT_TRUE(!!analyzer.get());
217 217
218 TraceEventVector found; 218 TraceEventVector found;
219 219
220 // == 220 // ==
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 EXPECT_STREQ("name2", found[0]->name.c_str()); 282 EXPECT_STREQ("name2", found[0]->name.c_str());
283 EXPECT_STREQ("name4", found[1]->name.c_str()); 283 EXPECT_STREQ("name4", found[1]->name.c_str());
284 } 284 }
285 285
286 TEST_F(TraceEventAnalyzerTest, ArithmeticOperators) { 286 TEST_F(TraceEventAnalyzerTest, ArithmeticOperators) {
287 ManualSetUp(); 287 ManualSetUp();
288 288
289 BeginTracing(); 289 BeginTracing();
290 { 290 {
291 // These events are searched for: 291 // These events are searched for:
292 TRACE_EVENT_INSTANT2("cat1", "math1", "a", 10, "b", 5); 292 TRACE_EVENT_INSTANT2("cat1", "math1", TRACE_EVENT_SCOPE_THREAD,
293 TRACE_EVENT_INSTANT2("cat1", "math2", "a", 10, "b", 10); 293 "a", 10, "b", 5);
294 TRACE_EVENT_INSTANT2("cat1", "math2", TRACE_EVENT_SCOPE_THREAD,
295 "a", 10, "b", 10);
294 // Extra events that never match, for noise: 296 // Extra events that never match, for noise:
295 TRACE_EVENT_INSTANT2("noise", "math3", "a", 1, "b", 3); 297 TRACE_EVENT_INSTANT2("noise", "math3", TRACE_EVENT_SCOPE_THREAD,
296 TRACE_EVENT_INSTANT2("noise", "math4", "c", 10, "d", 5); 298 "a", 1, "b", 3);
299 TRACE_EVENT_INSTANT2("noise", "math4", TRACE_EVENT_SCOPE_THREAD,
300 "c", 10, "d", 5);
297 } 301 }
298 EndTracing(); 302 EndTracing();
299 303
300 scoped_ptr<TraceAnalyzer> 304 scoped_ptr<TraceAnalyzer>
301 analyzer(TraceAnalyzer::Create(output_.json_output)); 305 analyzer(TraceAnalyzer::Create(output_.json_output));
302 ASSERT_TRUE(analyzer.get()); 306 ASSERT_TRUE(analyzer.get());
303 307
304 TraceEventVector found; 308 TraceEventVector found;
305 309
306 // Verify that arithmetic operators function: 310 // Verify that arithmetic operators function:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 analyzer->FindEvents(-Query::EventArg("b") == Query::Int(-10), &found); 342 analyzer->FindEvents(-Query::EventArg("b") == Query::Int(-10), &found);
339 EXPECT_EQ(1u, found.size()); 343 EXPECT_EQ(1u, found.size());
340 EXPECT_STREQ("math2", found.front()->name.c_str()); 344 EXPECT_STREQ("math2", found.front()->name.c_str());
341 } 345 }
342 346
343 TEST_F(TraceEventAnalyzerTest, StringPattern) { 347 TEST_F(TraceEventAnalyzerTest, StringPattern) {
344 ManualSetUp(); 348 ManualSetUp();
345 349
346 BeginTracing(); 350 BeginTracing();
347 { 351 {
348 TRACE_EVENT_INSTANT0("cat1", "name1"); 352 TRACE_EVENT_INSTANT0("cat1", "name1", TRACE_EVENT_SCOPE_THREAD);
349 TRACE_EVENT_INSTANT0("cat1", "name2"); 353 TRACE_EVENT_INSTANT0("cat1", "name2", TRACE_EVENT_SCOPE_THREAD);
350 TRACE_EVENT_INSTANT0("cat1", "no match"); 354 TRACE_EVENT_INSTANT0("cat1", "no match", TRACE_EVENT_SCOPE_THREAD);
351 TRACE_EVENT_INSTANT0("cat1", "name3x"); 355 TRACE_EVENT_INSTANT0("cat1", "name3x", TRACE_EVENT_SCOPE_THREAD);
352 } 356 }
353 EndTracing(); 357 EndTracing();
354 358
355 scoped_ptr<TraceAnalyzer> 359 scoped_ptr<TraceAnalyzer>
356 analyzer(TraceAnalyzer::Create(output_.json_output)); 360 analyzer(TraceAnalyzer::Create(output_.json_output));
357 ASSERT_TRUE(analyzer.get()); 361 ASSERT_TRUE(analyzer.get());
358 362
359 TraceEventVector found; 363 TraceEventVector found;
360 364
361 analyzer->FindEvents(Query::EventName() == Query::Pattern("name?"), &found); 365 analyzer->FindEvents(Query::EventName() == Query::Pattern("name?"), &found);
(...skipping 20 matching lines...) Expand all
382 // 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
383 // sleep time, so that there is no flakiness. 387 // sleep time, so that there is no flakiness.
384 int duration_cutoff_us = (kSleepTime.InMicroseconds() * 9) / 10; 388 int duration_cutoff_us = (kSleepTime.InMicroseconds() * 9) / 10;
385 389
386 BeginTracing(); 390 BeginTracing();
387 { 391 {
388 TRACE_EVENT0("cat1", "name1"); // found by duration query 392 TRACE_EVENT0("cat1", "name1"); // found by duration query
389 TRACE_EVENT0("noise", "name2"); // not searched for, just noise 393 TRACE_EVENT0("noise", "name2"); // not searched for, just noise
390 { 394 {
391 TRACE_EVENT0("cat2", "name3"); // found by duration query 395 TRACE_EVENT0("cat2", "name3"); // found by duration query
392 TRACE_EVENT_INSTANT0("noise", "name4"); // not searched for, just noise 396 // next event not searched for, just noise
397 TRACE_EVENT_INSTANT0("noise", "name4", TRACE_EVENT_SCOPE_THREAD);
393 base::debug::HighResSleepForTraceTest(kSleepTime); 398 base::debug::HighResSleepForTraceTest(kSleepTime);
394 TRACE_EVENT0("cat2", "name5"); // not found (duration too short) 399 TRACE_EVENT0("cat2", "name5"); // not found (duration too short)
395 } 400 }
396 } 401 }
397 EndTracing(); 402 EndTracing();
398 403
399 scoped_ptr<TraceAnalyzer> 404 scoped_ptr<TraceAnalyzer>
400 analyzer(TraceAnalyzer::Create(output_.json_output)); 405 analyzer(TraceAnalyzer::Create(output_.json_output));
401 ASSERT_TRUE(analyzer.get()); 406 ASSERT_TRUE(analyzer.get());
402 analyzer->AssociateBeginEndEvents(); 407 analyzer->AssociateBeginEndEvents();
(...skipping 12 matching lines...) Expand all
415 } 420 }
416 421
417 // Test AssociateBeginEndEvents 422 // Test AssociateBeginEndEvents
418 TEST_F(TraceEventAnalyzerTest, BeginEndAssocations) { 423 TEST_F(TraceEventAnalyzerTest, BeginEndAssocations) {
419 ManualSetUp(); 424 ManualSetUp();
420 425
421 BeginTracing(); 426 BeginTracing();
422 { 427 {
423 TRACE_EVENT_END0("cat1", "name1"); // does not match out of order begin 428 TRACE_EVENT_END0("cat1", "name1"); // does not match out of order begin
424 TRACE_EVENT0("cat1", "name2"); 429 TRACE_EVENT0("cat1", "name2");
425 TRACE_EVENT_INSTANT0("cat1", "name3"); 430 TRACE_EVENT_INSTANT0("cat1", "name3", TRACE_EVENT_SCOPE_THREAD);
426 TRACE_EVENT_BEGIN0("cat1", "name1"); 431 TRACE_EVENT_BEGIN0("cat1", "name1");
427 } 432 }
428 EndTracing(); 433 EndTracing();
429 434
430 scoped_ptr<TraceAnalyzer> 435 scoped_ptr<TraceAnalyzer>
431 analyzer(TraceAnalyzer::Create(output_.json_output)); 436 analyzer(TraceAnalyzer::Create(output_.json_output));
432 ASSERT_TRUE(analyzer.get()); 437 ASSERT_TRUE(analyzer.get());
433 analyzer->AssociateBeginEndEvents(); 438 analyzer->AssociateBeginEndEvents();
434 439
435 TraceEventVector found; 440 TraceEventVector found;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 473
469 // Test AssociateAsyncBeginEndEvents 474 // Test AssociateAsyncBeginEndEvents
470 TEST_F(TraceEventAnalyzerTest, AsyncBeginEndAssocations) { 475 TEST_F(TraceEventAnalyzerTest, AsyncBeginEndAssocations) {
471 ManualSetUp(); 476 ManualSetUp();
472 477
473 BeginTracing(); 478 BeginTracing();
474 { 479 {
475 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xA); // no match / out of order 480 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xA); // no match / out of order
476 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xB); 481 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xB);
477 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xC); 482 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xC);
478 TRACE_EVENT_INSTANT0("cat1", "name1"); // noise 483 TRACE_EVENT_INSTANT0("cat1", "name1", TRACE_EVENT_SCOPE_THREAD); // noise
479 TRACE_EVENT0("cat1", "name1"); // noise 484 TRACE_EVENT0("cat1", "name1"); // noise
480 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xB); 485 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xB);
481 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xC); 486 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xC);
482 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xA); // no match / out of order 487 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xA); // no match / out of order
483 } 488 }
484 EndTracing(); 489 EndTracing();
485 490
486 scoped_ptr<TraceAnalyzer> 491 scoped_ptr<TraceAnalyzer>
487 analyzer(TraceAnalyzer::Create(output_.json_output)); 492 analyzer(TraceAnalyzer::Create(output_.json_output));
488 ASSERT_TRUE(analyzer.get()); 493 ASSERT_TRUE(analyzer.get());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 } 553 }
549 554
550 // Test that the TraceAnalyzer custom associations work. 555 // Test that the TraceAnalyzer custom associations work.
551 TEST_F(TraceEventAnalyzerTest, CustomAssociations) { 556 TEST_F(TraceEventAnalyzerTest, CustomAssociations) {
552 ManualSetUp(); 557 ManualSetUp();
553 558
554 // Add events that begin/end in pipelined ordering with unique ID parameter 559 // Add events that begin/end in pipelined ordering with unique ID parameter
555 // to match up the begin/end pairs. 560 // to match up the begin/end pairs.
556 BeginTracing(); 561 BeginTracing();
557 { 562 {
558 TRACE_EVENT_INSTANT1("cat1", "end", "id", 1); // no begin match 563 // no begin match
559 TRACE_EVENT_INSTANT1("cat2", "begin", "id", 2); // end is cat4 564 TRACE_EVENT_INSTANT1("cat1", "end", TRACE_EVENT_SCOPE_THREAD, "id", 1);
560 TRACE_EVENT_INSTANT1("cat3", "begin", "id", 3); // end is cat5 565 // end is cat4
561 TRACE_EVENT_INSTANT1("cat4", "end", "id", 2); 566 TRACE_EVENT_INSTANT1("cat2", "begin", TRACE_EVENT_SCOPE_THREAD, "id", 2);
562 TRACE_EVENT_INSTANT1("cat5", "end", "id", 3); 567 // end is cat5
563 TRACE_EVENT_INSTANT1("cat6", "begin", "id", 1); // no end match 568 TRACE_EVENT_INSTANT1("cat3", "begin", TRACE_EVENT_SCOPE_THREAD, "id", 3);
569 TRACE_EVENT_INSTANT1("cat4", "end", TRACE_EVENT_SCOPE_THREAD, "id", 2);
570 TRACE_EVENT_INSTANT1("cat5", "end", TRACE_EVENT_SCOPE_THREAD, "id", 3);
571 // no end match
572 TRACE_EVENT_INSTANT1("cat6", "begin", TRACE_EVENT_SCOPE_THREAD, "id", 1);
564 } 573 }
565 EndTracing(); 574 EndTracing();
566 575
567 scoped_ptr<TraceAnalyzer> 576 scoped_ptr<TraceAnalyzer>
568 analyzer(TraceAnalyzer::Create(output_.json_output)); 577 analyzer(TraceAnalyzer::Create(output_.json_output));
569 ASSERT_TRUE(analyzer.get()); 578 ASSERT_TRUE(analyzer.get());
570 579
571 // begin, end, and match queries to find proper begin/end pairs. 580 // begin, end, and match queries to find proper begin/end pairs.
572 Query begin(Query::EventName() == Query::String("begin")); 581 Query begin(Query::EventName() == Query::String("begin"));
573 Query end(Query::EventName() == Query::String("end")); 582 Query end(Query::EventName() == Query::String("end"));
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); 825 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true)));
817 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), 826 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true),
818 1, num_events)); 827 1, num_events));
819 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); 828 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one));
820 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); 829 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one));
821 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); 830 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named));
822 } 831 }
823 832
824 833
825 } // namespace trace_analyzer 834 } // namespace trace_analyzer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698