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/debug/trace_event.h" | 5 #include "base/debug/trace_event.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 "name1", "value1", | 316 "name1", "value1", |
317 "name2", "value2"); | 317 "name2", "value2"); |
318 | 318 |
319 TRACE_EVENT_IF_LONGER_THAN0(0, "all", "TRACE_EVENT_IF_LONGER_THAN0 call"); | 319 TRACE_EVENT_IF_LONGER_THAN0(0, "all", "TRACE_EVENT_IF_LONGER_THAN0 call"); |
320 TRACE_EVENT_IF_LONGER_THAN1(0, "all", "TRACE_EVENT_IF_LONGER_THAN1 call", | 320 TRACE_EVENT_IF_LONGER_THAN1(0, "all", "TRACE_EVENT_IF_LONGER_THAN1 call", |
321 "name1", "value1"); | 321 "name1", "value1"); |
322 TRACE_EVENT_IF_LONGER_THAN2(0, "all", "TRACE_EVENT_IF_LONGER_THAN2 call", | 322 TRACE_EVENT_IF_LONGER_THAN2(0, "all", "TRACE_EVENT_IF_LONGER_THAN2 call", |
323 "name1", "value1", | 323 "name1", "value1", |
324 "name2", "value2"); | 324 "name2", "value2"); |
325 | 325 |
326 TRACE_EVENT_START0("all", "TRACE_EVENT_START0 call", 5); | 326 TRACE_EVENT_ASYNC_BEGIN0("all", "TRACE_EVENT_ASYNC_BEGIN0 call", 5); |
327 TRACE_EVENT_START1("all", "TRACE_EVENT_START1 call", 5, | 327 TRACE_EVENT_ASYNC_BEGIN1("all", "TRACE_EVENT_ASYNC_BEGIN1 call", 5, |
328 "name1", "value1"); | 328 "name1", "value1"); |
329 TRACE_EVENT_START2("all", "TRACE_EVENT_START2 call", 5, | 329 TRACE_EVENT_ASYNC_BEGIN2("all", "TRACE_EVENT_ASYNC_BEGIN2 call", 5, |
330 "name1", "value1", | 330 "name1", "value1", |
331 "name2", "value2"); | 331 "name2", "value2"); |
332 | 332 |
333 TRACE_EVENT_FINISH0("all", "TRACE_EVENT_FINISH0 call", 5); | 333 TRACE_EVENT_ASYNC_STEP0("all", "TRACE_EVENT_ASYNC_STEP0 call", 5); |
334 TRACE_EVENT_FINISH1("all", "TRACE_EVENT_FINISH1 call", 5, | 334 TRACE_EVENT_ASYNC_STEP1("all", "TRACE_EVENT_ASYNC_STEP1 call", 5, |
335 "name1", "value1"); | 335 "name1", "value1"); |
336 TRACE_EVENT_FINISH2("all", "TRACE_EVENT_FINISH2 call", 5, | 336 TRACE_EVENT_ASYNC_STEP2("all", "TRACE_EVENT_ASYNC_STEP2 call", 5, |
337 "name1", "value1", | 337 "name1", "value1", |
338 "name2", "value2"); | 338 "name2", "value2"); |
| 339 |
| 340 TRACE_EVENT_ASYNC_END0("all", "TRACE_EVENT_ASYNC_END0 call", 5); |
| 341 TRACE_EVENT_ASYNC_END1("all", "TRACE_EVENT_ASYNC_END1 call", 5, |
| 342 "name1", "value1"); |
| 343 TRACE_EVENT_ASYNC_END2("all", "TRACE_EVENT_ASYNC_END2 call", 5, |
| 344 "name1", "value1", |
| 345 "name2", "value2"); |
339 | 346 |
340 TRACE_EVENT_BEGIN_ETW("TRACE_EVENT_BEGIN_ETW0 call", 5, NULL); | 347 TRACE_EVENT_BEGIN_ETW("TRACE_EVENT_BEGIN_ETW0 call", 5, NULL); |
341 TRACE_EVENT_BEGIN_ETW("TRACE_EVENT_BEGIN_ETW1 call", 5, "value"); | 348 TRACE_EVENT_BEGIN_ETW("TRACE_EVENT_BEGIN_ETW1 call", 5, "value"); |
342 TRACE_EVENT_END_ETW("TRACE_EVENT_END_ETW0 call", 5, NULL); | 349 TRACE_EVENT_END_ETW("TRACE_EVENT_END_ETW0 call", 5, NULL); |
343 TRACE_EVENT_END_ETW("TRACE_EVENT_END_ETW1 call", 5, "value"); | 350 TRACE_EVENT_END_ETW("TRACE_EVENT_END_ETW1 call", 5, "value"); |
344 TRACE_EVENT_INSTANT_ETW("TRACE_EVENT_INSTANT_ETW0 call", 5, NULL); | 351 TRACE_EVENT_INSTANT_ETW("TRACE_EVENT_INSTANT_ETW0 call", 5, NULL); |
345 TRACE_EVENT_INSTANT_ETW("TRACE_EVENT_INSTANT_ETW1 call", 5, "value"); | 352 TRACE_EVENT_INSTANT_ETW("TRACE_EVENT_INSTANT_ETW1 call", 5, "value"); |
346 | 353 |
347 TRACE_COUNTER1("all", "TRACE_COUNTER1 call", 31415); | 354 TRACE_COUNTER1("all", "TRACE_COUNTER1 call", 31415); |
348 TRACE_COUNTER2("all", "TRACE_COUNTER2 call", | 355 TRACE_COUNTER2("all", "TRACE_COUNTER2 call", |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 EXPECT_FIND_("TRACE_EVENT_IF_LONGER_THAN0 call"); | 440 EXPECT_FIND_("TRACE_EVENT_IF_LONGER_THAN0 call"); |
434 EXPECT_FIND_("TRACE_EVENT_IF_LONGER_THAN1 call"); | 441 EXPECT_FIND_("TRACE_EVENT_IF_LONGER_THAN1 call"); |
435 EXPECT_SUB_FIND_("name1"); | 442 EXPECT_SUB_FIND_("name1"); |
436 EXPECT_SUB_FIND_("value1"); | 443 EXPECT_SUB_FIND_("value1"); |
437 EXPECT_FIND_("TRACE_EVENT_IF_LONGER_THAN2 call"); | 444 EXPECT_FIND_("TRACE_EVENT_IF_LONGER_THAN2 call"); |
438 EXPECT_SUB_FIND_("name1"); | 445 EXPECT_SUB_FIND_("name1"); |
439 EXPECT_SUB_FIND_("value1"); | 446 EXPECT_SUB_FIND_("value1"); |
440 EXPECT_SUB_FIND_("name2"); | 447 EXPECT_SUB_FIND_("name2"); |
441 EXPECT_SUB_FIND_("value2"); | 448 EXPECT_SUB_FIND_("value2"); |
442 | 449 |
443 EXPECT_FIND_("TRACE_EVENT_START0 call"); | 450 EXPECT_FIND_("TRACE_EVENT_ASYNC_BEGIN0 call"); |
444 EXPECT_SUB_FIND_("id"); | 451 EXPECT_SUB_FIND_("id"); |
445 EXPECT_SUB_FIND_("5"); | 452 EXPECT_SUB_FIND_("5"); |
446 EXPECT_FIND_("TRACE_EVENT_START1 call"); | 453 EXPECT_FIND_("TRACE_EVENT_ASYNC_BEGIN1 call"); |
447 EXPECT_SUB_FIND_("id"); | 454 EXPECT_SUB_FIND_("id"); |
448 EXPECT_SUB_FIND_("5"); | 455 EXPECT_SUB_FIND_("5"); |
449 EXPECT_SUB_FIND_("name1"); | 456 EXPECT_SUB_FIND_("name1"); |
450 EXPECT_SUB_FIND_("value1"); | 457 EXPECT_SUB_FIND_("value1"); |
451 EXPECT_FIND_("TRACE_EVENT_START2 call"); | 458 EXPECT_FIND_("TRACE_EVENT_ASYNC_BEGIN2 call"); |
452 EXPECT_SUB_FIND_("id"); | 459 EXPECT_SUB_FIND_("id"); |
453 EXPECT_SUB_FIND_("5"); | 460 EXPECT_SUB_FIND_("5"); |
454 EXPECT_SUB_FIND_("name1"); | 461 EXPECT_SUB_FIND_("name1"); |
| 462 EXPECT_SUB_FIND_("value1"); |
| 463 EXPECT_SUB_FIND_("name2"); |
| 464 EXPECT_SUB_FIND_("value2"); |
| 465 |
| 466 EXPECT_FIND_("TRACE_EVENT_ASYNC_STEP0 call"); |
| 467 EXPECT_SUB_FIND_("id"); |
| 468 EXPECT_SUB_FIND_("5"); |
| 469 EXPECT_FIND_("TRACE_EVENT_ASYNC_STEP1 call"); |
| 470 EXPECT_SUB_FIND_("id"); |
| 471 EXPECT_SUB_FIND_("5"); |
| 472 EXPECT_SUB_FIND_("name1"); |
| 473 EXPECT_SUB_FIND_("value1"); |
| 474 EXPECT_FIND_("TRACE_EVENT_ASYNC_STEP2 call"); |
| 475 EXPECT_SUB_FIND_("id"); |
| 476 EXPECT_SUB_FIND_("5"); |
| 477 EXPECT_SUB_FIND_("name1"); |
455 EXPECT_SUB_FIND_("value1"); | 478 EXPECT_SUB_FIND_("value1"); |
456 EXPECT_SUB_FIND_("name2"); | 479 EXPECT_SUB_FIND_("name2"); |
457 EXPECT_SUB_FIND_("value2"); | 480 EXPECT_SUB_FIND_("value2"); |
458 | 481 |
459 EXPECT_FIND_("TRACE_EVENT_FINISH0 call"); | 482 EXPECT_FIND_("TRACE_EVENT_ASYNC_END0 call"); |
460 EXPECT_SUB_FIND_("id"); | 483 EXPECT_SUB_FIND_("id"); |
461 EXPECT_SUB_FIND_("5"); | 484 EXPECT_SUB_FIND_("5"); |
462 EXPECT_FIND_("TRACE_EVENT_FINISH1 call"); | 485 EXPECT_FIND_("TRACE_EVENT_ASYNC_END1 call"); |
463 EXPECT_SUB_FIND_("id"); | 486 EXPECT_SUB_FIND_("id"); |
464 EXPECT_SUB_FIND_("5"); | 487 EXPECT_SUB_FIND_("5"); |
465 EXPECT_SUB_FIND_("name1"); | 488 EXPECT_SUB_FIND_("name1"); |
466 EXPECT_SUB_FIND_("value1"); | 489 EXPECT_SUB_FIND_("value1"); |
467 EXPECT_FIND_("TRACE_EVENT_FINISH2 call"); | 490 EXPECT_FIND_("TRACE_EVENT_ASYNC_END2 call"); |
468 EXPECT_SUB_FIND_("id"); | 491 EXPECT_SUB_FIND_("id"); |
469 EXPECT_SUB_FIND_("5"); | 492 EXPECT_SUB_FIND_("5"); |
470 EXPECT_SUB_FIND_("name1"); | 493 EXPECT_SUB_FIND_("name1"); |
471 EXPECT_SUB_FIND_("value1"); | 494 EXPECT_SUB_FIND_("value1"); |
472 EXPECT_SUB_FIND_("name2"); | 495 EXPECT_SUB_FIND_("name2"); |
473 EXPECT_SUB_FIND_("value2"); | 496 EXPECT_SUB_FIND_("value2"); |
474 | 497 |
475 EXPECT_FIND_("TRACE_EVENT_BEGIN_ETW0 call"); | 498 EXPECT_FIND_("TRACE_EVENT_BEGIN_ETW0 call"); |
476 EXPECT_SUB_FIND_("id"); | 499 EXPECT_SUB_FIND_("id"); |
477 EXPECT_SUB_FIND_("5"); | 500 EXPECT_SUB_FIND_("5"); |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 EXPECT_NOT_FIND_BE_("3thresholdlong2"); | 933 EXPECT_NOT_FIND_BE_("3thresholdlong2"); |
911 | 934 |
912 EXPECT_FIND_BE_("nonthreshold4"); | 935 EXPECT_FIND_BE_("nonthreshold4"); |
913 EXPECT_FIND_BE_("4threshold100"); | 936 EXPECT_FIND_BE_("4threshold100"); |
914 EXPECT_FIND_BE_("4threshold1000"); | 937 EXPECT_FIND_BE_("4threshold1000"); |
915 EXPECT_FIND_BE_("4threshold10000"); | 938 EXPECT_FIND_BE_("4threshold10000"); |
916 EXPECT_NOT_FIND_BE_("4thresholdlong1"); | 939 EXPECT_NOT_FIND_BE_("4thresholdlong1"); |
917 EXPECT_NOT_FIND_BE_("4thresholdlong2"); | 940 EXPECT_NOT_FIND_BE_("4thresholdlong2"); |
918 } | 941 } |
919 | 942 |
920 // Test Start/Finish events | 943 // Test ASYNC_BEGIN/END events |
921 TEST_F(TraceEventTestFixture, StartFinishEvents) { | 944 TEST_F(TraceEventTestFixture, AsyncBeginEndEvents) { |
922 ManualTestSetUp(); | 945 ManualTestSetUp(); |
923 TraceLog::GetInstance()->SetEnabled(true); | 946 TraceLog::GetInstance()->SetEnabled(true); |
924 | 947 |
925 unsigned long long id = 0xfeedbeeffeedbeefull; | 948 unsigned long long id = 0xfeedbeeffeedbeefull; |
926 TRACE_EVENT_START0( "cat", "name1", id); | 949 TRACE_EVENT_ASYNC_BEGIN0( "cat", "name1", id); |
927 TRACE_EVENT_FINISH0("cat", "name1", id); | 950 TRACE_EVENT_ASYNC_STEP0( "cat", "name1", id); |
| 951 TRACE_EVENT_ASYNC_END0("cat", "name1", id); |
928 TRACE_EVENT_BEGIN0( "cat", "name2"); | 952 TRACE_EVENT_BEGIN0( "cat", "name2"); |
929 TRACE_EVENT_START0( "cat", "name3", 0); | 953 TRACE_EVENT_ASYNC_BEGIN0( "cat", "name3", 0); |
930 | 954 |
931 TraceLog::GetInstance()->SetEnabled(false); | 955 TraceLog::GetInstance()->SetEnabled(false); |
932 | 956 |
933 EXPECT_TRUE(FindNamePhase("name1", "S")); | 957 EXPECT_TRUE(FindNamePhase("name1", "S")); |
| 958 EXPECT_TRUE(FindNamePhase("name1", "T")); |
934 EXPECT_TRUE(FindNamePhase("name1", "F")); | 959 EXPECT_TRUE(FindNamePhase("name1", "F")); |
935 | 960 |
936 std::string id_str; | 961 std::string id_str; |
937 StringAppendF(&id_str, "%llx", id); | 962 StringAppendF(&id_str, "%llx", id); |
938 | 963 |
939 EXPECT_TRUE(FindNamePhaseKeyValue("name1", "S", "id", id_str.c_str())); | 964 EXPECT_TRUE(FindNamePhaseKeyValue("name1", "S", "id", id_str.c_str())); |
| 965 EXPECT_TRUE(FindNamePhaseKeyValue("name1", "T", "id", id_str.c_str())); |
940 EXPECT_TRUE(FindNamePhaseKeyValue("name1", "F", "id", id_str.c_str())); | 966 EXPECT_TRUE(FindNamePhaseKeyValue("name1", "F", "id", id_str.c_str())); |
941 EXPECT_TRUE(FindNamePhaseKeyValue("name3", "S", "id", "0")); | 967 EXPECT_TRUE(FindNamePhaseKeyValue("name3", "S", "id", "0")); |
942 | 968 |
943 // BEGIN events should not have id | 969 // BEGIN events should not have id |
944 EXPECT_FALSE(FindNamePhaseKeyValue("name2", "B", "id", "0")); | 970 EXPECT_FALSE(FindNamePhaseKeyValue("name2", "B", "id", "0")); |
945 } | 971 } |
946 | 972 |
947 // Test Start/Finish events | 973 // Test ASYNC_BEGIN/END events |
948 TEST_F(TraceEventTestFixture, StartFinishPointerMangling) { | 974 TEST_F(TraceEventTestFixture, AsyncBeginEndPointerMangling) { |
949 ManualTestSetUp(); | 975 ManualTestSetUp(); |
950 | 976 |
951 void* ptr = this; | 977 void* ptr = this; |
952 | 978 |
953 TraceLog::GetInstance()->SetProcessID(100); | 979 TraceLog::GetInstance()->SetProcessID(100); |
954 TraceLog::GetInstance()->SetEnabled(true); | 980 TraceLog::GetInstance()->SetEnabled(true); |
955 TRACE_EVENT_START0( "cat", "name1", ptr); | 981 TRACE_EVENT_ASYNC_BEGIN0( "cat", "name1", ptr); |
956 TRACE_EVENT_START0( "cat", "name2", ptr); | 982 TRACE_EVENT_ASYNC_BEGIN0( "cat", "name2", ptr); |
957 TraceLog::GetInstance()->SetEnabled(false); | 983 TraceLog::GetInstance()->SetEnabled(false); |
958 | 984 |
959 TraceLog::GetInstance()->SetProcessID(200); | 985 TraceLog::GetInstance()->SetProcessID(200); |
960 TraceLog::GetInstance()->SetEnabled(true); | 986 TraceLog::GetInstance()->SetEnabled(true); |
961 TRACE_EVENT_FINISH0( "cat", "name1", ptr); | 987 TRACE_EVENT_ASYNC_END0( "cat", "name1", ptr); |
962 TraceLog::GetInstance()->SetEnabled(false); | 988 TraceLog::GetInstance()->SetEnabled(false); |
963 | 989 |
964 DictionaryValue* start = FindNamePhase("name1", "S"); | 990 DictionaryValue* async_begin = FindNamePhase("name1", "S"); |
965 DictionaryValue* start2 = FindNamePhase("name2", "S"); | 991 DictionaryValue* async_begin2 = FindNamePhase("name2", "S"); |
966 DictionaryValue* finish = FindNamePhase("name1", "F"); | 992 DictionaryValue* async_end = FindNamePhase("name1", "F"); |
967 EXPECT_TRUE(start); | 993 EXPECT_TRUE(async_begin); |
968 EXPECT_TRUE(start2); | 994 EXPECT_TRUE(async_begin2); |
969 EXPECT_TRUE(finish); | 995 EXPECT_TRUE(async_end); |
970 | 996 |
971 Value* value = NULL; | 997 Value* value = NULL; |
972 std::string start_id_str; | 998 std::string async_begin_id_str; |
973 std::string start2_id_str; | 999 std::string async_begin2_id_str; |
974 std::string finish_id_str; | 1000 std::string async_end_id_str; |
975 ASSERT_TRUE(start->Get("id", &value)); | 1001 ASSERT_TRUE(async_begin->Get("id", &value)); |
976 ASSERT_TRUE(value->GetAsString(&start_id_str)); | 1002 ASSERT_TRUE(value->GetAsString(&async_begin_id_str)); |
977 ASSERT_TRUE(start2->Get("id", &value)); | 1003 ASSERT_TRUE(async_begin2->Get("id", &value)); |
978 ASSERT_TRUE(value->GetAsString(&start2_id_str)); | 1004 ASSERT_TRUE(value->GetAsString(&async_begin2_id_str)); |
979 ASSERT_TRUE(finish->Get("id", &value)); | 1005 ASSERT_TRUE(async_end->Get("id", &value)); |
980 ASSERT_TRUE(value->GetAsString(&finish_id_str)); | 1006 ASSERT_TRUE(value->GetAsString(&async_end_id_str)); |
981 | 1007 |
982 EXPECT_STREQ(start_id_str.c_str(), start2_id_str.c_str()); | 1008 EXPECT_STREQ(async_begin_id_str.c_str(), async_begin2_id_str.c_str()); |
983 EXPECT_STRNE(start_id_str.c_str(), finish_id_str.c_str()); | 1009 EXPECT_STRNE(async_begin_id_str.c_str(), async_end_id_str.c_str()); |
984 } | 1010 } |
985 | 1011 |
986 // Test that static strings are not copied. | 1012 // Test that static strings are not copied. |
987 TEST_F(TraceEventTestFixture, StaticStringVsString) { | 1013 TEST_F(TraceEventTestFixture, StaticStringVsString) { |
988 ManualTestSetUp(); | 1014 ManualTestSetUp(); |
989 TraceLog* tracer = TraceLog::GetInstance(); | 1015 TraceLog* tracer = TraceLog::GetInstance(); |
990 // Make sure old events are flushed: | 1016 // Make sure old events are flushed: |
991 tracer->SetEnabled(false); | 1017 tracer->SetEnabled(false); |
992 EXPECT_EQ(0u, tracer->GetEventsSize()); | 1018 EXPECT_EQ(0u, tracer->GetEventsSize()); |
993 | 1019 |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 Clear(); | 1372 Clear(); |
1347 | 1373 |
1348 trace_buffer_.Start(); | 1374 trace_buffer_.Start(); |
1349 trace_buffer_.AddFragment("bla1,bla2,bla3,bla4"); | 1375 trace_buffer_.AddFragment("bla1,bla2,bla3,bla4"); |
1350 trace_buffer_.Finish(); | 1376 trace_buffer_.Finish(); |
1351 EXPECT_STREQ(json_output_.json_output.c_str(), "[bla1,bla2,bla3,bla4]"); | 1377 EXPECT_STREQ(json_output_.json_output.c_str(), "[bla1,bla2,bla3,bla4]"); |
1352 } | 1378 } |
1353 | 1379 |
1354 } // namespace debug | 1380 } // namespace debug |
1355 } // namespace base | 1381 } // namespace base |
OLD | NEW |