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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 391 |
392 // Gets a pointer to the global histogram allocator. | 392 // Gets a pointer to the global histogram allocator. |
393 static GlobalHistogramAllocator* Get(); | 393 static GlobalHistogramAllocator* Get(); |
394 | 394 |
395 // This access to the persistent allocator is only for testing; it extracts | 395 // This access to the persistent allocator is only for testing; it extracts |
396 // the current allocator completely. This allows easy creation of histograms | 396 // the current allocator completely. This allows easy creation of histograms |
397 // within persistent memory segments which can then be extracted and used | 397 // within persistent memory segments which can then be extracted and used |
398 // in other ways. | 398 // in other ways. |
399 static std::unique_ptr<GlobalHistogramAllocator> ReleaseForTesting(); | 399 static std::unique_ptr<GlobalHistogramAllocator> ReleaseForTesting(); |
400 | 400 |
| 401 // Stores a pathname to which the contents of this allocator should be saved |
| 402 // in order to persist the data for a later use. |
| 403 void SetPersistentLocation(const FilePath& location); |
| 404 |
| 405 // Writes the internal data to a previously set location. This is generally |
| 406 // called when a process is exiting from a section of code that may not know |
| 407 // the filesystem. The data is written in an atomic manner. The return value |
| 408 // indicates success. |
| 409 bool WriteToPersistentLocation(); |
| 410 |
401 private: | 411 private: |
402 friend class StatisticsRecorder; | 412 friend class StatisticsRecorder; |
403 | 413 |
404 explicit GlobalHistogramAllocator( | 414 explicit GlobalHistogramAllocator( |
405 std::unique_ptr<PersistentMemoryAllocator> memory); | 415 std::unique_ptr<PersistentMemoryAllocator> memory); |
406 | 416 |
407 // Import new histograms from the global histogram allocator. It's possible | 417 // Import new histograms from the global histogram allocator. It's possible |
408 // for other processes to create histograms in the active memory segment; | 418 // 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 | 419 // 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 | 420 // 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 | 421 // this method resumes from the last entry it saw; it costs nothing if |
412 // nothing new has been added. | 422 // nothing new has been added. |
413 void ImportHistogramsToStatisticsRecorder(); | 423 void ImportHistogramsToStatisticsRecorder(); |
414 | 424 |
415 // Import always continues from where it left off, making use of a single | 425 // Import always continues from where it left off, making use of a single |
416 // iterator to continue the work. | 426 // iterator to continue the work. |
417 Iterator import_iterator_; | 427 Iterator import_iterator_; |
418 | 428 |
| 429 // The location to which the data should be persisted. |
| 430 FilePath persistent_location_; |
| 431 |
419 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator); | 432 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator); |
420 }; | 433 }; |
421 | 434 |
422 } // namespace base | 435 } // namespace base |
423 | 436 |
424 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ | 437 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ |
OLD | NEW |