OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 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 #include "cc/memory_history.h" |
| 6 |
| 7 namespace cc { |
| 8 |
| 9 // static |
| 10 scoped_ptr<MemoryHistory> MemoryHistory::create() { |
| 11 return make_scoped_ptr(new MemoryHistory()); |
| 12 } |
| 13 |
| 14 MemoryHistory::MemoryHistory() { |
| 15 } |
| 16 |
| 17 MemoryHistory::Entry MemoryHistory::GetEntry(const size_t& n) const { |
| 18 DCHECK(n < ring_buffer_.BufferSize()); |
| 19 |
| 20 if (ring_buffer_.IsFilledIndex(n)) |
| 21 return ring_buffer_.ReadBuffer(n); |
| 22 |
| 23 return MemoryHistory::Entry(); |
| 24 } |
| 25 |
| 26 void MemoryHistory::SaveEntry(const MemoryHistory::Entry& entry) { |
| 27 ring_buffer_.SaveToBuffer(entry); |
| 28 } |
| 29 |
| 30 void MemoryHistory::GetMinAndMax(size_t* min, size_t* max) const { |
| 31 *min = std::numeric_limits<size_t>::max(); |
| 32 *max = 0; |
| 33 |
| 34 for (size_t i = 0; i < ring_buffer_.BufferSize(); i++) { |
| 35 if (!ring_buffer_.IsFilledIndex(i)) |
| 36 continue; |
| 37 const Entry entry = ring_buffer_.ReadBuffer(i); |
| 38 size_t bytes_total = entry.bytes_total(); |
| 39 |
| 40 if (bytes_total < *min) |
| 41 *min = bytes_total; |
| 42 if (bytes_total > *max) |
| 43 *max = bytes_total; |
| 44 } |
| 45 |
| 46 if (*min > *max) |
| 47 *min = *max; |
| 48 } |
| 49 |
| 50 } // namespace cc |
OLD | NEW |