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

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

Issue 2662083002: Create 'errors' histogram for failures. (Closed)
Patch Set: Created 3 years, 10 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_memory_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 (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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_PERSISTENT_MEMORY_ALLOCATOR_H_ 5 #ifndef BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_
6 #define BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ 6 #define BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <atomic> 10 #include <atomic>
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 bool IsReadonly() { return readonly_; } 279 bool IsReadonly() { return readonly_; }
280 280
281 // Create internal histograms for tracking memory use and allocation sizes 281 // Create internal histograms for tracking memory use and allocation sizes
282 // for allocator of |name| (which can simply be the result of Name()). This 282 // for allocator of |name| (which can simply be the result of Name()). This
283 // is done seperately from construction for situations such as when the 283 // is done seperately from construction for situations such as when the
284 // histograms will be backed by memory provided by this very allocator. 284 // histograms will be backed by memory provided by this very allocator.
285 // 285 //
286 // IMPORTANT: Callers must update tools/metrics/histograms/histograms.xml 286 // IMPORTANT: Callers must update tools/metrics/histograms/histograms.xml
287 // with the following histograms: 287 // with the following histograms:
288 // UMA.PersistentAllocator.name.Allocs 288 // UMA.PersistentAllocator.name.Allocs
289 // UMA.PersistentAllocator.name.Errors
289 // UMA.PersistentAllocator.name.UsedPct 290 // UMA.PersistentAllocator.name.UsedPct
290 void CreateTrackingHistograms(base::StringPiece name); 291 void CreateTrackingHistograms(base::StringPiece name);
291 292
292 // Direct access to underlying memory segment. If the segment is shared 293 // Direct access to underlying memory segment. If the segment is shared
293 // across threads or processes, reading data through these values does 294 // across threads or processes, reading data through these values does
294 // not guarantee consistency. Use with care. Do not write. 295 // not guarantee consistency. Use with care. Do not write.
295 const void* data() const { return const_cast<const char*>(mem_base_); } 296 const void* data() const { return const_cast<const char*>(mem_base_); }
296 size_t length() const { return mem_size_; } 297 size_t length() const { return mem_size_; }
297 size_t size() const { return mem_size_; } 298 size_t size() const { return mem_size_; }
298 size_t used() const; 299 size_t used() const;
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 // Get the actual data within a block associated with a specific reference. 603 // Get the actual data within a block associated with a specific reference.
603 const volatile void* GetBlockData(Reference ref, uint32_t type_id, 604 const volatile void* GetBlockData(Reference ref, uint32_t type_id,
604 uint32_t size) const; 605 uint32_t size) const;
605 volatile void* GetBlockData(Reference ref, uint32_t type_id, 606 volatile void* GetBlockData(Reference ref, uint32_t type_id,
606 uint32_t size) { 607 uint32_t size) {
607 return const_cast<volatile void*>( 608 return const_cast<volatile void*>(
608 const_cast<const PersistentMemoryAllocator*>(this)->GetBlockData( 609 const_cast<const PersistentMemoryAllocator*>(this)->GetBlockData(
609 ref, type_id, size)); 610 ref, type_id, size));
610 } 611 }
611 612
612 const bool readonly_; // Indicates access to read-only memory. 613 // Record an error in the internal histogram.
613 std::atomic<bool> corrupt_; // Local version of "corrupted" flag. 614 void RecordError(int error) const;
615
616 const bool readonly_; // Indicates access to read-only memory.
617 mutable std::atomic<bool> corrupt_; // Local version of "corrupted" flag.
614 618
615 HistogramBase* allocs_histogram_; // Histogram recording allocs. 619 HistogramBase* allocs_histogram_; // Histogram recording allocs.
616 HistogramBase* used_histogram_; // Histogram recording used space. 620 HistogramBase* used_histogram_; // Histogram recording used space.
621 HistogramBase* errors_histogram_; // Histogram recording errors.
617 622
618 friend class PersistentMemoryAllocatorTest; 623 friend class PersistentMemoryAllocatorTest;
619 FRIEND_TEST_ALL_PREFIXES(PersistentMemoryAllocatorTest, AllocateAndIterate); 624 FRIEND_TEST_ALL_PREFIXES(PersistentMemoryAllocatorTest, AllocateAndIterate);
620 DISALLOW_COPY_AND_ASSIGN(PersistentMemoryAllocator); 625 DISALLOW_COPY_AND_ASSIGN(PersistentMemoryAllocator);
621 }; 626 };
622 627
623 628
624 // This allocator uses a local memory block it allocates from the general 629 // This allocator uses a local memory block it allocates from the general
625 // heap. It is generally used when some kind of "death rattle" handler will 630 // heap. It is generally used when some kind of "death rattle" handler will
626 // save the contents to persistent storage during process shutdown. It is 631 // save the contents to persistent storage during process shutdown. It is
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 private: 702 private:
698 std::unique_ptr<MemoryMappedFile> mapped_file_; 703 std::unique_ptr<MemoryMappedFile> mapped_file_;
699 704
700 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator); 705 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator);
701 }; 706 };
702 #endif // !defined(OS_NACL) 707 #endif // !defined(OS_NACL)
703 708
704 } // namespace base 709 } // namespace base
705 710
706 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ 711 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/persistent_memory_allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698