Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: base/metrics/persistent_histogram_allocator.cc

Issue 2023253002: Merge subprocess metrics into global StatisticsRecorder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: improved comment about when merges occur Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/persistent_histogram_allocator.h" 5 #include "base/metrics/persistent_histogram_allocator.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/files/important_file_writer.h" 9 #include "base/files/important_file_writer.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/metrics/histogram_base.h" 14 #include "base/metrics/histogram_base.h"
15 #include "base/metrics/histogram_samples.h" 15 #include "base/metrics/histogram_samples.h"
16 #include "base/metrics/persistent_sample_map.h" 16 #include "base/metrics/persistent_sample_map.h"
17 #include "base/metrics/sparse_histogram.h" 17 #include "base/metrics/sparse_histogram.h"
18 #include "base/metrics/statistics_recorder.h" 18 #include "base/metrics/statistics_recorder.h"
19 #include "base/pickle.h"
19 #include "base/synchronization/lock.h" 20 #include "base/synchronization/lock.h"
20 21
21 // TODO(bcwhite): Order these methods to match the header file. The current 22 // TODO(bcwhite): Order these methods to match the header file. The current
22 // order is only temporary in order to aid review of the transition from 23 // order is only temporary in order to aid review of the transition from
23 // a non-class implementation. 24 // a non-class implementation.
24 25
25 namespace base { 26 namespace base {
26 27
27 namespace { 28 namespace {
28 29
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 // be marked as "iterable" in order to be found by other processes. 477 // be marked as "iterable" in order to be found by other processes.
477 if (registered) 478 if (registered)
478 memory_allocator_->MakeIterable(ref); 479 memory_allocator_->MakeIterable(ref);
479 // If it wasn't registered then a race condition must have caused 480 // If it wasn't registered then a race condition must have caused
480 // two to be created. The allocator does not support releasing the 481 // two to be created. The allocator does not support releasing the
481 // acquired memory so just change the type to be empty. 482 // acquired memory so just change the type to be empty.
482 else 483 else
483 memory_allocator_->SetType(ref, 0); 484 memory_allocator_->SetType(ref, 0);
484 } 485 }
485 486
487 void PersistentHistogramAllocator::MergeHistogramToStatisticsRecorder(
488 HistogramBase* histogram) {
489 // This should never be called on the global histogram allocator as objects
490 // created there are already within the global statistics recorder.
491 DCHECK_NE(g_allocator, this);
492 DCHECK(histogram);
493
494 HistogramBase* existing =
495 StatisticsRecorder::FindHistogram(histogram->histogram_name());
496 if (!existing) {
497 // Adding the passed histogram to the SR would cause a problem if the
498 // allocator that holds it eventually goes away. Instead, create a new
499 // one from a serialized version and then add the data to it. Future
500 // merges won't need to do this step since FindHistogram() will locate
501 // the one created here.
502 base::Pickle pickle;
503 if (!histogram->SerializeInfo(&pickle)) {
504 // Pickling should never fail but if it does, no real harm is done.
505 // The data won't be merged but it also won't be recorded as merged
506 // so a future try, if successful, will get what was missed. If it
507 // continues to fail, some metric data will be lost but that is
508 // better than crashing.
509 NOTREACHED();
510 return;
511 }
512
513 PickleIterator iter(pickle);
514 existing = DeserializeHistogramInfo(&iter);
515 if (!existing) {
516 // Un-pickling should similarly never fail.
517 NOTREACHED();
518 return;
519 }
520
521 // Make sure there is no "serialization" flag set.
522 DCHECK_EQ(0,
523 existing->flags() & HistogramBase::kIPCSerializationSourceFlag);
524
525 // Record the newly created histogram in the SR.
526 existing = StatisticsRecorder::RegisterOrDeleteDuplicate(existing);
527 }
528
529 // Merge the delta from the passed object to the one in the SR.
530 existing->AddSamples(*histogram->SnapshotDelta());
531 }
532
486 PersistentSampleMapRecords* PersistentHistogramAllocator::UseSampleMapRecords( 533 PersistentSampleMapRecords* PersistentHistogramAllocator::UseSampleMapRecords(
487 uint64_t id, 534 uint64_t id,
488 const void* user) { 535 const void* user) {
489 return sparse_histogram_data_manager_.UseSampleMapRecords(id, user); 536 return sparse_histogram_data_manager_.UseSampleMapRecords(id, user);
490 } 537 }
491 538
492 std::unique_ptr<HistogramBase> PersistentHistogramAllocator::AllocateHistogram( 539 std::unique_ptr<HistogramBase> PersistentHistogramAllocator::AllocateHistogram(
493 HistogramType histogram_type, 540 HistogramType histogram_type,
494 const std::string& name, 541 const std::string& name,
495 int minimum, 542 int minimum,
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 while (true) { 805 while (true) {
759 std::unique_ptr<HistogramBase> histogram = 806 std::unique_ptr<HistogramBase> histogram =
760 import_iterator_.GetNextWithIgnore(record_to_ignore); 807 import_iterator_.GetNextWithIgnore(record_to_ignore);
761 if (!histogram) 808 if (!histogram)
762 break; 809 break;
763 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); 810 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release());
764 } 811 }
765 } 812 }
766 813
767 } // namespace base 814 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/persistent_histogram_allocator.h ('k') | base/metrics/persistent_histogram_allocator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698