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

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 some 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();
399
400 // Gets a pointer to an enabled global histogram allocator. If a global
401 // allocator exists but is disabled, this will return null.
393 static GlobalHistogramAllocator* Get(); 402 static GlobalHistogramAllocator* Get();
394 403
404 // Gets a pointer to a global histogram allocator if one exists, even if
405 // that allocator is disabled.
406 static GlobalHistogramAllocator* GetEvenIfDisabled();
Ilya Sherman 2016/04/26 20:01:24 Looking at the uses, it looks like you could repla
bcwhite 2016/04/26 21:04:26 The name can't be a constant here because the name
407
395 // This access to the persistent allocator is only for testing; it extracts 408 // This access to the persistent allocator is only for testing; it extracts
396 // the current allocator completely. This allows easy creation of histograms 409 // the current allocator completely regardless whether it is enabled or not.
397 // within persistent memory segments which can then be extracted and used 410 // This allows easy creation of histograms within persistent memory segments
398 // in other ways. 411 // which can then be extracted and used in other ways.
399 static std::unique_ptr<GlobalHistogramAllocator> ReleaseForTesting(); 412 static std::unique_ptr<GlobalHistogramAllocator> ReleaseForTesting();
400 413
414 // Stores a pathname to which the contents of this allocator should be saved
415 // in order to persist the data for a later use.
416 void SetPersistentLocation(const FilePath& location);
417
418 // Writes the internal data to a previously set location. This is generally
419 // called when a process is exiting from a section of code that may not know
420 // the filesystem. The data is written in an atomic manner. The return value
421 // indicates success.
422 bool WriteToPersistentLocation();
423
401 private: 424 private:
402 friend class StatisticsRecorder; 425 friend class StatisticsRecorder;
403 426
427 // Creates a new global histogram allocator. It will be enabled by default.
404 explicit GlobalHistogramAllocator( 428 explicit GlobalHistogramAllocator(
405 std::unique_ptr<PersistentMemoryAllocator> memory); 429 std::unique_ptr<PersistentMemoryAllocator> memory);
406 430
407 // Import new histograms from the global histogram allocator. It's possible 431 // Import new histograms from the global histogram allocator. It's possible
408 // for other processes to create histograms in the active memory segment; 432 // 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 433 // 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 434 // 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 435 // this method resumes from the last entry it saw; it costs nothing if
412 // nothing new has been added. 436 // nothing new has been added.
413 void ImportHistogramsToStatisticsRecorder(); 437 void ImportHistogramsToStatisticsRecorder();
414 438
415 // Import always continues from where it left off, making use of a single 439 // Import always continues from where it left off, making use of a single
416 // iterator to continue the work. 440 // iterator to continue the work.
417 Iterator import_iterator_; 441 Iterator import_iterator_;
418 442
443 // The location to which the data should be persisted.
444 FilePath persistent_location_;
445
419 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator); 446 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator);
420 }; 447 };
421 448
422 } // namespace base 449 } // namespace base
423 450
424 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ 451 #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