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_impl.h" | 5 #include "base/debug/trace_event_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
963 : bucket(bucket), | 963 : bucket(bucket), |
964 bucket_name(name), | 964 bucket_name(name), |
965 callback(callback) { | 965 callback(callback) { |
966 } | 966 } |
967 | 967 |
968 TraceBucketData::~TraceBucketData() { | 968 TraceBucketData::~TraceBucketData() { |
969 } | 969 } |
970 | 970 |
971 //////////////////////////////////////////////////////////////////////////////// | 971 //////////////////////////////////////////////////////////////////////////////// |
972 // | 972 // |
973 // TraceOptions | |
974 // | |
975 //////////////////////////////////////////////////////////////////////////////// | |
976 | |
977 TraceOptions::TraceOptions(StringPiece options) | |
978 : record_mode(RECORD_UNTIL_FULL), enable_sampling(false) { | |
979 std::vector<std::string> split; | |
980 std::vector<std::string>::iterator iter; | |
981 | |
982 base::SplitString(options.as_string(), ',', &split); | |
983 for (iter = split.begin(); iter != split.end(); ++iter) { | |
984 if (*iter == kRecordUntilFull) { | |
985 record_mode = RECORD_UNTIL_FULL; | |
986 } else if (*iter == kRecordContinuously) { | |
987 record_mode = RECORD_CONTINUOUSLY; | |
988 } else if (*iter == kTraceToConsole) { | |
989 record_mode = ECHO_TO_CONSOLE; | |
990 } else if (*iter == kEnableSampling) { | |
991 enable_sampling = true; | |
992 } | |
993 } | |
994 } | |
995 | |
996 std::string TraceOptions::ToString() const { | |
997 std::string ret; | |
998 switch (record_mode) { | |
999 case RECORD_UNTIL_FULL: | |
1000 ret = kRecordUntilFull; | |
1001 break; | |
1002 case RECORD_CONTINUOUSLY: | |
1003 ret = kRecordContinuously; | |
1004 break; | |
1005 case ECHO_TO_CONSOLE: | |
1006 ret = kTraceToConsole; | |
1007 break; | |
1008 default: | |
1009 NOTREACHED(); | |
1010 } | |
1011 return enable_sampling ? ret + "," + kEnableSampling : ret; | |
1012 } | |
1013 | |
1014 //////////////////////////////////////////////////////////////////////////////// | |
1015 // | |
973 // TraceLog | 1016 // TraceLog |
974 // | 1017 // |
975 //////////////////////////////////////////////////////////////////////////////// | 1018 //////////////////////////////////////////////////////////////////////////////// |
976 | 1019 |
977 class TraceLog::ThreadLocalEventBuffer | 1020 class TraceLog::ThreadLocalEventBuffer |
978 : public MessageLoop::DestructionObserver { | 1021 : public MessageLoop::DestructionObserver { |
979 public: | 1022 public: |
980 ThreadLocalEventBuffer(TraceLog* trace_log); | 1023 ThreadLocalEventBuffer(TraceLog* trace_log); |
981 virtual ~ThreadLocalEventBuffer(); | 1024 virtual ~ThreadLocalEventBuffer(); |
982 | 1025 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1168 switches::kTraceToConsole); | 1211 switches::kTraceToConsole); |
1169 if (filter.empty()) { | 1212 if (filter.empty()) { |
1170 filter = kEchoToConsoleCategoryFilter; | 1213 filter = kEchoToConsoleCategoryFilter; |
1171 } else { | 1214 } else { |
1172 filter.append(","); | 1215 filter.append(","); |
1173 filter.append(kEchoToConsoleCategoryFilter); | 1216 filter.append(kEchoToConsoleCategoryFilter); |
1174 } | 1217 } |
1175 | 1218 |
1176 LOG(ERROR) << "Start " << switches::kTraceToConsole | 1219 LOG(ERROR) << "Start " << switches::kTraceToConsole |
1177 << " with CategoryFilter '" << filter << "'."; | 1220 << " with CategoryFilter '" << filter << "'."; |
1178 SetEnabled(CategoryFilter(filter), RECORDING_MODE, ECHO_TO_CONSOLE); | 1221 SetEnabled(CategoryFilter(filter), |
1222 RECORDING_MODE, | |
1223 TraceOptions(TraceOptions::ECHO_TO_CONSOLE, false)); | |
1179 } | 1224 } |
1180 #endif | 1225 #endif |
1181 | 1226 |
1182 logged_events_.reset(CreateTraceBuffer()); | 1227 logged_events_.reset(CreateTraceBuffer()); |
1183 } | 1228 } |
1184 | 1229 |
1185 TraceLog::~TraceLog() { | 1230 TraceLog::~TraceLog() { |
1186 } | 1231 } |
1187 | 1232 |
1188 const unsigned char* TraceLog::GetCategoryGroupEnabled( | 1233 const unsigned char* TraceLog::GetCategoryGroupEnabled( |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1318 AutoLock lock(lock_); | 1363 AutoLock lock(lock_); |
1319 category_groups->push_back( | 1364 category_groups->push_back( |
1320 g_category_groups[g_category_trace_event_overhead]); | 1365 g_category_groups[g_category_trace_event_overhead]); |
1321 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index); | 1366 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index); |
1322 for (size_t i = g_num_builtin_categories; i < category_index; i++) | 1367 for (size_t i = g_num_builtin_categories; i < category_index; i++) |
1323 category_groups->push_back(g_category_groups[i]); | 1368 category_groups->push_back(g_category_groups[i]); |
1324 } | 1369 } |
1325 | 1370 |
1326 void TraceLog::SetEnabled(const CategoryFilter& category_filter, | 1371 void TraceLog::SetEnabled(const CategoryFilter& category_filter, |
1327 Mode mode, | 1372 Mode mode, |
1328 Options options) { | 1373 TraceOptions options) { |
1329 std::vector<EnabledStateObserver*> observer_list; | 1374 std::vector<EnabledStateObserver*> observer_list; |
1330 { | 1375 { |
1331 AutoLock lock(lock_); | 1376 AutoLock lock(lock_); |
1332 | 1377 |
1333 // Can't enable tracing when Flush() is in progress. | 1378 // Can't enable tracing when Flush() is in progress. |
1334 DCHECK(!flush_message_loop_proxy_.get()); | 1379 DCHECK(!flush_message_loop_proxy_.get()); |
1335 | 1380 |
1336 Options old_options = trace_options(); | 1381 InternalTraceOptions new_options = |
1382 GetInternalOptionsFromTraceOptions(options); | |
1383 | |
1384 InternalTraceOptions old_options = trace_options(); | |
1337 | 1385 |
1338 if (IsEnabled()) { | 1386 if (IsEnabled()) { |
1339 if (options != old_options) { | 1387 if (new_options != old_options) { |
1340 DLOG(ERROR) << "Attempting to re-enable tracing with a different " | 1388 DLOG(ERROR) << "Attempting to re-enable tracing with a different " |
1341 << "set of options."; | 1389 << "set of options."; |
1342 } | 1390 } |
1343 | 1391 |
1344 if (mode != mode_) { | 1392 if (mode != mode_) { |
1345 DLOG(ERROR) << "Attempting to re-enable tracing with a different mode."; | 1393 DLOG(ERROR) << "Attempting to re-enable tracing with a different mode."; |
1346 } | 1394 } |
1347 | 1395 |
1348 category_filter_.Merge(category_filter); | 1396 category_filter_.Merge(category_filter); |
1349 UpdateCategoryGroupEnabledFlags(); | 1397 UpdateCategoryGroupEnabledFlags(); |
1350 return; | 1398 return; |
1351 } | 1399 } |
1352 | 1400 |
1353 if (dispatching_to_observer_list_) { | 1401 if (dispatching_to_observer_list_) { |
1354 DLOG(ERROR) << | 1402 DLOG(ERROR) << |
1355 "Cannot manipulate TraceLog::Enabled state from an observer."; | 1403 "Cannot manipulate TraceLog::Enabled state from an observer."; |
1356 return; | 1404 return; |
1357 } | 1405 } |
1358 | 1406 |
1359 mode_ = mode; | 1407 mode_ = mode; |
1360 | 1408 |
1361 if (options != old_options) { | 1409 if (new_options != old_options) { |
1362 subtle::NoBarrier_Store(&trace_options_, options); | 1410 subtle::NoBarrier_Store(&trace_options_, new_options); |
1363 UseNextTraceBuffer(); | 1411 UseNextTraceBuffer(); |
1364 } | 1412 } |
1365 | 1413 |
1366 num_traces_recorded_++; | 1414 num_traces_recorded_++; |
1367 | 1415 |
1368 category_filter_ = CategoryFilter(category_filter); | 1416 category_filter_ = CategoryFilter(category_filter); |
1369 UpdateCategoryGroupEnabledFlags(); | 1417 UpdateCategoryGroupEnabledFlags(); |
1370 UpdateSyntheticDelaysFromCategoryFilter(); | 1418 UpdateSyntheticDelaysFromCategoryFilter(); |
1371 | 1419 |
1372 if (options & ENABLE_SAMPLING) { | 1420 if (new_options & ENABLE_SAMPLING) { |
1373 sampling_thread_.reset(new TraceSamplingThread); | 1421 sampling_thread_.reset(new TraceSamplingThread); |
1374 sampling_thread_->RegisterSampleBucket( | 1422 sampling_thread_->RegisterSampleBucket( |
1375 &g_trace_state[0], | 1423 &g_trace_state[0], |
1376 "bucket0", | 1424 "bucket0", |
1377 Bind(&TraceSamplingThread::DefaultSamplingCallback)); | 1425 Bind(&TraceSamplingThread::DefaultSamplingCallback)); |
1378 sampling_thread_->RegisterSampleBucket( | 1426 sampling_thread_->RegisterSampleBucket( |
1379 &g_trace_state[1], | 1427 &g_trace_state[1], |
1380 "bucket1", | 1428 "bucket1", |
1381 Bind(&TraceSamplingThread::DefaultSamplingCallback)); | 1429 Bind(&TraceSamplingThread::DefaultSamplingCallback)); |
1382 sampling_thread_->RegisterSampleBucket( | 1430 sampling_thread_->RegisterSampleBucket( |
(...skipping 12 matching lines...) Expand all Loading... | |
1395 // Notify observers outside the lock in case they trigger trace events. | 1443 // Notify observers outside the lock in case they trigger trace events. |
1396 for (size_t i = 0; i < observer_list.size(); ++i) | 1444 for (size_t i = 0; i < observer_list.size(); ++i) |
1397 observer_list[i]->OnTraceLogEnabled(); | 1445 observer_list[i]->OnTraceLogEnabled(); |
1398 | 1446 |
1399 { | 1447 { |
1400 AutoLock lock(lock_); | 1448 AutoLock lock(lock_); |
1401 dispatching_to_observer_list_ = false; | 1449 dispatching_to_observer_list_ = false; |
1402 } | 1450 } |
1403 } | 1451 } |
1404 | 1452 |
1453 TraceLog::InternalTraceOptions TraceLog::GetInternalOptionsFromTraceOptions( | |
dsinclair
2014/07/28 18:52:36
The spit between trace options and internal trace
nednguyen
2014/07/28 20:27:22
The InternalTraceOptions is only used by the trace
| |
1454 const TraceOptions& options) { | |
1455 InternalTraceOptions ret = options.enable_sampling ? ENABLE_SAMPLING : NONE; | |
1456 switch (options.record_mode) { | |
1457 case TraceOptions::RECORD_UNTIL_FULL: | |
1458 return ret | RECORD_UNTIL_FULL; | |
1459 case TraceOptions::RECORD_CONTINUOUSLY: | |
1460 return ret | RECORD_CONTINUOUSLY; | |
1461 case TraceOptions::ECHO_TO_CONSOLE: | |
1462 return ret | ECHO_TO_CONSOLE; | |
1463 } | |
1464 NOTREACHED(); | |
1465 return NONE; | |
1466 } | |
1467 | |
1405 CategoryFilter TraceLog::GetCurrentCategoryFilter() { | 1468 CategoryFilter TraceLog::GetCurrentCategoryFilter() { |
1406 AutoLock lock(lock_); | 1469 AutoLock lock(lock_); |
1407 return category_filter_; | 1470 return category_filter_; |
1408 } | 1471 } |
1409 | 1472 |
1473 TraceOptions TraceLog::GetCurrentTraceOptions() const { | |
1474 TraceOptions ret; | |
1475 InternalTraceOptions option = trace_options(); | |
1476 ret.enable_sampling = (option & ENABLE_SAMPLING) != 0; | |
1477 if (option & RECORD_UNTIL_FULL) | |
1478 ret.record_mode = TraceOptions::RECORD_UNTIL_FULL; | |
1479 else if (option & RECORD_CONTINUOUSLY) | |
1480 ret.record_mode = TraceOptions::RECORD_CONTINUOUSLY; | |
1481 else if (option & ECHO_TO_CONSOLE) | |
1482 ret.record_mode = TraceOptions::ECHO_TO_CONSOLE; | |
1483 else | |
1484 NOTREACHED(); | |
1485 return ret; | |
1486 } | |
1487 | |
1410 void TraceLog::SetDisabled() { | 1488 void TraceLog::SetDisabled() { |
1411 AutoLock lock(lock_); | 1489 AutoLock lock(lock_); |
1412 SetDisabledWhileLocked(); | 1490 SetDisabledWhileLocked(); |
1413 } | 1491 } |
1414 | 1492 |
1415 void TraceLog::SetDisabledWhileLocked() { | 1493 void TraceLog::SetDisabledWhileLocked() { |
1416 lock_.AssertAcquired(); | 1494 lock_.AssertAcquired(); |
1417 | 1495 |
1418 if (!IsEnabled()) | 1496 if (!IsEnabled()) |
1419 return; | 1497 return; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1489 return static_cast<float>(static_cast<double>(logged_events_->Size()) / | 1567 return static_cast<float>(static_cast<double>(logged_events_->Size()) / |
1490 logged_events_->Capacity()); | 1568 logged_events_->Capacity()); |
1491 } | 1569 } |
1492 | 1570 |
1493 bool TraceLog::BufferIsFull() const { | 1571 bool TraceLog::BufferIsFull() const { |
1494 AutoLock lock(lock_); | 1572 AutoLock lock(lock_); |
1495 return logged_events_->IsFull(); | 1573 return logged_events_->IsFull(); |
1496 } | 1574 } |
1497 | 1575 |
1498 TraceBuffer* TraceLog::CreateTraceBuffer() { | 1576 TraceBuffer* TraceLog::CreateTraceBuffer() { |
1499 Options options = trace_options(); | 1577 InternalTraceOptions options = trace_options(); |
1500 if (options & RECORD_CONTINUOUSLY) | 1578 if (options & RECORD_CONTINUOUSLY) |
1501 return new TraceBufferRingBuffer(kTraceEventRingBufferChunks); | 1579 return new TraceBufferRingBuffer(kTraceEventRingBufferChunks); |
1502 else if ((options & ENABLE_SAMPLING) && mode_ == MONITORING_MODE) | 1580 else if ((options & ENABLE_SAMPLING) && mode_ == MONITORING_MODE) |
1503 return new TraceBufferRingBuffer(kMonitorTraceEventBufferChunks); | 1581 return new TraceBufferRingBuffer(kMonitorTraceEventBufferChunks); |
1504 else if (options & ECHO_TO_CONSOLE) | 1582 else if (options & ECHO_TO_CONSOLE) |
1505 return new TraceBufferRingBuffer(kEchoToConsoleTraceEventBufferChunks); | 1583 return new TraceBufferRingBuffer(kEchoToConsoleTraceEventBufferChunks); |
1506 return CreateTraceBufferVectorOfSize(kTraceEventVectorBufferChunks); | 1584 return CreateTraceBufferVectorOfSize(kTraceEventVectorBufferChunks); |
1507 } | 1585 } |
1508 | 1586 |
1509 TraceBuffer* TraceLog::CreateTraceBufferVectorOfSize(size_t max_chunks) { | 1587 TraceBuffer* TraceLog::CreateTraceBufferVectorOfSize(size_t max_chunks) { |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2447 } | 2525 } |
2448 | 2526 |
2449 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2527 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
2450 if (*category_group_enabled_) { | 2528 if (*category_group_enabled_) { |
2451 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2529 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
2452 name_, event_handle_); | 2530 name_, event_handle_); |
2453 } | 2531 } |
2454 } | 2532 } |
2455 | 2533 |
2456 } // namespace trace_event_internal | 2534 } // namespace trace_event_internal |
OLD | NEW |