| OLD | NEW |
| 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 size_t size); | 387 size_t size); |
| 388 | 388 |
| 389 // Sets a GlobalHistogramAllocator for globally storing histograms in | 389 // Sets a GlobalHistogramAllocator for globally storing histograms in |
| 390 // a space that can be persisted or shared between processes. There is only | 390 // a space that can be persisted or shared between processes. There is only |
| 391 // ever one allocator for all such histograms created by a single process. | 391 // ever one allocator for all such histograms created by a single process. |
| 392 // This takes ownership of the object and should be called as soon as | 392 // This takes ownership of the object and should be called as soon as |
| 393 // possible during startup to capture as many histograms as possible and | 393 // possible during startup to capture as many histograms as possible and |
| 394 // while operating single-threaded so there are no race-conditions. | 394 // while operating single-threaded so there are no race-conditions. |
| 395 static void Set(std::unique_ptr<GlobalHistogramAllocator> allocator); | 395 static void Set(std::unique_ptr<GlobalHistogramAllocator> allocator); |
| 396 | 396 |
| 397 // Enables the global persistent allocator. Existing histograms will not be | 397 // Gets a pointer to the global histogram allocator. Returns null if none |
| 398 // affected; only newly created ones will go into the allocator. | 398 // exists. |
| 399 static void Enable(); | |
| 400 | |
| 401 // Disables the global persistent allocator. Existing histograms will not be | |
| 402 // affected; newly created histograms will be allocated from the heap. | |
| 403 static void Disable(); | |
| 404 | |
| 405 // Gets a pointer to an enabled global histogram allocator. If a global | |
| 406 // allocator exists but is disabled, this will return null. | |
| 407 static GlobalHistogramAllocator* Get(); | 399 static GlobalHistogramAllocator* Get(); |
| 408 | 400 |
| 409 // Gets a pointer to a global histogram allocator if one exists, even if | |
| 410 // that allocator is disabled. | |
| 411 static GlobalHistogramAllocator* GetEvenIfDisabled(); | |
| 412 | |
| 413 // This access to the persistent allocator is only for testing; it extracts | 401 // This access to the persistent allocator is only for testing; it extracts |
| 414 // the current allocator completely regardless whether it is enabled or not. | 402 // the current allocator completely. This allows easy creation of histograms |
| 415 // This allows easy creation of histograms within persistent memory segments | 403 // within persistent memory segments which can then be extracted and used in |
| 416 // which can then be extracted and used in other ways. | 404 // other ways. |
| 417 static std::unique_ptr<GlobalHistogramAllocator> ReleaseForTesting(); | 405 static std::unique_ptr<GlobalHistogramAllocator> ReleaseForTesting(); |
| 418 | 406 |
| 419 // Stores a pathname to which the contents of this allocator should be saved | 407 // Stores a pathname to which the contents of this allocator should be saved |
| 420 // in order to persist the data for a later use. | 408 // in order to persist the data for a later use. |
| 421 void SetPersistentLocation(const FilePath& location); | 409 void SetPersistentLocation(const FilePath& location); |
| 422 | 410 |
| 423 // Writes the internal data to a previously set location. This is generally | 411 // Writes the internal data to a previously set location. This is generally |
| 424 // called when a process is exiting from a section of code that may not know | 412 // called when a process is exiting from a section of code that may not know |
| 425 // the filesystem. The data is written in an atomic manner. The return value | 413 // the filesystem. The data is written in an atomic manner. The return value |
| 426 // indicates success. | 414 // indicates success. |
| 427 bool WriteToPersistentLocation(); | 415 bool WriteToPersistentLocation(); |
| 428 | 416 |
| 429 private: | 417 private: |
| 430 friend class StatisticsRecorder; | 418 friend class StatisticsRecorder; |
| 431 | 419 |
| 432 // Creates a new global histogram allocator. It will be enabled by default. | 420 // Creates a new global histogram allocator. |
| 433 explicit GlobalHistogramAllocator( | 421 explicit GlobalHistogramAllocator( |
| 434 std::unique_ptr<PersistentMemoryAllocator> memory); | 422 std::unique_ptr<PersistentMemoryAllocator> memory); |
| 435 | 423 |
| 436 // Import new histograms from the global histogram allocator. It's possible | 424 // Import new histograms from the global histogram allocator. It's possible |
| 437 // for other processes to create histograms in the active memory segment; | 425 // for other processes to create histograms in the active memory segment; |
| 438 // this adds those to the internal list of known histograms to avoid creating | 426 // this adds those to the internal list of known histograms to avoid creating |
| 439 // duplicates that would have to be merged during reporting. Every call to | 427 // duplicates that would have to be merged during reporting. Every call to |
| 440 // this method resumes from the last entry it saw; it costs nothing if | 428 // this method resumes from the last entry it saw; it costs nothing if |
| 441 // nothing new has been added. | 429 // nothing new has been added. |
| 442 void ImportHistogramsToStatisticsRecorder(); | 430 void ImportHistogramsToStatisticsRecorder(); |
| 443 | 431 |
| 444 // Import always continues from where it left off, making use of a single | 432 // Import always continues from where it left off, making use of a single |
| 445 // iterator to continue the work. | 433 // iterator to continue the work. |
| 446 Iterator import_iterator_; | 434 Iterator import_iterator_; |
| 447 | 435 |
| 448 // The location to which the data should be persisted. | 436 // The location to which the data should be persisted. |
| 449 FilePath persistent_location_; | 437 FilePath persistent_location_; |
| 450 | 438 |
| 451 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator); | 439 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator); |
| 452 }; | 440 }; |
| 453 | 441 |
| 454 } // namespace base | 442 } // namespace base |
| 455 | 443 |
| 456 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ | 444 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ |
| OLD | NEW |