1 // Copyright 2009 The Chromium Authors
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"
11 #include "base/strings/stringprintf.h"
15 H() { inH = false; tick_ = 0; bw_ = 0; d_bw_ = d_tick_ = 0; m_bw_ = 0; mem_ = high_ = 0;}
19 for (M::iterator p = m_.begin(); p != m_.end(); ++p, ++i) {
21 LOG(INFO) << base::StringPrintf("%3d %8u: %8u %8u %8u %8u", i, s,
22 m_[s], c_[s], h_[s], h_[s] * s);
24 LOG(INFO) << "Peak " << fmt(high_);
27 std::string fmt(size_t s) {
28 if (s > 1000000000) return base::StringPrintf("%.3gG", s/(1000000000.0));
29 if (s > 1000000) return base::StringPrintf("%.3gM", s/(1000000.));
30 if (s > 9999) return base::StringPrintf("%.3gk", s/(1000.));
31 return base::NumberToString(s);
34 void tick(size_t w, char sign) {
37 const size_t T = 4*4*1024;
38 const size_t M = 4*1024*1024;
41 tick_ += (d_tick_/T)*T;
52 base::StringAppendF(&o, "%u:", tick_ + d_tick_);
53 base::StringAppendF(&o, " (%c%s)", sign, fmt(w).c_str());
55 for (M::iterator p = c_.begin(); p != c_.end(); ++p) {
61 base::StringAppendF(&o, " %s", fmt(s).c_str());
63 base::StringAppendF(&o, " %s*%u", fmt(s).c_str(), n);
67 base::StringAppendF(&o, " = %s", fmt(sum).c_str());
69 //printf("%s\n", o.c_str());
70 if (sum > 200*1024*1024) {
75 void add(size_t s, void *p) {
78 mem_ += s; if (mem_ > high_) high_ = mem_;
81 if (c_[s] > h_[s]) h_[s] = c_[s];
91 size_t s = allocs_[p];
102 typedef std::map<size_t, size_t> M;
115 std::map<void*, size_t> allocs_;
118 void* operator new(size_t s) {
125 void operator delete(void *p) {