| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // This file defines a service that collects information about the user | 5 // This file defines a service that collects information about the user |
| 6 // experience in order to help improve future versions of the app. | 6 // experience in order to help improve future versions of the app. |
| 7 | 7 |
| 8 #ifndef COMPONENTS_METRICS_METRICS_SERVICE_H_ | 8 #ifndef COMPONENTS_METRICS_METRICS_SERVICE_H_ |
| 9 #define COMPONENTS_METRICS_METRICS_SERVICE_H_ | 9 #define COMPONENTS_METRICS_METRICS_SERVICE_H_ |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <set> |
| 12 #include <string> | 13 #include <string> |
| 13 #include <vector> | 14 #include <vector> |
| 14 | 15 |
| 15 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 16 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
| 19 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 20 #include "base/metrics/field_trial.h" | 21 #include "base/metrics/field_trial.h" |
| 21 #include "base/metrics/histogram_flattener.h" | 22 #include "base/metrics/histogram_flattener.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 UNINITIALIZED_PHASE = 0, | 98 UNINITIALIZED_PHASE = 0, |
| 98 START_METRICS_RECORDING = 100, | 99 START_METRICS_RECORDING = 100, |
| 99 CREATE_PROFILE = 200, | 100 CREATE_PROFILE = 200, |
| 100 STARTUP_TIMEBOMB_ARM = 300, | 101 STARTUP_TIMEBOMB_ARM = 300, |
| 101 THREAD_WATCHER_START = 400, | 102 THREAD_WATCHER_START = 400, |
| 102 MAIN_MESSAGE_LOOP_RUN = 500, | 103 MAIN_MESSAGE_LOOP_RUN = 500, |
| 103 SHUTDOWN_TIMEBOMB_ARM = 600, | 104 SHUTDOWN_TIMEBOMB_ARM = 600, |
| 104 SHUTDOWN_COMPLETE = 700, | 105 SHUTDOWN_COMPLETE = 700, |
| 105 }; | 106 }; |
| 106 | 107 |
| 108 typedef std::set<base::HistogramBase*> HistogramSet; |
| 109 |
| 107 // Creates the MetricsService with the given |state_manager|, |client|, and | 110 // Creates the MetricsService with the given |state_manager|, |client|, and |
| 108 // |local_state|. Does not take ownership of the paramaters; instead stores | 111 // |local_state|. Does not take ownership of the paramaters; instead stores |
| 109 // a weak pointer to each. Caller should ensure that the parameters are valid | 112 // a weak pointer to each. Caller should ensure that the parameters are valid |
| 110 // for the lifetime of this class. | 113 // for the lifetime of this class. |
| 111 MetricsService(MetricsStateManager* state_manager, | 114 MetricsService(MetricsStateManager* state_manager, |
| 112 MetricsServiceClient* client, | 115 MetricsServiceClient* client, |
| 113 PrefService* local_state); | 116 PrefService* local_state); |
| 114 ~MetricsService() override; | 117 ~MetricsService() override; |
| 115 | 118 |
| 116 // Initializes metrics recording state. Updates various bookkeeping values in | 119 // Initializes metrics recording state. Updates various bookkeeping values in |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 enum RecordingState { | 292 enum RecordingState { |
| 290 INACTIVE, | 293 INACTIVE, |
| 291 ACTIVE, | 294 ACTIVE, |
| 292 UNSET | 295 UNSET |
| 293 }; | 296 }; |
| 294 | 297 |
| 295 typedef std::set<base::PersistentMemoryAllocator*> AllocatorSet; | 298 typedef std::set<base::PersistentMemoryAllocator*> AllocatorSet; |
| 296 | 299 |
| 297 // A class for iterating over the histograms in persistent memory segments. | 300 // A class for iterating over the histograms in persistent memory segments. |
| 298 class PersistentHistogramIterator { | 301 class PersistentHistogramIterator { |
| 299 // This class provides a reference-counted pointer to a histogram which | |
| 300 // is necessary for histogram objects that are dynamically generated | |
| 301 // (generally pointing to persistent memory) and to be owned by an STL | |
| 302 // iterator which, by necessity, must be copyable. | |
| 303 class HistogramPointer : public base::RefCounted<HistogramPointer> { | |
| 304 public: | |
| 305 HistogramPointer(base::HistogramBase* h) : histogram_(h) {} | |
| 306 base::HistogramBase* get() { return histogram_.get(); } | |
| 307 | |
| 308 private: | |
| 309 scoped_ptr<base::HistogramBase> histogram_; | |
| 310 }; | |
| 311 | |
| 312 public: | 302 public: |
| 313 PersistentHistogramIterator(AllocatorSet& allocators, | 303 // The |found_histograms| set will be loaded with pointers to all the |
| 304 // histograms found during iteration. This is important because users |
| 305 // of the iterator may expect the returned histograms to live longer |
| 306 // than a particular iteration step. The caller must delete these |
| 307 // if necessary. |
| 308 PersistentHistogramIterator(HistogramSet* found_histograms, |
| 309 AllocatorSet& allocators, |
| 314 AllocatorSet::iterator pos); | 310 AllocatorSet::iterator pos); |
| 315 | 311 |
| 316 PersistentHistogramIterator& operator++(); | 312 PersistentHistogramIterator& operator++(); |
| 317 PersistentHistogramIterator operator++(int) { | 313 PersistentHistogramIterator operator++(int) { |
| 318 PersistentHistogramIterator tmp(*this); | 314 PersistentHistogramIterator tmp(*this); |
| 319 operator++(); | 315 operator++(); |
| 320 return tmp; | 316 return tmp; |
| 321 } | 317 } |
| 322 | 318 |
| 323 bool operator==(const PersistentHistogramIterator& rhs) const { | 319 bool operator==(const PersistentHistogramIterator& rhs) const { |
| 324 return allocator_iter_ == rhs.allocator_iter_ && | 320 return allocator_iter_ == rhs.allocator_iter_ && |
| 325 histogram_iter_ == rhs.histogram_iter_; | 321 histogram_iter_ == rhs.histogram_iter_; |
| 326 } | 322 } |
| 327 bool operator!=(const PersistentHistogramIterator& rhs) const { | 323 bool operator!=(const PersistentHistogramIterator& rhs) const { |
| 328 return allocator_iter_ != rhs.allocator_iter_ || | 324 return allocator_iter_ != rhs.allocator_iter_ || |
| 329 histogram_iter_ != rhs.histogram_iter_; | 325 histogram_iter_ != rhs.histogram_iter_; |
| 330 } | 326 } |
| 331 base::HistogramBase* operator*() { | 327 base::HistogramBase* operator*() { |
| 332 return current_histogram_->get(); | 328 return current_histogram_; |
| 333 } | 329 } |
| 334 | 330 |
| 335 private: | 331 private: |
| 336 AllocatorSet& allocators_; | 332 AllocatorSet& allocators_; |
| 337 AllocatorSet::iterator allocator_iter_; | 333 AllocatorSet::iterator allocator_iter_; |
| 338 base::PersistentMemoryAllocator::Iterator histogram_iter_; | 334 base::PersistentMemoryAllocator::Iterator histogram_iter_; |
| 339 | 335 |
| 340 // STL iterators must be copyable so a regular scoped_ptr is not | 336 HistogramSet* found_histograms_; |
| 341 // sufficient as it doesn't allow such. A ref-counted one is needed. | 337 base::HistogramBase* current_histogram_; |
| 342 scoped_refptr<HistogramPointer> current_histogram_; | |
| 343 }; | 338 }; |
| 344 | 339 |
| 345 typedef std::vector<SyntheticTrialGroup> SyntheticTrialGroups; | 340 typedef std::vector<SyntheticTrialGroup> SyntheticTrialGroups; |
| 346 | 341 |
| 347 // Calls into the client to initialize some system profile metrics. | 342 // Calls into the client to initialize some system profile metrics. |
| 348 void StartInitTask(); | 343 void StartInitTask(); |
| 349 | 344 |
| 350 // Callback that moves the state to INIT_TASK_DONE. When this is called, the | 345 // Callback that moves the state to INIT_TASK_DONE. When this is called, the |
| 351 // state should be INIT_TASK_SCHEDULED. | 346 // state should be INIT_TASK_SCHEDULED. |
| 352 void FinishedInitTask(); | 347 void FinishedInitTask(); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 471 |
| 477 // Record complete list of stability histograms into the current log, | 472 // Record complete list of stability histograms into the current log, |
| 478 // i.e., histograms with the |kUmaStabilityHistogramFlag| flag set. | 473 // i.e., histograms with the |kUmaStabilityHistogramFlag| flag set. |
| 479 void RecordCurrentStabilityHistograms(); | 474 void RecordCurrentStabilityHistograms(); |
| 480 | 475 |
| 481 // Skips staged upload and discards the log. Used in case of unsuccessful | 476 // Skips staged upload and discards the log. Used in case of unsuccessful |
| 482 // upload or intentional sampling of logs. | 477 // upload or intentional sampling of logs. |
| 483 void SkipAndDiscardUpload(); | 478 void SkipAndDiscardUpload(); |
| 484 | 479 |
| 485 // Begin and End iterators for going through all the metrics under management. | 480 // Begin and End iterators for going through all the metrics under management. |
| 486 PersistentHistogramIterator persistent_begin(); | 481 PersistentHistogramIterator persistent_begin(HistogramSet* found); |
| 487 PersistentHistogramIterator persistent_end(); | 482 PersistentHistogramIterator persistent_end(); |
| 488 | 483 |
| 489 // Manager for the various in-flight logs. | 484 // Manager for the various in-flight logs. |
| 490 MetricsLogManager log_manager_; | 485 MetricsLogManager log_manager_; |
| 491 | 486 |
| 492 // |histogram_snapshot_manager_| prepares histogram deltas for transmission. | 487 // |histogram_snapshot_manager_| prepares histogram deltas for transmission. |
| 493 base::HistogramSnapshotManager histogram_snapshot_manager_; | 488 base::HistogramSnapshotManager histogram_snapshot_manager_; |
| 494 | 489 |
| 495 // Used to manage various metrics reporting state prefs, such as client id, | 490 // Used to manage various metrics reporting state prefs, such as client id, |
| 496 // low entropy source and whether metrics reporting is enabled. Weak pointer. | 491 // low entropy source and whether metrics reporting is enabled. Weak pointer. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 | 574 |
| 580 // Persistent memory segments that contain histograms created elsewhere. | 575 // Persistent memory segments that contain histograms created elsewhere. |
| 581 AllocatorSet allocators_; | 576 AllocatorSet allocators_; |
| 582 | 577 |
| 583 DISALLOW_COPY_AND_ASSIGN(MetricsService); | 578 DISALLOW_COPY_AND_ASSIGN(MetricsService); |
| 584 }; | 579 }; |
| 585 | 580 |
| 586 } // namespace metrics | 581 } // namespace metrics |
| 587 | 582 |
| 588 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ | 583 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ |
| OLD | NEW |