Chromium Code Reviews| Index: base/trace_event/memory_peak_detector.h |
| diff --git a/base/trace_event/memory_peak_detector.h b/base/trace_event/memory_peak_detector.h |
| index b91429583322549619e7f91da7eb45af953696aa..8de615e64bdff165e5fb6d917d1ecfe00c87208a 100644 |
| --- a/base/trace_event/memory_peak_detector.h |
| +++ b/base/trace_event/memory_peak_detector.h |
| @@ -23,6 +23,13 @@ namespace trace_event { |
| struct MemoryDumpProviderInfo; |
| +// Detects temporally local memory peaks. Peak detection is based on |
| +// continuously querying memory usage using MemoryDumpprovider(s) that support |
| +// fast polling (e.g., ProcessMetricsDumpProvider which under the hoods reads |
| +// /proc/PID/statm on Linux) and using a cobination of: |
| +// - An static threshold (currently 1% of total system memory). |
| +// - Sliding window stddev analysis. |
| +// Design doc: https://goo.gl/0kOU4A . |
| // This class is NOT thread-safe, the caller has to ensure linearization of |
| // the calls to the public methods. In any case, the public methods do NOT have |
| // to be called from the |task_runner| on which the polling tasks run. |
| @@ -39,6 +46,21 @@ class BASE_EXPORT MemoryPeakDetector { |
| RUNNING // After Start(). The PollMemoryAndDetectPeak() task is scheduled. |
| }; |
| + // Peak detector configuration, passed to Start(). |
| + struct Config { |
| + // The rate at which memory will be polled. Polls will happen on the task |
| + // runner passed to Setup(). |
| + uint32_t polling_interval_ms; |
| + |
| + // Guarantees that a peak detection callback will never before than the |
|
ssid
2017/04/10 20:55:06
"will never before than"?
Primiano Tucci (use gerrit)
2017/04/11 11:12:09
reworded
|
| + // specified amount of time from the last one. |
| + uint32_t min_time_between_peaks_ms; |
| + |
| + // When enabled causes a TRACE_COUNTER event to be injected in the trace |
| + // for each poll (if tracing is enabled). |
| + bool enable_verbose_poll_tracing; |
| + }; |
| + |
| static MemoryPeakDetector* GetInstance(); |
| // Configures the peak detector, binding the polling tasks on the given |
| @@ -66,7 +88,7 @@ class BASE_EXPORT MemoryPeakDetector { |
| // If not, the detector remains in the ENABLED state and will start polling |
| // automatically (i.e. without requiring another call to Start()) on the |
| // next call to NotifyMemoryDumpProvidersChanged(). |
| - void Start(); |
| + void Start(Config); |
| // Stops the polling on the task runner (if was active at all). This doesn't |
| // wait for the task runner to drain pending tasks, so it is possible that |
| @@ -75,24 +97,36 @@ class BASE_EXPORT MemoryPeakDetector { |
| // with the task runner. |
| void Stop(); |
| + // Clears the history of the peak detector, both for the sliding window and |
| + // static threshold logic, if Start()-ed, otherwise it's a no-op. The intended |
| + // use case is to prevent that a memory dump is triggered due to peak |
| + // detection soon after another dump has been triggered for other reasons. |
| + void Clear(); |
| + |
| // Used by MemoryDumpManager to notify that the list of polling-capable dump |
| // providers has changed. The peak detector will reload the list on the next |
| // polling task. This function can be called before Setup(), in which |
| // case will be just a no-op. |
| void NotifyMemoryDumpProvidersChanged(); |
| + void SetStaticThresholdForTesting(uint64_t static_threshold_bytes); |
| + |
| private: |
| friend class MemoryPeakDetectorTest; |
| + static constexpr uint32_t kSlidingWindowNumSamples = 50; |
| + |
| MemoryPeakDetector(); |
| ~MemoryPeakDetector(); |
| // All these methods are always called on the |task_runner_|. |
| - void StartInternal(); |
| + void StartInternal(Config); |
| void StopInternal(); |
| void TearDownInternal(); |
| void ReloadDumpProvidersAndStartPollingIfNeeded(); |
| void PollMemoryAndDetectPeak(uint32_t expected_generation); |
| + bool DetectPeakUsingSlidingWindowStddev(uint64_t last_sample_bytes); |
| + void ResetPollHistory(); |
| // It is safe to call these testing methods only on the |task_runner_|. |
| State state_for_testing() const { return state_; } |
| @@ -127,7 +161,15 @@ class BASE_EXPORT MemoryPeakDetector { |
| uint32_t generation_; |
| State state_; |
| - uint32_t polling_interval_ms_; |
| + |
| + // Config passed to Start(), only valid when |state_| = {ENABLED, RUNNING}. |
| + Config config_; |
| + |
| + int64_t static_threshold_bytes_; |
| + uint32_t skip_polls_; |
| + uint64_t last_dump_memory_total_; |
| + uint64_t samples_bytes_[kSlidingWindowNumSamples]; |
| + uint32_t samples_index_; |
| uint32_t poll_tasks_count_for_testing_; |
| DISALLOW_COPY_AND_ASSIGN(MemoryPeakDetector); |