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

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: addressed review comments by Alexei Created 4 years, 11 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 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 <stdint.h> 11 #include <stdint.h>
12 12
13 #include <map> 13 #include <map>
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "base/memory/scoped_vector.h" 20 #include "base/memory/scoped_vector.h"
21 #include "base/memory/weak_ptr.h" 21 #include "base/memory/weak_ptr.h"
22 #include "base/metrics/field_trial.h" 22 #include "base/metrics/field_trial.h"
23 #include "base/metrics/histogram_flattener.h" 23 #include "base/metrics/histogram_flattener.h"
24 #include "base/metrics/histogram_snapshot_manager.h" 24 #include "base/metrics/histogram_snapshot_manager.h"
25 #include "base/metrics/persistent_memory_allocator.h"
25 #include "base/metrics/user_metrics.h" 26 #include "base/metrics/user_metrics.h"
26 #include "base/observer_list.h" 27 #include "base/observer_list.h"
27 #include "base/time/time.h" 28 #include "base/time/time.h"
28 #include "build/build_config.h" 29 #include "build/build_config.h"
29 #include "components/metrics/clean_exit_beacon.h" 30 #include "components/metrics/clean_exit_beacon.h"
30 #include "components/metrics/metrics_log.h" 31 #include "components/metrics/metrics_log.h"
31 #include "components/metrics/metrics_log_manager.h" 32 #include "components/metrics/metrics_log_manager.h"
32 #include "components/metrics/metrics_provider.h" 33 #include "components/metrics/metrics_provider.h"
33 #include "components/metrics/net/network_metrics_provider.h" 34 #include "components/metrics/net/network_metrics_provider.h"
34 #include "components/variations/synthetic_trials.h" 35 #include "components/variations/synthetic_trials.h"
35 36
36 class PrefService; 37 class PrefService;
37 class PrefRegistrySimple; 38 class PrefRegistrySimple;
38 39
39 namespace base { 40 namespace base {
40 class DictionaryValue; 41 class DictionaryValue;
41 class HistogramSamples; 42 class HistogramSamples;
42 class PrefService; 43 class PrefService;
44 class SharedMemoryAllocator;
43 } 45 }
44 46
45 namespace variations { 47 namespace variations {
46 struct ActiveGroupId; 48 struct ActiveGroupId;
47 } 49 }
48 50
49 namespace net { 51 namespace net {
50 class URLFetcher; 52 class URLFetcher;
51 } 53 }
52 54
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // should not be called more than once. 209 // should not be called more than once.
208 void CheckForClonedInstall( 210 void CheckForClonedInstall(
209 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 211 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
210 212
211 // Clears the stability metrics that are saved in local state. 213 // Clears the stability metrics that are saved in local state.
212 void ClearSavedStabilityMetrics(); 214 void ClearSavedStabilityMetrics();
213 215
214 // Pushes a log that has been generated by an external component. 216 // Pushes a log that has been generated by an external component.
215 void PushExternalLog(const std::string& log); 217 void PushExternalLog(const std::string& log);
216 218
219 // Add a persistent memory segment that contains histograms. Ownership
220 // of this object remains with the caller; it must be removed from here
221 // before being destroyed.
222 void AddPersistentMemorySegment(base::PersistentMemoryAllocator* alloc);
223
224 // Remove a persistent memory segment. This should be done only after
225 // a final reporting has been done to avoid data loss and incorrect
226 // reporting.
227 void RemovePersistentMemorySegment(base::PersistentMemoryAllocator* alloc);
228
217 protected: 229 protected:
218 // Exposed for testing. 230 // Exposed for testing.
219 MetricsLogManager* log_manager() { return &log_manager_; } 231 MetricsLogManager* log_manager() { return &log_manager_; }
220 232
221 private: 233 private:
222 friend class MetricsServiceAccessor; 234 friend class MetricsServiceAccessor;
223 235
224 // The MetricsService has a lifecycle that is stored as a state. 236 // The MetricsService has a lifecycle that is stored as a state.
225 // See metrics_service.cc for description of this lifecycle. 237 // See metrics_service.cc for description of this lifecycle.
226 enum State { 238 enum State {
(...skipping 10 matching lines...) Expand all
237 249
238 // The current state of recording for the MetricsService. The state is UNSET 250 // The current state of recording for the MetricsService. The state is UNSET
239 // until set to something else, at which point it remains INACTIVE or ACTIVE 251 // until set to something else, at which point it remains INACTIVE or ACTIVE
240 // for the lifetime of the object. 252 // for the lifetime of the object.
241 enum RecordingState { 253 enum RecordingState {
242 INACTIVE, 254 INACTIVE,
243 ACTIVE, 255 ACTIVE,
244 UNSET 256 UNSET
245 }; 257 };
246 258
259 typedef std::set<base::PersistentMemoryAllocator*> AllocatorSet;
247 typedef std::vector<variations::SyntheticTrialGroup> SyntheticTrialGroups; 260 typedef std::vector<variations::SyntheticTrialGroup> SyntheticTrialGroups;
248 261
249 // Registers a field trial name and group to be used to annotate a UMA report 262 // Registers a field trial name and group to be used to annotate a UMA report
250 // with a particular Chrome configuration state. A UMA report will be 263 // with a particular Chrome configuration state. A UMA report will be
251 // annotated with this trial group if and only if all events in the report 264 // annotated with this trial group if and only if all events in the report
252 // were created after the trial is registered. Only one group name may be 265 // were created after the trial is registered. Only one group name may be
253 // registered at a time for a given trial_name. Only the last group name that 266 // registered at a time for a given trial_name. Only the last group name that
254 // is registered for a given trial name will be recorded. The values passed 267 // is registered for a given trial name will be recorded. The values passed
255 // in must not correspond to any real field trial in the code. 268 // in must not correspond to any real field trial in the code.
256 void RegisterSyntheticFieldTrial( 269 void RegisterSyntheticFieldTrial(
257 const variations::SyntheticTrialGroup& trial_group); 270 const variations::SyntheticTrialGroup& trial_group);
258 271
272
273 // A class for iterating over the histograms in persistent memory segments.
274 // This is implemented as an STL-compatible iterator so it can be used in
275 // places that accept histograms both from here and from std containers.
276 class PersistentHistogramIterator {
277 // This class provides a reference-counted pointer to a histogram which
278 // is necessary for histogram objects that are dynamically generated
279 // (generally pointing to persistent memory) and to be owned by an STL
280 // iterator which, by necessity, must be copyable.
281 class HistogramPointer : public base::RefCounted<HistogramPointer> {
282 public:
283 HistogramPointer(base::HistogramBase* h) : histogram_(h) {}
284 base::HistogramBase* get() { return histogram_.get(); }
285
286 private:
287 scoped_ptr<base::HistogramBase> histogram_;
288 };
289
290 public:
291 PersistentHistogramIterator(AllocatorSet& allocators,
292 AllocatorSet::iterator pos);
293
294 PersistentHistogramIterator& operator++();
295 PersistentHistogramIterator operator++(int) {
296 PersistentHistogramIterator tmp(*this);
297 operator++();
298 return tmp;
299 }
300
301 bool operator==(const PersistentHistogramIterator& rhs) const {
302 return allocator_iter_ == rhs.allocator_iter_ &&
303 histogram_iter_ == rhs.histogram_iter_;
304 }
305 bool operator!=(const PersistentHistogramIterator& rhs) const {
306 return allocator_iter_ != rhs.allocator_iter_ ||
307 histogram_iter_ != rhs.histogram_iter_;
308 }
309 base::HistogramBase* operator*() {
310 return current_histogram_->get();
311 }
312
313 private:
314 AllocatorSet& allocators_;
315 AllocatorSet::iterator allocator_iter_;
316 base::PersistentMemoryAllocator::Iterator histogram_iter_;
317
318 // STL iterators must be copyable so a regular scoped_ptr is not
319 // sufficient as it doesn't allow such. A ref-counted one is needed.
320 scoped_refptr<HistogramPointer> current_histogram_;
321 };
322
323
259 // Calls into the client to initialize some system profile metrics. 324 // Calls into the client to initialize some system profile metrics.
260 void StartInitTask(); 325 void StartInitTask();
261 326
262 // Callback that moves the state to INIT_TASK_DONE. When this is called, the 327 // Callback that moves the state to INIT_TASK_DONE. When this is called, the
263 // state should be INIT_TASK_SCHEDULED. 328 // state should be INIT_TASK_SCHEDULED.
264 void FinishedInitTask(); 329 void FinishedInitTask();
265 330
266 void OnUserAction(const std::string& action); 331 void OnUserAction(const std::string& action);
267 332
268 // Get the amount of uptime since this process started and since the last 333 // Get the amount of uptime since this process started and since the last
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 void RecordCurrentHistograms(); 452 void RecordCurrentHistograms();
388 453
389 // Record complete list of stability histograms into the current log, 454 // Record complete list of stability histograms into the current log,
390 // i.e., histograms with the |kUmaStabilityHistogramFlag| flag set. 455 // i.e., histograms with the |kUmaStabilityHistogramFlag| flag set.
391 void RecordCurrentStabilityHistograms(); 456 void RecordCurrentStabilityHistograms();
392 457
393 // Skips staged upload and discards the log. Used in case of unsuccessful 458 // Skips staged upload and discards the log. Used in case of unsuccessful
394 // upload or intentional sampling of logs. 459 // upload or intentional sampling of logs.
395 void SkipAndDiscardUpload(); 460 void SkipAndDiscardUpload();
396 461
462 // Begin and End iterators for going through all the metrics under management.
463 PersistentHistogramIterator persistent_begin();
464 PersistentHistogramIterator persistent_end();
465
397 // Manager for the various in-flight logs. 466 // Manager for the various in-flight logs.
398 MetricsLogManager log_manager_; 467 MetricsLogManager log_manager_;
399 468
400 // |histogram_snapshot_manager_| prepares histogram deltas for transmission. 469 // |histogram_snapshot_manager_| prepares histogram deltas for transmission.
401 base::HistogramSnapshotManager histogram_snapshot_manager_; 470 base::HistogramSnapshotManager histogram_snapshot_manager_;
402 471
403 // Used to manage various metrics reporting state prefs, such as client id, 472 // Used to manage various metrics reporting state prefs, such as client id,
404 // low entropy source and whether metrics reporting is enabled. Weak pointer. 473 // low entropy source and whether metrics reporting is enabled. Weak pointer.
405 MetricsStateManager* const state_manager_; 474 MetricsStateManager* const state_manager_;
406 475
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 static ExecutionPhase execution_phase_; 538 static ExecutionPhase execution_phase_;
470 539
471 // Reduntant marker to check that we completed our shutdown, and set the 540 // Reduntant marker to check that we completed our shutdown, and set the
472 // exited-cleanly bit in the prefs. 541 // exited-cleanly bit in the prefs.
473 static ShutdownCleanliness clean_shutdown_status_; 542 static ShutdownCleanliness clean_shutdown_status_;
474 543
475 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); 544 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess);
476 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, 545 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest,
477 PermutedEntropyCacheClearedWhenLowEntropyReset); 546 PermutedEntropyCacheClearedWhenLowEntropyReset);
478 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); 547 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial);
548 FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MultiplePersistentAllocators);
479 549
480 // Weak pointers factory used to post task on different threads. All weak 550 // Weak pointers factory used to post task on different threads. All weak
481 // pointers managed by this factory have the same lifetime as MetricsService. 551 // pointers managed by this factory have the same lifetime as MetricsService.
482 base::WeakPtrFactory<MetricsService> self_ptr_factory_; 552 base::WeakPtrFactory<MetricsService> self_ptr_factory_;
483 553
484 // Weak pointers factory used for saving state. All weak pointers managed by 554 // Weak pointers factory used for saving state. All weak pointers managed by
485 // this factory are invalidated in ScheduleNextStateSave. 555 // this factory are invalidated in ScheduleNextStateSave.
486 base::WeakPtrFactory<MetricsService> state_saver_factory_; 556 base::WeakPtrFactory<MetricsService> state_saver_factory_;
487 557
558 // Persistent memory segments that contain histograms created elsewhere.
559 AllocatorSet allocators_;
560
488 DISALLOW_COPY_AND_ASSIGN(MetricsService); 561 DISALLOW_COPY_AND_ASSIGN(MetricsService);
489 }; 562 };
490 563
491 } // namespace metrics 564 } // namespace metrics
492 565
493 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ 566 #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698