1 // Copyright (c) 2009 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.
9 #include "base/logging.h"
10 #include "base/strings/string_util.h"
14 H() { inH = false; tick_ = 0; bw_ = 0; d_bw_ = d_tick_ = 0; m_bw_ = 0; mem_ = high_ = 0;}
18 for (M::iterator p = m_.begin(); p != m_.end(); ++p, ++i) {
20 LOG(INFO) << base::StringPrintf("%3d %8u: %8u %8u %8u %8u", i, s,
21 m_[s], c_[s], h_[s], h_[s] * s);
23 LOG(INFO) << "Peak " << fmt(high_);
26 std::string fmt(size_t s) {
27 if (s > 1000000000) return base::StringPrintf("%.3gG", s/(1000000000.0));
28 if (s > 1000000) return base::StringPrintf("%.3gM", s/(1000000.));
29 if (s > 9999) return base::StringPrintf("%.3gk", s/(1000.));
30 return base::IntToString((int)s);
33 void tick(size_t w, char sign) {
36 const size_t T = 4*4*1024;
37 const size_t M = 4*1024*1024;
40 tick_ += (d_tick_/T)*T;
51 base::StringAppendF(&o, "%u:", tick_ + d_tick_);
52 base::StringAppendF(&o, " (%c%s)", sign, fmt(w).c_str());
54 for (M::iterator p = c_.begin(); p != c_.end(); ++p) {
60 base::StringAppendF(&o, " %s", fmt(s).c_str());
62 base::StringAppendF(&o, " %s*%u", fmt(s).c_str(), n);
66 base::StringAppendF(&o, " = %s", fmt(sum).c_str());
68 //printf("%s\n", o.c_str());
69 if (sum > 200*1024*1024) {
74 void add(size_t s, void *p) {
77 mem_ += s; if (mem_ > high_) high_ = mem_;
80 if (c_[s] > h_[s]) h_[s] = c_[s];
90 size_t s = allocs_[p];
101 typedef std::map<size_t, size_t> M;
114 std::map<void*, size_t> allocs_;
117 void* operator new(size_t s) {
124 void operator delete(void *p) {