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/metrics/statistics_recorder.h" | 5 #include "base/metrics/statistics_recorder.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/debug/leak_annotations.h" | 8 #include "base/debug/leak_annotations.h" |
9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 histograms_ = new HistogramMap; | 386 histograms_ = new HistogramMap; |
387 callbacks_ = new CallbackMap; | 387 callbacks_ = new CallbackMap; |
388 ranges_ = new RangesMap; | 388 ranges_ = new RangesMap; |
389 | 389 |
390 if (VLOG_IS_ON(1)) | 390 if (VLOG_IS_ON(1)) |
391 AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this); | 391 AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this); |
392 } | 392 } |
393 | 393 |
394 // static | 394 // static |
395 void StatisticsRecorder::ResetForTesting() { | 395 void StatisticsRecorder::ResetForTesting() { |
396 if (histograms_) { | 396 // This leaks a lot of objects but they've allready been annotated for such. |
grt (UTC plus 2)
2016/02/15 15:42:39
"already"
bcwhite
2016/02/15 19:22:10
Done.
| |
397 STLDeleteValues(histograms_); | 397 // Deleting them isn't possible because there could be other pointers to |
398 delete histograms_; | 398 // them somewhere. |
399 histograms_= nullptr; | 399 delete histograms_; |
400 } | 400 histograms_= nullptr; |
401 if (ranges_) { | 401 delete ranges_; |
402 for (auto& iter : *ranges_) { | 402 ranges_ = nullptr; |
403 STLDeleteElements(iter.second); | |
404 delete iter.second; | |
405 } | |
406 delete ranges_; | |
407 ranges_ = nullptr; | |
408 } | |
409 delete callbacks_; | 403 delete callbacks_; |
410 callbacks_ = nullptr; | 404 callbacks_ = nullptr; |
411 } | 405 } |
412 | 406 |
413 // static | 407 // static |
408 void StatisticsRecorder::ForgetHistogramForTesting(const std::string& name) { | |
409 if (histograms_) | |
410 histograms_->erase(HashMetricName(name)); | |
411 } | |
412 | |
413 // static | |
414 void StatisticsRecorder::DumpHistogramsToVlog(void* instance) { | 414 void StatisticsRecorder::DumpHistogramsToVlog(void* instance) { |
415 std::string output; | 415 std::string output; |
416 StatisticsRecorder::WriteGraph(std::string(), &output); | 416 StatisticsRecorder::WriteGraph(std::string(), &output); |
417 VLOG(1) << output; | 417 VLOG(1) << output; |
418 } | 418 } |
419 | 419 |
420 StatisticsRecorder::~StatisticsRecorder() { | 420 StatisticsRecorder::~StatisticsRecorder() { |
421 DCHECK(histograms_ && ranges_ && lock_); | 421 DCHECK(histograms_ && ranges_ && lock_); |
422 | 422 |
423 // Clean up. | 423 // Clean up. |
(...skipping 18 matching lines...) Expand all Loading... | |
442 // static | 442 // static |
443 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 443 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
444 // static | 444 // static |
445 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; | 445 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; |
446 // static | 446 // static |
447 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 447 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
448 // static | 448 // static |
449 base::Lock* StatisticsRecorder::lock_ = NULL; | 449 base::Lock* StatisticsRecorder::lock_ = NULL; |
450 | 450 |
451 } // namespace base | 451 } // namespace base |
OLD | NEW |