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

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

Issue 1891913002: Support saving browser metrics to disk and reading them during next run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed review comments by Ilya Created 4 years, 8 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 #ifndef BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ 5 #ifndef BASE_METRICS_HISTOGRAM_PERSISTENCE_H_
6 #define BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ 6 #define BASE_METRICS_HISTOGRAM_PERSISTENCE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 10
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 size_t size); 382 size_t size);
383 383
384 // Sets a GlobalHistogramAllocator for globally storing histograms in 384 // Sets a GlobalHistogramAllocator for globally storing histograms in
385 // a space that can be persisted or shared between processes. There is only 385 // a space that can be persisted or shared between processes. There is only
386 // ever one allocator for all such histograms created by a single process. 386 // ever one allocator for all such histograms created by a single process.
387 // This takes ownership of the object and should be called as soon as 387 // This takes ownership of the object and should be called as soon as
388 // possible during startup to capture as many histograms as possible and 388 // possible during startup to capture as many histograms as possible and
389 // while operating single-threaded so there are no race-conditions. 389 // while operating single-threaded so there are no race-conditions.
390 static void Set(std::unique_ptr<GlobalHistogramAllocator> allocator); 390 static void Set(std::unique_ptr<GlobalHistogramAllocator> allocator);
391 391
392 // Gets a pointer to the global histogram allocator. 392 // Enables the global persistent allocator. Existing histograms will not be
393 // affected; only newly created ones will go into the allocator.
394 static void Enable();
395
396 // Disables the global persistent allocator. Existing histograms will not be
397 // affected; newly created histograms will be allocated from the heap.
398 static void Disable();
Ilya Sherman 2016/04/25 19:48:40 Rather than having both an Enable() and a Disable(
bcwhite 2016/04/25 20:37:17 The default is "enabled" because that is the norma
Ilya Sherman 2016/04/25 21:12:11 Sorry, I don't follow. How is the experiment a sp
bcwhite 2016/04/26 13:32:30 See discussion in persistent_histogram_allocator.c
Ilya Sherman 2016/04/26 20:01:24 Okay, yeah, I see your point. Thanks.
399
400 // Returns whether a global allocator is enabled. This will return false if
401 // none has been set.
402 static bool IsEnabled();
Ilya Sherman 2016/04/25 19:48:40 This method appears to be unused.
bcwhite 2016/04/25 20:37:17 I was using it... Code must have changed. Still,
Ilya Sherman 2016/04/25 21:12:11 I strongly disagree that it's worthwhile to land d
bcwhite 2016/04/26 13:32:30 Done.
403
404 // Gets a pointer to an enabled global histogram allocator. If a global
405 // allocator exists but is disabled, this will return null.
393 static GlobalHistogramAllocator* Get(); 406 static GlobalHistogramAllocator* Get();
394 407
408 // Gets a pointer to a global histogram allocator if one exists, even if
409 // that allocator is disabled.
410 static GlobalHistogramAllocator* GetEvenIfDisabled();
Ilya Sherman 2016/04/25 19:48:40 IMO this method is not needed. Get() should alway
bcwhite 2016/04/25 20:37:17 Get() always returns an active allocator. Existin
Ilya Sherman 2016/04/25 21:12:11 IMO this is a poor design pattern, and I'd much ra
bcwhite 2016/04/26 13:32:30 The whole GlobalHistogramAllocator is already sepa
411
395 // This access to the persistent allocator is only for testing; it extracts 412 // This access to the persistent allocator is only for testing; it extracts
396 // the current allocator completely. This allows easy creation of histograms 413 // the current allocator completely regardless whether it is enabled or not.
397 // within persistent memory segments which can then be extracted and used 414 // This allows easy creation of histograms within persistent memory segments
398 // in other ways. 415 // which can then be extracted and used in other ways.
399 static std::unique_ptr<GlobalHistogramAllocator> ReleaseForTesting(); 416 static std::unique_ptr<GlobalHistogramAllocator> ReleaseForTesting();
400 417
418 // Stores a pathname to which the contents of this allocator should be saved
419 // in order to persist the data for a later use.
420 void SetPersistentLocation(const FilePath& location);
421
422 // Writes the internal data to a previously set location. This is generally
423 // called when a process is exiting from a section of code that may not know
424 // the filesystem. The data is written in an atomic manner. The return value
425 // indicates success.
426 bool WriteToPersistentLocation();
427
401 private: 428 private:
402 friend class StatisticsRecorder; 429 friend class StatisticsRecorder;
403 430
431 // Creates a new global histogram allocator. It will be enabled by default.
404 explicit GlobalHistogramAllocator( 432 explicit GlobalHistogramAllocator(
405 std::unique_ptr<PersistentMemoryAllocator> memory); 433 std::unique_ptr<PersistentMemoryAllocator> memory);
406 434
407 // Import new histograms from the global histogram allocator. It's possible 435 // Import new histograms from the global histogram allocator. It's possible
408 // for other processes to create histograms in the active memory segment; 436 // for other processes to create histograms in the active memory segment;
409 // this adds those to the internal list of known histograms to avoid creating 437 // this adds those to the internal list of known histograms to avoid creating
410 // duplicates that would have to be merged during reporting. Every call to 438 // duplicates that would have to be merged during reporting. Every call to
411 // this method resumes from the last entry it saw; it costs nothing if 439 // this method resumes from the last entry it saw; it costs nothing if
412 // nothing new has been added. 440 // nothing new has been added.
413 void ImportHistogramsToStatisticsRecorder(); 441 void ImportHistogramsToStatisticsRecorder();
414 442
415 // Import always continues from where it left off, making use of a single 443 // Import always continues from where it left off, making use of a single
416 // iterator to continue the work. 444 // iterator to continue the work.
417 Iterator import_iterator_; 445 Iterator import_iterator_;
418 446
447 // The location to which the data should be persisted.
448 FilePath persistent_location_;
449
419 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator); 450 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator);
420 }; 451 };
421 452
422 } // namespace base 453 } // namespace base
423 454
424 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ 455 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/persistent_histogram_allocator.cc » ('j') | base/metrics/persistent_histogram_allocator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698