| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <strstream> | 7 #include <strstream> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/debug/trace_event.h" | |
| 13 #include "base/debug/trace_event_win.h" | |
| 14 #include "base/win/event_trace_consumer.h" | 12 #include "base/win/event_trace_consumer.h" |
| 15 #include "base/win/event_trace_controller.h" | 13 #include "base/win/event_trace_controller.h" |
| 16 #include "base/win/event_trace_provider.h" | |
| 17 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include <initguid.h> // NOLINT - must be last include. | 17 #include <initguid.h> // NOLINT - must be last include. |
| 21 | 18 |
| 22 namespace base { | 19 namespace base { |
| 23 namespace debug { | 20 namespace debug { |
| 24 | 21 |
| 25 namespace { | 22 namespace { |
| 26 | 23 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 event->MofLength, | 77 event->MofLength, |
| 81 event->MofData); | 78 event->MofData); |
| 82 } | 79 } |
| 83 | 80 |
| 84 private: | 81 private: |
| 85 static TestEventConsumer* current_; | 82 static TestEventConsumer* current_; |
| 86 }; | 83 }; |
| 87 | 84 |
| 88 TestEventConsumer* TestEventConsumer::current_ = NULL; | 85 TestEventConsumer* TestEventConsumer::current_ = NULL; |
| 89 | 86 |
| 90 class TraceEventWinTest: public testing::Test { | 87 class TraceEventTest: public testing::Test { |
| 91 public: | 88 public: |
| 92 TraceEventWinTest() { | 89 TraceEventTest() { |
| 93 } | 90 } |
| 94 | 91 |
| 95 void SetUp() { | 92 void SetUp() { |
| 96 bool is_xp = win::GetVersion() < base::win::VERSION_VISTA; | 93 bool is_xp = win::GetVersion() < base::win::VERSION_VISTA; |
| 97 | 94 |
| 98 if (is_xp) { | 95 if (is_xp) { |
| 99 // Tear down any dangling session from an earlier failing test. | 96 // Tear down any dangling session from an earlier failing test. |
| 100 EtwTraceProperties ignore; | 97 EtwTraceProperties ignore; |
| 101 EtwTraceController::Stop(kTestSessionName, &ignore); | 98 EtwTraceController::Stop(kTestSessionName, &ignore); |
| 102 } | 99 } |
| 103 | 100 |
| 104 // Resurrect and initialize the TraceLog singleton instance. | 101 // Resurrect and initialize the TraceLog singleton instance. |
| 105 // On Vista and better, we need the provider registered before we | 102 // On Vista and better, we need the provider registered before we |
| 106 // start the private, in-proc session, but on XP we need the global | 103 // start the private, in-proc session, but on XP we need the global |
| 107 // session created and the provider enabled before we register our | 104 // session created and the provider enabled before we register our |
| 108 // provider. | 105 // provider. |
| 109 TraceEventETWProvider* tracelog = NULL; | 106 TraceLog* tracelog = NULL; |
| 110 if (!is_xp) { | 107 if (!is_xp) { |
| 111 TraceEventETWProvider::Resurrect(); | 108 TraceLog::Resurrect(); |
| 112 tracelog = TraceEventETWProvider::GetInstance(); | 109 tracelog = TraceLog::GetInstance(); |
| 113 ASSERT_TRUE(tracelog != NULL); | 110 ASSERT_TRUE(tracelog != NULL); |
| 114 ASSERT_FALSE(tracelog->IsTracing()); | 111 ASSERT_FALSE(tracelog->IsTracing()); |
| 115 } | 112 } |
| 116 | 113 |
| 117 // Create the log file. | 114 // Create the log file. |
| 118 ASSERT_TRUE(file_util::CreateTemporaryFile(&log_file_)); | 115 ASSERT_TRUE(file_util::CreateTemporaryFile(&log_file_)); |
| 119 | 116 |
| 120 // Create a private log session on the file. | 117 // Create a private log session on the file. |
| 121 EtwTraceProperties prop; | 118 EtwTraceProperties prop; |
| 122 ASSERT_HRESULT_SUCCEEDED(prop.SetLoggerFileName(log_file_.value().c_str())); | 119 ASSERT_HRESULT_SUCCEEDED(prop.SetLoggerFileName(log_file_.value().c_str())); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 137 p.FlushTimer = 1; // 1 second flush lag. | 134 p.FlushTimer = 1; // 1 second flush lag. |
| 138 ASSERT_HRESULT_SUCCEEDED(controller_.Start(kTestSessionName, &prop)); | 135 ASSERT_HRESULT_SUCCEEDED(controller_.Start(kTestSessionName, &prop)); |
| 139 | 136 |
| 140 // Enable the TraceLog provider GUID. | 137 // Enable the TraceLog provider GUID. |
| 141 ASSERT_HRESULT_SUCCEEDED( | 138 ASSERT_HRESULT_SUCCEEDED( |
| 142 controller_.EnableProvider(kChromeTraceProviderName, | 139 controller_.EnableProvider(kChromeTraceProviderName, |
| 143 TRACE_LEVEL_INFORMATION, | 140 TRACE_LEVEL_INFORMATION, |
| 144 0)); | 141 0)); |
| 145 | 142 |
| 146 if (is_xp) { | 143 if (is_xp) { |
| 147 TraceEventETWProvider::Resurrect(); | 144 TraceLog::Resurrect(); |
| 148 tracelog = TraceEventETWProvider::GetInstance(); | 145 tracelog = TraceLog::GetInstance(); |
| 149 } | 146 } |
| 150 ASSERT_TRUE(tracelog != NULL); | 147 ASSERT_TRUE(tracelog != NULL); |
| 151 EXPECT_TRUE(tracelog->IsTracing()); | 148 EXPECT_TRUE(tracelog->IsTracing()); |
| 152 } | 149 } |
| 153 | 150 |
| 154 void TearDown() { | 151 void TearDown() { |
| 155 EtwTraceProperties prop; | 152 EtwTraceProperties prop; |
| 156 if (controller_.session() != 0) | 153 if (controller_.session() != 0) |
| 157 EXPECT_HRESULT_SUCCEEDED(controller_.Stop(&prop)); | 154 EXPECT_HRESULT_SUCCEEDED(controller_.Stop(&prop)); |
| 158 | 155 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // We want our singleton torn down after each test. | 197 // We want our singleton torn down after each test. |
| 201 ShadowingAtExitManager at_exit_manager_; | 198 ShadowingAtExitManager at_exit_manager_; |
| 202 EtwTraceController controller_; | 199 EtwTraceController controller_; |
| 203 FilePath log_file_; | 200 FilePath log_file_; |
| 204 TestEventConsumer consumer_; | 201 TestEventConsumer consumer_; |
| 205 }; | 202 }; |
| 206 | 203 |
| 207 } // namespace | 204 } // namespace |
| 208 | 205 |
| 209 | 206 |
| 210 TEST_F(TraceEventWinTest, TraceLog) { | 207 TEST_F(TraceEventTest, TraceLog) { |
| 211 ExpectPlayLog(); | 208 ExpectPlayLog(); |
| 212 | 209 |
| 213 // The events should arrive in the same sequence as the expects. | 210 // The events should arrive in the same sequence as the expects. |
| 214 InSequence in_sequence; | 211 InSequence in_sequence; |
| 215 | 212 |
| 216 // Full argument version, passing lengths explicitly. | 213 // Full argument version, passing lengths explicitly. |
| 217 TraceEventETWProvider::Trace(kName, | 214 TraceLog::Trace(kName, |
| 218 strlen(kName), | 215 strlen(kName), |
| 219 base::debug::TRACE_EVENT_PHASE_BEGIN, | 216 TraceLog::EVENT_BEGIN, |
| 220 kId, | 217 kId, |
| 221 kExtra, | 218 kExtra, |
| 222 strlen(kExtra)); | 219 strlen(kExtra)); |
| 223 | 220 |
| 224 ExpectEvent(kTraceEventClass32, | 221 ExpectEvent(kTraceEventClass32, |
| 225 kTraceEventTypeBegin, | 222 kTraceEventTypeBegin, |
| 226 kName, strlen(kName), | 223 kName, strlen(kName), |
| 227 kId, | 224 kId, |
| 228 kExtra, strlen(kExtra)); | 225 kExtra, strlen(kExtra)); |
| 229 | 226 |
| 230 // Const char* version. | 227 // Const char* version. |
| 231 TraceEventETWProvider::Trace(static_cast<const char*>(kName), | 228 TraceLog::Trace(static_cast<const char*>(kName), |
| 232 base::debug::TRACE_EVENT_PHASE_END, | 229 TraceLog::EVENT_END, |
| 233 kId, | 230 kId, |
| 234 static_cast<const char*>(kExtra)); | 231 static_cast<const char*>(kExtra)); |
| 235 | 232 |
| 236 ExpectEvent(kTraceEventClass32, | 233 ExpectEvent(kTraceEventClass32, |
| 237 kTraceEventTypeEnd, | 234 kTraceEventTypeEnd, |
| 238 kName, strlen(kName), | 235 kName, strlen(kName), |
| 239 kId, | 236 kId, |
| 240 kExtra, strlen(kExtra)); | 237 kExtra, strlen(kExtra)); |
| 241 | 238 |
| 242 // std::string extra version. | 239 // std::string extra version. |
| 243 TraceEventETWProvider::Trace(static_cast<const char*>(kName), | 240 TraceLog::Trace(static_cast<const char*>(kName), |
| 244 base::debug::TRACE_EVENT_PHASE_INSTANT, | 241 TraceLog::EVENT_INSTANT, |
| 245 kId, | 242 kId, |
| 246 std::string(kExtra)); | 243 std::string(kExtra)); |
| 247 | 244 |
| 248 ExpectEvent(kTraceEventClass32, | 245 ExpectEvent(kTraceEventClass32, |
| 249 kTraceEventTypeInstant, | 246 kTraceEventTypeInstant, |
| 250 kName, strlen(kName), | 247 kName, strlen(kName), |
| 251 kId, | 248 kId, |
| 252 kExtra, strlen(kExtra)); | 249 kExtra, strlen(kExtra)); |
| 253 | 250 |
| 254 | 251 |
| 255 // Test for sanity on NULL inputs. | 252 // Test for sanity on NULL inputs. |
| 256 TraceEventETWProvider::Trace(NULL, | 253 TraceLog::Trace(NULL, |
| 257 0, | 254 0, |
| 258 base::debug::TRACE_EVENT_PHASE_BEGIN, | 255 TraceLog::EVENT_BEGIN, |
| 259 kId, | 256 kId, |
| 260 NULL, | 257 NULL, |
| 261 0); | 258 0); |
| 262 | 259 |
| 263 ExpectEvent(kTraceEventClass32, | 260 ExpectEvent(kTraceEventClass32, |
| 264 kTraceEventTypeBegin, | 261 kTraceEventTypeBegin, |
| 265 kEmpty, 0, | 262 kEmpty, 0, |
| 266 kId, | 263 kId, |
| 267 kEmpty, 0); | 264 kEmpty, 0); |
| 268 | 265 |
| 269 TraceEventETWProvider::Trace(NULL, | 266 TraceLog::Trace(NULL, |
| 270 -1, | 267 -1, |
| 271 base::debug::TRACE_EVENT_PHASE_END, | 268 TraceLog::EVENT_END, |
| 272 kId, | 269 kId, |
| 273 NULL, | 270 NULL, |
| 274 -1); | 271 -1); |
| 275 | 272 |
| 276 ExpectEvent(kTraceEventClass32, | 273 ExpectEvent(kTraceEventClass32, |
| 277 kTraceEventTypeEnd, | 274 kTraceEventTypeEnd, |
| 278 kEmpty, 0, | 275 kEmpty, 0, |
| 279 kId, | 276 kId, |
| 280 kEmpty, 0); | 277 kEmpty, 0); |
| 281 | 278 |
| 282 PlayLog(); | 279 PlayLog(); |
| 283 } | 280 } |
| 284 | 281 |
| 285 TEST_F(TraceEventWinTest, Macros) { | 282 TEST_F(TraceEventTest, Macros) { |
| 286 ExpectPlayLog(); | 283 ExpectPlayLog(); |
| 287 | 284 |
| 288 // The events should arrive in the same sequence as the expects. | 285 // The events should arrive in the same sequence as the expects. |
| 289 InSequence in_sequence; | 286 InSequence in_sequence; |
| 290 | 287 |
| 291 TRACE_EVENT_BEGIN_ETW(kName, kId, kExtra); | 288 TRACE_EVENT_BEGIN(kName, kId, kExtra); |
| 292 ExpectEvent(kTraceEventClass32, | 289 ExpectEvent(kTraceEventClass32, |
| 293 kTraceEventTypeBegin, | 290 kTraceEventTypeBegin, |
| 294 kName, strlen(kName), | 291 kName, strlen(kName), |
| 295 kId, | 292 kId, |
| 296 kExtra, strlen(kExtra)); | 293 kExtra, strlen(kExtra)); |
| 297 | 294 |
| 298 TRACE_EVENT_END_ETW(kName, kId, kExtra); | 295 TRACE_EVENT_END(kName, kId, kExtra); |
| 299 ExpectEvent(kTraceEventClass32, | 296 ExpectEvent(kTraceEventClass32, |
| 300 kTraceEventTypeEnd, | 297 kTraceEventTypeEnd, |
| 301 kName, strlen(kName), | 298 kName, strlen(kName), |
| 302 kId, | 299 kId, |
| 303 kExtra, strlen(kExtra)); | 300 kExtra, strlen(kExtra)); |
| 304 | 301 |
| 305 TRACE_EVENT_INSTANT_ETW(kName, kId, kExtra); | 302 TRACE_EVENT_INSTANT(kName, kId, kExtra); |
| 306 ExpectEvent(kTraceEventClass32, | 303 ExpectEvent(kTraceEventClass32, |
| 307 kTraceEventTypeInstant, | 304 kTraceEventTypeInstant, |
| 308 kName, strlen(kName), | 305 kName, strlen(kName), |
| 309 kId, | 306 kId, |
| 310 kExtra, strlen(kExtra)); | 307 kExtra, strlen(kExtra)); |
| 311 | 308 |
| 312 PlayLog(); | 309 PlayLog(); |
| 313 } | 310 } |
| 314 | 311 |
| 315 } // namespace debug | 312 } // namespace debug |
| 316 } // namespace base | 313 } // namespace base |
| OLD | NEW |