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 <math.h> | 5 #include <math.h> |
6 #include <cstdlib> | 6 #include <cstdlib> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 2278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2289 const std::string& category, | 2289 const std::string& category, |
2290 const std::string& name) { | 2290 const std::string& name) { |
2291 EXPECT_EQ(phase, collected_events_phases_[i]); | 2291 EXPECT_EQ(phase, collected_events_phases_[i]); |
2292 EXPECT_EQ(category, collected_events_categories_[i]); | 2292 EXPECT_EQ(category, collected_events_categories_[i]); |
2293 EXPECT_EQ(name, collected_events_names_[i]); | 2293 EXPECT_EQ(name, collected_events_names_[i]); |
2294 } | 2294 } |
2295 | 2295 |
2296 std::vector<std::string> collected_events_categories_; | 2296 std::vector<std::string> collected_events_categories_; |
2297 std::vector<std::string> collected_events_names_; | 2297 std::vector<std::string> collected_events_names_; |
2298 std::vector<unsigned char> collected_events_phases_; | 2298 std::vector<unsigned char> collected_events_phases_; |
2299 std::vector<TimeTicks> collected_events_timestamps_; | 2299 std::vector<TraceTicks> collected_events_timestamps_; |
2300 | 2300 |
2301 static TraceEventCallbackTest* s_instance; | 2301 static TraceEventCallbackTest* s_instance; |
2302 static void Callback(TimeTicks timestamp, | 2302 static void Callback(TraceTicks timestamp, |
2303 char phase, | 2303 char phase, |
2304 const unsigned char* category_group_enabled, | 2304 const unsigned char* category_group_enabled, |
2305 const char* name, | 2305 const char* name, |
2306 unsigned long long id, | 2306 unsigned long long id, |
2307 int num_args, | 2307 int num_args, |
2308 const char* const arg_names[], | 2308 const char* const arg_names[], |
2309 const unsigned char arg_types[], | 2309 const unsigned char arg_types[], |
2310 const unsigned long long arg_values[], | 2310 const unsigned long long arg_values[], |
2311 unsigned char flags) { | 2311 unsigned char flags) { |
2312 s_instance->collected_events_phases_.push_back(phase); | 2312 s_instance->collected_events_phases_.push_back(phase); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2491 | 2491 |
2492 TEST_F(TraceEventTestFixture, TraceBufferVectorReportFull) { | 2492 TEST_F(TraceEventTestFixture, TraceBufferVectorReportFull) { |
2493 TraceLog* trace_log = TraceLog::GetInstance(); | 2493 TraceLog* trace_log = TraceLog::GetInstance(); |
2494 trace_log->SetEnabled(CategoryFilter("*"), | 2494 trace_log->SetEnabled(CategoryFilter("*"), |
2495 TraceLog::RECORDING_MODE, | 2495 TraceLog::RECORDING_MODE, |
2496 TraceOptions()); | 2496 TraceOptions()); |
2497 trace_log->logged_events_.reset( | 2497 trace_log->logged_events_.reset( |
2498 trace_log->CreateTraceBufferVectorOfSize(100)); | 2498 trace_log->CreateTraceBufferVectorOfSize(100)); |
2499 do { | 2499 do { |
2500 TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( | 2500 TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( |
2501 "all", "with_timestamp", 0, 0, | 2501 "all", "with_timestamp", 0, 0, TraceTicks::Now().ToInternalValue()); |
2502 TimeTicks::NowFromSystemTraceTime().ToInternalValue()); | |
2503 TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0( | 2502 TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0( |
2504 "all", "with_timestamp", 0, 0, | 2503 "all", "with_timestamp", 0, 0, TraceTicks::Now().ToInternalValue()); |
2505 TimeTicks::NowFromSystemTraceTime().ToInternalValue()); | |
2506 } while (!trace_log->BufferIsFull()); | 2504 } while (!trace_log->BufferIsFull()); |
2507 | 2505 |
2508 EndTraceAndFlush(); | 2506 EndTraceAndFlush(); |
2509 | 2507 |
2510 const DictionaryValue* trace_full_metadata = NULL; | 2508 const DictionaryValue* trace_full_metadata = NULL; |
2511 | 2509 |
2512 trace_full_metadata = FindTraceEntry(trace_parsed_, | 2510 trace_full_metadata = FindTraceEntry(trace_parsed_, |
2513 "overflowed_at_ts"); | 2511 "overflowed_at_ts"); |
2514 std::string phase; | 2512 std::string phase; |
2515 double buffer_limit_reached_timestamp = 0; | 2513 double buffer_limit_reached_timestamp = 0; |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2868 TRACE_EVENT0("b", "duration"); | 2866 TRACE_EVENT0("b", "duration"); |
2869 } | 2867 } |
2870 | 2868 |
2871 EndTraceAndFlush(); | 2869 EndTraceAndFlush(); |
2872 logging::SetLogMessageHandler(old_log_message_handler); | 2870 logging::SetLogMessageHandler(old_log_message_handler); |
2873 } | 2871 } |
2874 | 2872 |
2875 TEST_F(TraceEventTestFixture, TimeOffset) { | 2873 TEST_F(TraceEventTestFixture, TimeOffset) { |
2876 BeginTrace(); | 2874 BeginTrace(); |
2877 // Let TraceLog timer start from 0. | 2875 // Let TraceLog timer start from 0. |
2878 TimeDelta time_offset = TimeTicks::NowFromSystemTraceTime() - TimeTicks(); | 2876 TimeDelta time_offset = TraceTicks::Now() - TraceTicks(); |
2879 TraceLog::GetInstance()->SetTimeOffset(time_offset); | 2877 TraceLog::GetInstance()->SetTimeOffset(time_offset); |
2880 | 2878 |
2881 { | 2879 { |
2882 TRACE_EVENT0("all", "duration1"); | 2880 TRACE_EVENT0("all", "duration1"); |
2883 TRACE_EVENT0("all", "duration2"); | 2881 TRACE_EVENT0("all", "duration2"); |
2884 } | 2882 } |
2885 TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( | 2883 TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( |
2886 "all", "with_timestamp", 0, 0, | 2884 "all", "with_timestamp", 0, 0, TraceTicks::Now().ToInternalValue()); |
2887 TimeTicks::NowFromSystemTraceTime().ToInternalValue()); | |
2888 TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0( | 2885 TRACE_EVENT_END_WITH_ID_TID_AND_TIMESTAMP0( |
2889 "all", "with_timestamp", 0, 0, | 2886 "all", "with_timestamp", 0, 0, TraceTicks::Now().ToInternalValue()); |
2890 TimeTicks::NowFromSystemTraceTime().ToInternalValue()); | |
2891 | 2887 |
2892 EndTraceAndFlush(); | 2888 EndTraceAndFlush(); |
2893 DropTracedMetadataRecords(); | 2889 DropTracedMetadataRecords(); |
2894 | 2890 |
2895 double end_time = static_cast<double>( | 2891 double end_time = static_cast<double>( |
2896 (TimeTicks::NowFromSystemTraceTime() - time_offset).ToInternalValue()); | 2892 (TraceTicks::Now() - time_offset).ToInternalValue()); |
2897 double last_timestamp = 0; | 2893 double last_timestamp = 0; |
2898 for (size_t i = 0; i < trace_parsed_.GetSize(); ++i) { | 2894 for (size_t i = 0; i < trace_parsed_.GetSize(); ++i) { |
2899 const DictionaryValue* item; | 2895 const DictionaryValue* item; |
2900 EXPECT_TRUE(trace_parsed_.GetDictionary(i, &item)); | 2896 EXPECT_TRUE(trace_parsed_.GetDictionary(i, &item)); |
2901 double timestamp; | 2897 double timestamp; |
2902 EXPECT_TRUE(item->GetDouble("ts", ×tamp)); | 2898 EXPECT_TRUE(item->GetDouble("ts", ×tamp)); |
2903 EXPECT_GE(timestamp, last_timestamp); | 2899 EXPECT_GE(timestamp, last_timestamp); |
2904 EXPECT_LE(timestamp, end_time); | 2900 EXPECT_LE(timestamp, end_time); |
2905 last_timestamp = timestamp; | 2901 last_timestamp = timestamp; |
2906 } | 2902 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2944 } | 2940 } |
2945 | 2941 |
2946 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) { | 2942 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) { |
2947 const char config[] = "DELAY(test.Delay;16;oneshot)"; | 2943 const char config[] = "DELAY(test.Delay;16;oneshot)"; |
2948 CategoryFilter filter(config); | 2944 CategoryFilter filter(config); |
2949 EXPECT_EQ(config, filter.ToString()); | 2945 EXPECT_EQ(config, filter.ToString()); |
2950 } | 2946 } |
2951 | 2947 |
2952 } // namespace trace_event | 2948 } // namespace trace_event |
2953 } // namespace base | 2949 } // namespace base |
OLD | NEW |