Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_METRICS_PERSISTENT_SYSTEM_PROFILE_H_ | |
| 6 #define BASE_METRICS_PERSISTENT_SYSTEM_PROFILE_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/threading/thread_checker.h" | |
| 11 #include "components/metrics/proto/system_profile.pb.h" | |
| 12 | |
| 13 namespace base { | |
| 14 | |
|
Alexei Svitkine (slow)
2017/05/26 18:01:53
Nit: No need for inner newlines for forward declar
bcwhite
2017/05/29 18:32:26
Done.
| |
| 15 class PersistentMemoryAllocator; | |
| 16 | |
| 17 } // namespace base | |
| 18 | |
| 19 namespace metrics { | |
| 20 | |
| 21 // Manage a copy of the system profile inside persistent memory segments. | |
|
Alexei Svitkine (slow)
2017/05/26 18:01:53
Nit: Manages
bcwhite
2017/05/29 18:32:26
Done.
| |
| 22 class PersistentSystemProfile { | |
| 23 public: | |
| 24 PersistentSystemProfile(); | |
| 25 ~PersistentSystemProfile(); | |
| 26 | |
| 27 // This object can store records in multiple memory allocators. | |
| 28 void RegisterPersistentAllocator( | |
| 29 base::PersistentMemoryAllocator* memory_allocator); | |
| 30 void DeregisterPersistentAllocator( | |
| 31 base::PersistentMemoryAllocator* memory_allocator); | |
| 32 | |
| 33 // Stores a complete system profile. | |
| 34 void SetSystemProfile(const SystemProfileProto& system_profile); | |
| 35 | |
| 36 // Retrieves the system profile from a persistent memory allocator. Returns | |
| 37 // true if a profile was successfully retrieved. | |
| 38 static bool GetSystemProfile( | |
| 39 SystemProfileProto* system_profile, | |
| 40 const base::PersistentMemoryAllocator* memory_allocator); | |
|
Alexei Svitkine (slow)
2017/05/26 18:01:53
If the param can't be null, pass by const ref inst
bcwhite
2017/05/29 18:32:26
For historical reasons, the persistent allocator i
Alexei Svitkine (slow)
2017/05/29 19:48:32
I don't see why it needs to be that way. The style
bcwhite
2017/05/29 20:56:35
Done.
| |
| 41 | |
| 42 private: | |
| 43 friend class PersistentSystemProfileTest; | |
| 44 | |
| 45 // Defines record types that can be stored inside our local Allocators. | |
| 46 enum RecordType : uint8_t { | |
| 47 kUnusedSpace, | |
| 48 kPadding, | |
|
Alexei Svitkine (slow)
2017/05/26 18:01:53
This seems unused?
bcwhite
2017/05/29 18:32:26
I was expecting to need it when more record types
| |
| 49 kSystemProfileProto, | |
| 50 }; | |
| 51 | |
| 52 // A class for managing record allocations inside a persistent memory segment. | |
| 53 class RecordAllocator { | |
| 54 public: | |
| 55 // Construct an allocator for writing. | |
| 56 RecordAllocator(base::PersistentMemoryAllocator* memory_allocator, | |
| 57 size_t min_size); | |
| 58 | |
| 59 // Construct an allocator for reading. | |
| 60 RecordAllocator(const base::PersistentMemoryAllocator* memory_allocator); | |
| 61 | |
| 62 bool Matches(const base::PersistentMemoryAllocator* allocator) const; | |
|
Alexei Svitkine (slow)
2017/05/26 18:01:53
Nit: Add a comment.
Alternatively, how about just
bcwhite
2017/05/29 18:32:26
Done.
| |
| 63 | |
| 64 // These methods manage writing records to the allocator. Do not mix these | |
| 65 // with "read" calls; it's one or the other. | |
| 66 void Reset(); | |
|
Alexei Svitkine (slow)
2017/05/26 18:01:53
Given you always call Reset() before Write(), how
bcwhite
2017/05/29 18:32:26
Once there are more record types than just the sys
| |
| 67 bool Write(RecordType type, const std::string& record); | |
| 68 | |
| 69 // Read a record from the allocator. Do not mix this with "write" calls; | |
| 70 // it's one or the other. | |
| 71 bool Read(RecordType* type, std::string* record) const; | |
| 72 | |
| 73 private: | |
| 74 // Advance to the next record segment in the memory allocator. | |
| 75 bool NextSegment() const; | |
| 76 | |
| 77 // Advance to the next record segment, creating a new one if necessary with | |
| 78 // sufficent |min_size| space. | |
| 79 bool AddSegment(size_t min_size); | |
| 80 | |
| 81 // This never changes but can't be "const" because vector calls operator=(). | |
| 82 base::PersistentMemoryAllocator* allocator_; // Storage location. | |
| 83 | |
| 84 // These change even though the underlying data may be "const". | |
| 85 mutable uint32_t tail_reference_; // Last storage block. | |
| 86 mutable uint32_t end_offset_; // End of data in block. | |
|
Alexei Svitkine (slow)
2017/05/26 18:01:53
This field is not clear to me.
Why is it an offse
bcwhite
2017/05/29 18:32:26
It follows the STL begin/end naming. It's not str
| |
| 87 | |
| 88 // Copy and assign are allowed for easy use with STL containers. | |
| 89 }; | |
| 90 | |
| 91 // The list of registered persistent allocators, described by RecordAllocator | |
| 92 // instances. | |
| 93 std::vector<RecordAllocator> allocators_; | |
| 94 | |
| 95 THREAD_CHECKER(thread_checker_); | |
|
Alexei Svitkine (slow)
2017/05/26 18:01:53
Nit: Make this the first member.
bcwhite
2017/05/29 18:32:26
Typically its the last member.
Alexei Svitkine (slow)
2017/05/29 19:48:32
That's not been my experience back with ThreadChec
bcwhite
2017/05/29 20:56:35
I checked a 1/2 dozen files before replying and al
| |
| 96 | |
| 97 DISALLOW_COPY_AND_ASSIGN(PersistentSystemProfile); | |
| 98 }; | |
| 99 | |
| 100 } // namespace metrics | |
| 101 | |
| 102 #endif // BASE_METRICS_PERSISTENT_SYSTEM_PROFILE_H_ | |
| OLD | NEW |