| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/trace_event/trace_event_etw_export_win.h" | 5 #include "base/trace_event/trace_event_etw_export_win.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 void TraceEventETWExport::AddCompleteEndEvent(const char* name) { | 341 void TraceEventETWExport::AddCompleteEndEvent(const char* name) { |
| 342 auto* instance = GetInstance(); | 342 auto* instance = GetInstance(); |
| 343 if (!instance || !instance->etw_export_enabled_ || !EventEnabledChromeEvent()) | 343 if (!instance || !instance->etw_export_enabled_ || !EventEnabledChromeEvent()) |
| 344 return; | 344 return; |
| 345 | 345 |
| 346 EventWriteChromeEvent(name, "Complete End", "", "", "", "", "", ""); | 346 EventWriteChromeEvent(name, "Complete End", "", "", "", "", "", ""); |
| 347 } | 347 } |
| 348 | 348 |
| 349 // static | 349 // static |
| 350 bool TraceEventETWExport::IsCategoryGroupEnabled( | 350 bool TraceEventETWExport::IsCategoryGroupEnabled( |
| 351 const char* category_group_name) { | 351 StringPiece category_group_name) { |
| 352 DCHECK(category_group_name); | 352 DCHECK(!category_group_name.empty()); |
| 353 auto* instance = GetInstance(); | 353 auto* instance = GetInstance(); |
| 354 if (instance == nullptr) | 354 if (instance == nullptr) |
| 355 return false; | 355 return false; |
| 356 | 356 |
| 357 if (!instance->IsETWExportEnabled()) | 357 if (!instance->IsETWExportEnabled()) |
| 358 return false; | 358 return false; |
| 359 | 359 |
| 360 CStringTokenizer category_group_tokens( | 360 CStringTokenizer category_group_tokens(category_group_name.begin(), |
| 361 category_group_name, category_group_name + strlen(category_group_name), | 361 category_group_name.end(), ","); |
| 362 ","); | |
| 363 while (category_group_tokens.GetNext()) { | 362 while (category_group_tokens.GetNext()) { |
| 364 std::string category_group_token = category_group_tokens.token(); | 363 StringPiece category_group_token = category_group_tokens.token_piece(); |
| 365 if (instance->IsCategoryEnabled(category_group_token.c_str())) { | 364 if (instance->IsCategoryEnabled(category_group_token)) { |
| 366 return true; | 365 return true; |
| 367 } | 366 } |
| 368 } | 367 } |
| 369 return false; | 368 return false; |
| 370 } | 369 } |
| 371 | 370 |
| 372 bool TraceEventETWExport::UpdateEnabledCategories() { | 371 bool TraceEventETWExport::UpdateEnabledCategories() { |
| 373 if (etw_match_any_keyword_ == CHROME_Context.MatchAnyKeyword) | 372 if (etw_match_any_keyword_ == CHROME_Context.MatchAnyKeyword) |
| 374 return false; | 373 return false; |
| 375 | 374 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 399 } | 398 } |
| 400 | 399 |
| 401 DCHECK_EQ(kNumberOfCategories, categories_status_.size()); | 400 DCHECK_EQ(kNumberOfCategories, categories_status_.size()); |
| 402 | 401 |
| 403 // Update the categories in TraceLog. | 402 // Update the categories in TraceLog. |
| 404 TraceLog::GetInstance()->UpdateETWCategoryGroupEnabledFlags(); | 403 TraceLog::GetInstance()->UpdateETWCategoryGroupEnabledFlags(); |
| 405 | 404 |
| 406 return true; | 405 return true; |
| 407 } | 406 } |
| 408 | 407 |
| 409 bool TraceEventETWExport::IsCategoryEnabled(const char* category_name) const { | 408 bool TraceEventETWExport::IsCategoryEnabled(StringPiece category_name) const { |
| 410 DCHECK_EQ(kNumberOfCategories, categories_status_.size()); | 409 DCHECK_EQ(kNumberOfCategories, categories_status_.size()); |
| 411 // Try to find the category and return its status if found | 410 // Try to find the category and return its status if found |
| 412 auto it = categories_status_.find(category_name); | 411 auto it = categories_status_.find(category_name); |
| 413 if (it != categories_status_.end()) | 412 if (it != categories_status_.end()) |
| 414 return it->second; | 413 return it->second; |
| 415 | 414 |
| 416 // Otherwise return the corresponding default status by first checking if the | 415 // Otherwise return the corresponding default status by first checking if the |
| 417 // category is disabled by default. | 416 // category is disabled by default. |
| 418 if (StringPiece(category_name).starts_with("disabled-by-default")) { | 417 if (category_name.starts_with("disabled-by-default")) { |
| 419 DCHECK(categories_status_.find(kDisabledOtherEventsGroupName) != | 418 DCHECK(categories_status_.find(kDisabledOtherEventsGroupName) != |
| 420 categories_status_.end()); | 419 categories_status_.end()); |
| 421 return categories_status_.find(kDisabledOtherEventsGroupName)->second; | 420 return categories_status_.find(kDisabledOtherEventsGroupName)->second; |
| 422 } else { | 421 } else { |
| 423 DCHECK(categories_status_.find(kOtherEventsGroupName) != | 422 DCHECK(categories_status_.find(kOtherEventsGroupName) != |
| 424 categories_status_.end()); | 423 categories_status_.end()); |
| 425 return categories_status_.find(kOtherEventsGroupName)->second; | 424 return categories_status_.find(kOtherEventsGroupName)->second; |
| 426 } | 425 } |
| 427 } | 426 } |
| 428 | 427 |
| 429 // static | 428 // static |
| 430 void TraceEventETWExport::UpdateETWKeyword() { | 429 void TraceEventETWExport::UpdateETWKeyword() { |
| 431 if (!IsETWExportEnabled()) | 430 if (!IsETWExportEnabled()) |
| 432 return; | 431 return; |
| 433 auto* instance = GetInstance(); | 432 auto* instance = GetInstance(); |
| 434 DCHECK(instance); | 433 DCHECK(instance); |
| 435 instance->UpdateEnabledCategories(); | 434 instance->UpdateEnabledCategories(); |
| 436 } | 435 } |
| 437 } // namespace trace_event | 436 } // namespace trace_event |
| 438 } // namespace base | 437 } // namespace base |
| OLD | NEW |