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

Side by Side Diff: components/metrics/metrics_service.h

Issue 1425533011: Support "shared" histograms between processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shmem-alloc
Patch Set: extract common histogram FactoryGet code; extract histogram persistence into seperate files Created 5 years 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 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
(...skipping 19 matching lines...) Expand all
30 #include "components/metrics/net/network_metrics_provider.h" 30 #include "components/metrics/net/network_metrics_provider.h"
31 #include "components/variations/active_field_trials.h" 31 #include "components/variations/active_field_trials.h"
32 32
33 class PrefService; 33 class PrefService;
34 class PrefRegistrySimple; 34 class PrefRegistrySimple;
35 35
36 namespace base { 36 namespace base {
37 class DictionaryValue; 37 class DictionaryValue;
38 class HistogramSamples; 38 class HistogramSamples;
39 class PrefService; 39 class PrefService;
40 class SharedMemoryAllocator;
40 } 41 }
41 42
42 namespace variations { 43 namespace variations {
43 struct ActiveGroupId; 44 struct ActiveGroupId;
44 } 45 }
45 46
46 namespace net { 47 namespace net {
47 class URLFetcher; 48 class URLFetcher;
48 } 49 }
49 50
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // should not be called more than once. 247 // should not be called more than once.
247 void CheckForClonedInstall( 248 void CheckForClonedInstall(
248 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 249 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
249 250
250 // Clears the stability metrics that are saved in local state. 251 // Clears the stability metrics that are saved in local state.
251 void ClearSavedStabilityMetrics(); 252 void ClearSavedStabilityMetrics();
252 253
253 // Pushes a log that has been generated by an external component. 254 // Pushes a log that has been generated by an external component.
254 void PushExternalLog(const std::string& log); 255 void PushExternalLog(const std::string& log);
255 256
257 // Add a persistent memory segment that contains histograms. Ownership
258 // of this object remains with the caller; it must be removed from here
259 // before being destroyed.
260 void AddPersistentMemorySegment(base::PersistentMemoryAllocator* alloc);
261
262 // Remove a persistent memory segment. This should be done only after
263 // a final reporting has been done to avoid data loss and incorrect
264 // reporting.
265 void RemovePersistentMemorySegment(base::PersistentMemoryAllocator* alloc);
266
256 protected: 267 protected:
257 // Exposed for testing. 268 // Exposed for testing.
258 MetricsLogManager* log_manager() { return &log_manager_; } 269 MetricsLogManager* log_manager() { return &log_manager_; }
259 270
260 private: 271 private:
261 // The MetricsService has a lifecycle that is stored as a state. 272 // The MetricsService has a lifecycle that is stored as a state.
262 // See metrics_service.cc for description of this lifecycle. 273 // See metrics_service.cc for description of this lifecycle.
263 enum State { 274 enum State {
264 INITIALIZED, // Constructor was called. 275 INITIALIZED, // Constructor was called.
265 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to finish. 276 INIT_TASK_SCHEDULED, // Waiting for deferred init tasks to finish.
266 INIT_TASK_DONE, // Waiting for timer to send initial log. 277 INIT_TASK_DONE, // Waiting for timer to send initial log.
267 SENDING_LOGS, // Sending logs an creating new ones when we run out. 278 SENDING_LOGS, // Sending logs an creating new ones when we run out.
268 }; 279 };
269 280
270 enum ShutdownCleanliness { 281 enum ShutdownCleanliness {
271 CLEANLY_SHUTDOWN = 0xdeadbeef, 282 CLEANLY_SHUTDOWN = 0xdeadbeef,
272 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN 283 NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN
273 }; 284 };
274 285
275 // The current state of recording for the MetricsService. The state is UNSET 286 // The current state of recording for the MetricsService. The state is UNSET
276 // until set to something else, at which point it remains INACTIVE or ACTIVE 287 // until set to something else, at which point it remains INACTIVE or ACTIVE
277 // for the lifetime of the object. 288 // for the lifetime of the object.
278 enum RecordingState { 289 enum RecordingState {
279 INACTIVE, 290 INACTIVE,
280 ACTIVE, 291 ACTIVE,
281 UNSET 292 UNSET
282 }; 293 };
283 294
295 typedef std::set<base::PersistentMemoryAllocator*> AllocatorSet;
296
297 // A class for iterating over the histograms in persistent memory segments.
298 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:
313 PersistentHistogramIterator(AllocatorSet& allocators,
314 AllocatorSet::iterator pos);
315
316 PersistentHistogramIterator& operator++();
317 PersistentHistogramIterator operator++(int) {
318 PersistentHistogramIterator tmp(*this);
319 operator++();
320 return tmp;
321 }
322
323 bool operator==(const PersistentHistogramIterator& rhs) const {
324 return allocator_iter_ == rhs.allocator_iter_ &&
325 histogram_iter_ == rhs.histogram_iter_;
326 }
327 bool operator!=(const PersistentHistogramIterator& rhs) const {
328 return allocator_iter_ != rhs.allocator_iter_ ||
329 histogram_iter_ != rhs.histogram_iter_;
330 }
331 base::HistogramBase* operator*() {
332 return current_histogram_->get();
333 }
Alexei Svitkine (slow) 2015/12/15 22:48:52 I think I mentioned this before, but my suggestion
bcwhite 2015/12/16 13:54:29 The code taking this iterator accepts standard STL
Alexei Svitkine (slow) 2015/12/16 16:33:48 Do we currently pass in other iterators? If indeed
bcwhite 2015/12/17 15:55:48 Yes. The StatisticsRecorder provides an iterator,
334
335 private:
336 AllocatorSet& allocators_;
337 AllocatorSet::iterator allocator_iter_;
338 base::PersistentMemoryAllocator::Iterator histogram_iter_;
339
340 // STL iterators must be copyable so a regular scoped_ptr is not
341 // sufficient as it doesn't allow such. A ref-counted one is needed.
342 scoped_refptr<HistogramPointer> current_histogram_;
343 };
344
284 typedef std::vector<SyntheticTrialGroup> SyntheticTrialGroups; 345 typedef std::vector<SyntheticTrialGroup> SyntheticTrialGroups;
285 346
286 // Calls into the client to initialize some system profile metrics. 347 // Calls into the client to initialize some system profile metrics.
287 void StartInitTask(); 348 void StartInitTask();
288 349
289 // Callback that moves the state to INIT_TASK_DONE. When this is called, the 350 // Callback that moves the state to INIT_TASK_DONE. When this is called, the
290 // state should be INIT_TASK_SCHEDULED. 351 // state should be INIT_TASK_SCHEDULED.
291 void FinishedInitTask(); 352 void FinishedInitTask();
292 353
293 void OnUserAction(const std::string& action); 354 void OnUserAction(const std::string& action);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 void RecordCurrentHistograms(); 475 void RecordCurrentHistograms();
415 476
416 // Record complete list of stability histograms into the current log, 477 // Record complete list of stability histograms into the current log,
417 // i.e., histograms with the |kUmaStabilityHistogramFlag| flag set. 478 // i.e., histograms with the |kUmaStabilityHistogramFlag| flag set.
418 void RecordCurrentStabilityHistograms(); 479 void RecordCurrentStabilityHistograms();
419 480
420 // Skips staged upload and discards the log. Used in case of unsuccessful 481 // Skips staged upload and discards the log. Used in case of unsuccessful
421 // upload or intentional sampling of logs. 482 // upload or intentional sampling of logs.
422 void SkipAndDiscardUpload(); 483 void SkipAndDiscardUpload();
423 484
485 // Begin and End iterators for going through all the metrics under management.
486 PersistentHistogramIterator persistent_begin();
487 PersistentHistogramIterator persistent_end();
488
424 // Manager for the various in-flight logs. 489 // Manager for the various in-flight logs.
425 MetricsLogManager log_manager_; 490 MetricsLogManager log_manager_;
426 491
427 // |histogram_snapshot_manager_| prepares histogram deltas for transmission. 492 // |histogram_snapshot_manager_| prepares histogram deltas for transmission.
428 base::HistogramSnapshotManager histogram_snapshot_manager_; 493 base::HistogramSnapshotManager histogram_snapshot_manager_;
429 494
430 // Used to manage various metrics reporting state prefs, such as client id, 495 // Used to manage various metrics reporting state prefs, such as client id,
431 // low entropy source and whether metrics reporting is enabled. Weak pointer. 496 // low entropy source and whether metrics reporting is enabled. Weak pointer.
432 MetricsStateManager* const state_manager_; 497 MetricsStateManager* const state_manager_;
433 498
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 static ExecutionPhase execution_phase_; 560 static ExecutionPhase execution_phase_;
496 561
497 // Reduntant marker to check that we completed our shutdown, and set the 562 // Reduntant marker to check that we completed our shutdown, and set the
498 // exited-cleanly bit in the prefs. 563 // exited-cleanly bit in the prefs.
499 static ShutdownCleanliness clean_shutdown_status_; 564 static ShutdownCleanliness clean_shutdown_status_;
500 565
501 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); 566 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess);
502 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, 567 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest,
503 PermutedEntropyCacheClearedWhenLowEntropyReset); 568 PermutedEntropyCacheClearedWhenLowEntropyReset);
504 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); 569 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial);
570 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MultiplePersistentAllocators);
505 571
506 // Weak pointers factory used to post task on different threads. All weak 572 // Weak pointers factory used to post task on different threads. All weak
507 // pointers managed by this factory have the same lifetime as MetricsService. 573 // pointers managed by this factory have the same lifetime as MetricsService.
508 base::WeakPtrFactory<MetricsService> self_ptr_factory_; 574 base::WeakPtrFactory<MetricsService> self_ptr_factory_;
509 575
510 // Weak pointers factory used for saving state. All weak pointers managed by 576 // Weak pointers factory used for saving state. All weak pointers managed by
511 // this factory are invalidated in ScheduleNextStateSave. 577 // this factory are invalidated in ScheduleNextStateSave.
512 base::WeakPtrFactory<MetricsService> state_saver_factory_; 578 base::WeakPtrFactory<MetricsService> state_saver_factory_;
513 579
580 // Persistent memory segments that contain histograms created elsewhere.
581 AllocatorSet allocators_;
582
514 DISALLOW_COPY_AND_ASSIGN(MetricsService); 583 DISALLOW_COPY_AND_ASSIGN(MetricsService);
515 }; 584 };
516 585
517 } // namespace metrics 586 } // namespace metrics
518 587
519 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ 588 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698