summaryrefslogtreecommitdiffstats
path: root/cc/memory_history.h
blob: ddf6a0fbcca344f56438bef24f2e2657b4f89c3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_MEMORY_HISTORY_H_
#define CC_MEMORY_HISTORY_H_

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/time.h"
#include "cc/ring_buffer.h"

namespace cc {

// Maintains a history of memory for each frame
class MemoryHistory {
 public:
  static scoped_ptr<MemoryHistory> create();

  size_t HistorySize() const { return ring_buffer_.BufferSize(); }

  struct Entry {
  Entry()
      : total_budget_in_bytes(0),
        bytes_allocated(0),
        bytes_unreleasable(0),
        bytes_over(0) { }

      size_t total_budget_in_bytes;
      size_t bytes_allocated;
      size_t bytes_unreleasable;
      size_t bytes_over;
      size_t bytes_total() const {
          return bytes_allocated +
              bytes_unreleasable +
              bytes_over;
      }
  };

  void SaveEntry(const Entry& entry);
  void GetMinAndMax(size_t* min, size_t* max) const;

  typedef RingBuffer<Entry, 80> RingBufferType;
  RingBufferType::Iterator Begin() const { return ring_buffer_.Begin(); }
  RingBufferType::Iterator End() const { return ring_buffer_.End(); }

 private:
  MemoryHistory();

  RingBufferType ring_buffer_;

  DISALLOW_COPY_AND_ASSIGN(MemoryHistory);
};

}  // namespace cc

#endif  // CC_MEMORY_HISTORY_H_