1 // Copyright 2015 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_TRACE_EVENT_PROCESS_MEMORY_TOTALS_H_
6 #define BASE_TRACE_EVENT_PROCESS_MEMORY_TOTALS_H_
7 
8 #include <stdint.h>
9 
10 #include <map>
11 
12 #include "base/base_export.h"
13 #include "base/macros.h"
14 
15 namespace base {
16 namespace trace_event {
17 
18 class TracedValue;
19 
20 // Data model for process-wide memory stats.
21 class BASE_EXPORT ProcessMemoryTotals {
22  public:
23   ProcessMemoryTotals();
24   ~ProcessMemoryTotals();
25 
26   // Called at trace generation time to populate the TracedValue.
27   void AsValueInto(TracedValue* value) const;
28 
29   // Clears up all the data collected.
30   void Clear();
31 
32   uint64_t resident_set_bytes() const { return resident_set_bytes_; }
33   void set_resident_set_bytes(uint64_t value) { resident_set_bytes_ = value; }
34 
35   uint64_t peak_resident_set_bytes() const { return peak_resident_set_bytes_; }
36   void set_peak_resident_set_bytes(uint64_t value) {
37     peak_resident_set_bytes_ = value;
38   }
39 
40   // On some platforms (recent linux kernels, see goo.gl/sMvAVz) the peak rss
41   // can be reset. When is_peak_rss_resettable == true, the peak refers to
42   // peak from the previous measurement. When false, it is the absolute peak
43   // since the start of the process.
44   bool is_peak_rss_resetable() const { return is_peak_rss_resetable_; }
45   void set_is_peak_rss_resetable(bool value) { is_peak_rss_resetable_ = value; }
46 
47   void SetExtraFieldInBytes(const char* name, uint64_t value);
48 
49  private:
50   uint64_t resident_set_bytes_;
51   uint64_t peak_resident_set_bytes_;
52   bool is_peak_rss_resetable_;
53 
54   // Extra metrics for OS-specific statistics.
55   std::map<const char*, uint64_t> extra_fields_;
56 
57   DISALLOW_COPY_AND_ASSIGN(ProcessMemoryTotals);
58 };
59 
60 }  // namespace trace_event
61 }  // namespace base
62 
63 #endif  // BASE_TRACE_EVENT_PROCESS_MEMORY_TOTALS_H_
64