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

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

Issue 2888563005: Added support for 'spare' file that can be used at startup. (Closed)
Patch Set: rebased Created 3 years, 7 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
« no previous file with comments | « no previous file | base/metrics/persistent_histogram_allocator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 // exist, the allocator will use and add to its contents, ignoring the passed 397 // exist, the allocator will use and add to its contents, ignoring the passed
398 // size in favor of the existing size. Returns whether the global allocator 398 // size in favor of the existing size. Returns whether the global allocator
399 // was set. 399 // was set.
400 static bool CreateWithFile(const FilePath& file_path, 400 static bool CreateWithFile(const FilePath& file_path,
401 size_t size, 401 size_t size,
402 uint64_t id, 402 uint64_t id,
403 StringPiece name); 403 StringPiece name);
404 404
405 // Creates a new file at |active_path|. If it already exists, it will first be 405 // Creates a new file at |active_path|. If it already exists, it will first be
406 // moved to |base_path|. In all cases, any old file at |base_path| will be 406 // moved to |base_path|. In all cases, any old file at |base_path| will be
407 // removed. The file will be created using the given size, id, and name. 407 // removed. If |spare_path| is non-empty and exists, that will be renamed and
408 // Returns whether the global allocator was set. 408 // used as the active file. Otherwise, the file will be created using the
409 // given size, id, and name. Returns whether the global allocator was set.
409 static bool CreateWithActiveFile(const FilePath& base_path, 410 static bool CreateWithActiveFile(const FilePath& base_path,
410 const FilePath& active_path, 411 const FilePath& active_path,
412 const FilePath& spare_path,
411 size_t size, 413 size_t size,
412 uint64_t id, 414 uint64_t id,
413 StringPiece name); 415 StringPiece name);
414 416
415 // Uses ConstructBaseActivePairFilePaths() to build a pair of file names which 417 // Uses ConstructBaseActivePairFilePaths() to build a pair of file names which
416 // are then used for CreateWithActiveFile(). |name| is used for both the 418 // are then used for CreateWithActiveFile(). |name| is used for both the
417 // internal name for the allocator and also for the name of the file inside 419 // internal name for the allocator and also for the name of the file inside
418 // |dir|. 420 // |dir|.
419 static bool CreateWithActiveFileInDir(const FilePath& dir, 421 static bool CreateWithActiveFileInDir(const FilePath& dir,
420 size_t size, 422 size_t size,
421 uint64_t id, 423 uint64_t id,
422 StringPiece name); 424 StringPiece name);
423 425
424 // Constructs a pair of names in |dir| based on name that can be used for a 426 // Constructs a set of names in |dir| based on name that can be used for a
425 // base + active persistent memory mapped location for CreateWithActiveFile(). 427 // base + active persistent memory mapped location for CreateWithActiveFile().
426 // |name| will be used as the basename of the file inside |dir|. 428 // The spare path is a file that can be pre-created and moved to be active
427 // |out_base_path| or |out_active_path| may be null if not needed. 429 // without any startup penalty that comes from constructing the file. |name|
430 // will be used as the basename of the file inside |dir|. |out_base_path|,
431 // |out_active_path|, or |out_spare_path| may be null if not needed.
428 static void ConstructFilePaths(const FilePath& dir, 432 static void ConstructFilePaths(const FilePath& dir,
429 StringPiece name, 433 StringPiece name,
430 FilePath* out_base_path, 434 FilePath* out_base_path,
431 FilePath* out_active_path); 435 FilePath* out_active_path,
436 FilePath* out_spare_path);
437
438 // Create a "spare" file that can later be made the "active" file. This
439 // should be done on a background thread if possible.
440 static bool CreateSpareFile(const FilePath& spare_path, size_t size);
441
442 // Same as above but uses standard names. |name| is the name of the allocator
443 // and is also used to create the correct filename.
444 static bool CreateSpareFileInDir(const FilePath& dir_path,
445 size_t size,
446 StringPiece name);
432 #endif 447 #endif
433 448
434 // Create a global allocator using a block of shared memory accessed 449 // Create a global allocator using a block of shared memory accessed
435 // through the given |handle| and |size|. The allocator takes ownership 450 // through the given |handle| and |size|. The allocator takes ownership
436 // of the handle and closes it upon destruction, though the memory will 451 // of the handle and closes it upon destruction, though the memory will
437 // continue to live if other processes have access to it. 452 // continue to live if other processes have access to it.
438 static void CreateWithSharedMemoryHandle(const SharedMemoryHandle& handle, 453 static void CreateWithSharedMemoryHandle(const SharedMemoryHandle& handle,
439 size_t size); 454 size_t size);
440 455
441 // Sets a GlobalHistogramAllocator for globally storing histograms in 456 // Sets a GlobalHistogramAllocator for globally storing histograms in
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 510
496 // The location to which the data should be persisted. 511 // The location to which the data should be persisted.
497 FilePath persistent_location_; 512 FilePath persistent_location_;
498 513
499 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator); 514 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator);
500 }; 515 };
501 516
502 } // namespace base 517 } // namespace base
503 518
504 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ 519 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/persistent_histogram_allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698