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.
8 #include "base/logging.h"
9 #include "base/strings/string_util.h"
13 H() { inH
= false; tick_
= 0; bw_
= 0; d_bw_
= d_tick_
= 0; m_bw_
= 0; mem_
= high_
= 0;}
17 for (M::iterator p
= m_
.begin(); p
!= m_
.end(); ++p
, ++i
) {
19 LOG(INFO
) << base::StringPrintf("%3d %8u: %8u %8u %8u %8u", i
, s
,
20 m_
[s
], c_
[s
], h_
[s
], h_
[s
] * s
);
22 LOG(INFO
) << "Peak " << fmt(high_
);
25 std::string
fmt(size_t s
) {
26 if (s
> 1000000000) return base::StringPrintf("%.3gG", s
/(1000000000.0));
27 if (s
> 1000000) return base::StringPrintf("%.3gM", s
/(1000000.));
28 if (s
> 9999) return base::StringPrintf("%.3gk", s
/(1000.));
29 return base::IntToString((int)s
);
32 void tick(size_t w
, char sign
) {
35 const size_t T
= 4*4*1024;
36 const size_t M
= 4*1024*1024;
39 tick_
+= (d_tick_
/T
)*T
;
50 base::StringAppendF(&o
, "%u:", tick_
+ d_tick_
);
51 base::StringAppendF(&o
, " (%c%s)", sign
, fmt(w
).c_str());
53 for (M::iterator p
= c_
.begin(); p
!= c_
.end(); ++p
) {
59 base::StringAppendF(&o
, " %s", fmt(s
).c_str());
61 base::StringAppendF(&o
, " %s*%u", fmt(s
).c_str(), n
);
65 base::StringAppendF(&o
, " = %s", fmt(sum
).c_str());
67 //printf("%s\n", o.c_str());
68 if (sum
> 200*1024*1024) {
73 void add(size_t s
, void *p
) {
76 mem_
+= s
; if (mem_
> high_
) high_
= mem_
;
79 if (c_
[s
] > h_
[s
]) h_
[s
] = c_
[s
];
89 size_t s
= allocs_
[p
];
100 typedef std::map
<size_t, size_t> M
;
113 std::map
<void*, size_t> allocs_
;
116 void* operator new(size_t s
) {
123 void operator delete(void *p
) {