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

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

Issue 2308763002: Integrate Crashpad UMA (Closed)
Patch Set: . Created 4 years, 3 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 StringPiece name); 387 StringPiece name);
388 388
389 // Create a global allocator using an internal block of memory of the 389 // Create a global allocator using an internal block of memory of the
390 // specified |size| taken from the heap. 390 // specified |size| taken from the heap.
391 static void CreateWithLocalMemory(size_t size, uint64_t id, StringPiece name); 391 static void CreateWithLocalMemory(size_t size, uint64_t id, StringPiece name);
392 392
393 #if !defined(OS_NACL) 393 #if !defined(OS_NACL)
394 // Create a global allocator by memory-mapping a |file|. If the file does 394 // Create a global allocator by memory-mapping a |file|. If the file does
395 // not exist, it will be created with the specified |size|. If the file does 395 // not exist, it will be created with the specified |size|. If the file does
396 // exist, the allocator will use and add to its contents, ignoring the passed 396 // exist, the allocator will use and add to its contents, ignoring the passed
397 // size in favor of the existing size. 397 // size in favor of the existing size. Returns whether the global allocator
398 static void CreateWithFile(const FilePath& file_path, 398 // was set.
399 static bool CreateWithFile(const FilePath& file_path,
399 size_t size, 400 size_t size,
400 uint64_t id, 401 uint64_t id,
401 StringPiece name); 402 StringPiece name);
403
404 // Creates a new file at |active_path|. If it already exists, it will first be
405 // moved to |base_path|. In all cases, any old file at |base_path| will be
406 // removed. The file will be created using the given size, id, and name.
407 // Returns whether the global allocator was set.
408 static bool CreateWithActiveFile(const FilePath& base_path,
409 const FilePath& active_path,
410 size_t size,
411 uint64_t id,
412 StringPiece name);
413
414 // Uses ConstructBaseActivePairFilePaths() to build a pair of file names which
415 // are then used for CreateWithActiveFile().
bcwhite 2016/09/14 21:11:29 Note that |name| will be used for both the interna
scottmg 2016/09/14 22:12:30 Done.
416 static bool CreateWithActiveFileInDir(const FilePath& dir,
417 size_t size,
418 uint64_t id,
419 StringPiece name);
420
421 // Constructs a pair of names in |dir| based on name that can be used for a
422 // base + active persistent memory mapped location for CreateWithActiveFile().
423 static void ConstructBaseActivePairFilePaths(const FilePath& dir,
bcwhite 2016/09/14 21:11:30 How about shortening this method to just ContructF
scottmg 2016/09/14 22:12:31 Done.
424 StringPiece name,
425 FilePath* out_base_path,
426 FilePath* out_active_path);
402 #endif 427 #endif
403 428
404 // Create a global allocator using a block of shared |memory| of the 429 // Create a global allocator using a block of shared |memory| of the
405 // specified |size|. The allocator takes ownership of the shared memory 430 // specified |size|. The allocator takes ownership of the shared memory
406 // and releases it upon destruction, though the memory will continue to 431 // and releases it upon destruction, though the memory will continue to
407 // live if other processes have access to it. 432 // live if other processes have access to it.
408 static void CreateWithSharedMemory(std::unique_ptr<SharedMemory> memory, 433 static void CreateWithSharedMemory(std::unique_ptr<SharedMemory> memory,
409 size_t size, 434 size_t size,
410 uint64_t id, 435 uint64_t id,
411 StringPiece name); 436 StringPiece name);
(...skipping 30 matching lines...) Expand all
442 // Retrieves a previously set pathname to which the contents of this allocator 467 // Retrieves a previously set pathname to which the contents of this allocator
443 // are to be saved. 468 // are to be saved.
444 const FilePath& GetPersistentLocation() const; 469 const FilePath& GetPersistentLocation() const;
445 470
446 // Writes the internal data to a previously set location. This is generally 471 // Writes the internal data to a previously set location. This is generally
447 // called when a process is exiting from a section of code that may not know 472 // called when a process is exiting from a section of code that may not know
448 // the filesystem. The data is written in an atomic manner. The return value 473 // the filesystem. The data is written in an atomic manner. The return value
449 // indicates success. 474 // indicates success.
450 bool WriteToPersistentLocation(); 475 bool WriteToPersistentLocation();
451 476
477 // If there is a global metrics file being updated on disk, mark it to be
478 // deleted when the process exits. A normal shutdown is almost complete so
bcwhite 2016/09/14 21:11:30 Comment needs updating for its new location. A sh
scottmg 2016/09/14 22:12:31 Done.
479 // there is no benefit in keeping a file with no new data to be processed
480 // during the next startup sequence. Deleting the file during shutdown adds an
481 // extra disk-access or two to shutdown but eliminates the unnecessary
482 // processing of the contents during startup only to find nothing.
483 void DeletePersistentLocation();
484
452 private: 485 private:
453 friend class StatisticsRecorder; 486 friend class StatisticsRecorder;
454 487
455 // Creates a new global histogram allocator. 488 // Creates a new global histogram allocator.
456 explicit GlobalHistogramAllocator( 489 explicit GlobalHistogramAllocator(
457 std::unique_ptr<PersistentMemoryAllocator> memory); 490 std::unique_ptr<PersistentMemoryAllocator> memory);
458 491
459 // Import new histograms from the global histogram allocator. It's possible 492 // Import new histograms from the global histogram allocator. It's possible
460 // for other processes to create histograms in the active memory segment; 493 // for other processes to create histograms in the active memory segment;
461 // this adds those to the internal list of known histograms to avoid creating 494 // this adds those to the internal list of known histograms to avoid creating
462 // duplicates that would have to be merged during reporting. Every call to 495 // duplicates that would have to be merged during reporting. Every call to
463 // this method resumes from the last entry it saw; it costs nothing if 496 // this method resumes from the last entry it saw; it costs nothing if
464 // nothing new has been added. 497 // nothing new has been added.
465 void ImportHistogramsToStatisticsRecorder(); 498 void ImportHistogramsToStatisticsRecorder();
466 499
467 // Import always continues from where it left off, making use of a single 500 // Import always continues from where it left off, making use of a single
468 // iterator to continue the work. 501 // iterator to continue the work.
469 Iterator import_iterator_; 502 Iterator import_iterator_;
470 503
471 // The location to which the data should be persisted. 504 // The location to which the data should be persisted.
472 FilePath persistent_location_; 505 FilePath persistent_location_;
473 506
474 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator); 507 DISALLOW_COPY_AND_ASSIGN(GlobalHistogramAllocator);
475 }; 508 };
476 509
477 } // namespace base 510 } // namespace base
478 511
479 #endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_ 512 #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