Skip to content

Commit a4f13ec

Browse files
Thiabaud Engelbrechtcopybara-github
authored andcommitted
[base/histograms] Add ByteCount overloads of memory metric functions
Most callsites of these histogram functions do a conversion to KB or MB, so we add overloads of these functions to allow avoiding doing this conversion explicitly in the future. NO_IFTTT=per comments from reviewer, this CL is only adding the function versions. Bug: 429140103 Change-Id: I2b0e49e7667f62ca89f4d1d90db943305a947b11 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6728222 Reviewed-by: Alexei Svitkine <[email protected]> Commit-Queue: Thiabaud Engelbrecht <[email protected]> Cr-Commit-Position: refs/heads/main@{#1500187} NOKEYCHECK=True GitOrigin-RevId: 7b11c486f4e8032ec9d07981f4f753c38f1491a5
1 parent c54dff7 commit a4f13ec

File tree

3 files changed

+77
-26
lines changed

3 files changed

+77
-26
lines changed

metrics/histogram_functions.cc

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -311,40 +311,76 @@ void UmaHistogramMicrosecondsTimes(const char* name, TimeDelta sample) {
311311
Seconds(10), 50);
312312
}
313313

314-
void UmaHistogramMemoryKB(std::string_view name, int sample) {
315-
UmaHistogramCustomCounts(name, sample, 1000, 500000, 50);
314+
void UmaHistogramMemoryKB(std::string_view name, int sample_kb) {
315+
UmaHistogramCustomCounts(name, sample_kb, 1000, 500000, 50);
316316
}
317317

318-
void UmaHistogramMemoryKB(const std::string& name, int sample) {
319-
UmaHistogramCustomCounts(name, sample, 1000, 500000, 50);
318+
void UmaHistogramMemoryKB(const std::string& name, int sample_kb) {
319+
UmaHistogramCustomCounts(name, sample_kb, 1000, 500000, 50);
320320
}
321321

322-
void UmaHistogramMemoryKB(const char* name, int sample) {
323-
UmaHistogramCustomCounts(name, sample, 1000, 500000, 50);
322+
void UmaHistogramMemoryKB(const char* name, int sample_kb) {
323+
UmaHistogramCustomCounts(name, sample_kb, 1000, 500000, 50);
324324
}
325325

326-
void UmaHistogramMemoryMB(std::string_view name, int sample) {
327-
UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
326+
void UmaHistogramMemoryKB(std::string_view name, ByteCount sample) {
327+
UmaHistogramMemoryKB(name, static_cast<int>(sample.InKiB()));
328328
}
329329

330-
void UmaHistogramMemoryMB(const std::string& name, int sample) {
331-
UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
330+
void UmaHistogramMemoryKB(const std::string& name, ByteCount sample) {
331+
UmaHistogramMemoryKB(name, static_cast<int>(sample.InKiB()));
332332
}
333333

334-
void UmaHistogramMemoryMB(const char* name, int sample) {
335-
UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
334+
void UmaHistogramMemoryKB(const char* name, ByteCount sample) {
335+
UmaHistogramMemoryKB(name, static_cast<int>(sample.InKiB()));
336+
}
337+
338+
void UmaHistogramMemoryMB(std::string_view name, int sample_mb) {
339+
UmaHistogramCustomCounts(name, sample_mb, 1, 1000, 50);
340+
}
341+
342+
void UmaHistogramMemoryMB(const std::string& name, int sample_mb) {
343+
UmaHistogramCustomCounts(name, sample_mb, 1, 1000, 50);
344+
}
345+
346+
void UmaHistogramMemoryMB(const char* name, int sample_mb) {
347+
UmaHistogramCustomCounts(name, sample_mb, 1, 1000, 50);
348+
}
349+
350+
void UmaHistogramMemoryMB(std::string_view name, ByteCount sample) {
351+
UmaHistogramMemoryMB(name, static_cast<int>(sample.InMiB()));
352+
}
353+
354+
void UmaHistogramMemoryMB(const std::string& name, ByteCount sample) {
355+
UmaHistogramMemoryMB(name, static_cast<int>(sample.InMiB()));
356+
}
357+
358+
void UmaHistogramMemoryMB(const char* name, ByteCount sample) {
359+
UmaHistogramMemoryMB(name, static_cast<int>(sample.InMiB()));
360+
}
361+
362+
void UmaHistogramMemoryLargeMB(std::string_view name, int sample_mb) {
363+
UmaHistogramCustomCounts(name, sample_mb, 1, 64000, 100);
364+
}
365+
366+
void UmaHistogramMemoryLargeMB(const std::string& name, int sample_mb) {
367+
UmaHistogramCustomCounts(name, sample_mb, 1, 64000, 100);
368+
}
369+
370+
void UmaHistogramMemoryLargeMB(const char* name, int sample_mb) {
371+
UmaHistogramCustomCounts(name, sample_mb, 1, 64000, 100);
336372
}
337373

338-
void UmaHistogramMemoryLargeMB(std::string_view name, int sample) {
339-
UmaHistogramCustomCounts(name, sample, 1, 64000, 100);
374+
void UmaHistogramMemoryLargeMB(std::string_view name, ByteCount sample) {
375+
UmaHistogramMemoryLargeMB(name, static_cast<int>(sample.InMiB()));
340376
}
341377

342-
void UmaHistogramMemoryLargeMB(const std::string& name, int sample) {
343-
UmaHistogramCustomCounts(name, sample, 1, 64000, 100);
378+
void UmaHistogramMemoryLargeMB(const std::string& name, ByteCount sample) {
379+
UmaHistogramMemoryLargeMB(name, static_cast<int>(sample.InMiB()));
344380
}
345381

346-
void UmaHistogramMemoryLargeMB(const char* name, int sample) {
347-
UmaHistogramCustomCounts(name, sample, 1, 64000, 100);
382+
void UmaHistogramMemoryLargeMB(const char* name, ByteCount sample) {
383+
UmaHistogramMemoryLargeMB(name, static_cast<int>(sample.InMiB()));
348384
}
349385

350386
void UmaHistogramSparse(std::string_view name, int sample) {

metrics/histogram_functions.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <type_traits>
1313

1414
#include "base/base_export.h"
15+
#include "base/byte_count.h"
1516
#include "base/check_op.h"
1617
#include "base/metrics/histogram.h"
1718
#include "base/metrics/histogram_base.h"
@@ -195,15 +196,19 @@ BASE_EXPORT void UmaHistogramMicrosecondsTimes(std::string_view name,
195196
// For recording memory-related histograms.
196197
// LINT.IfChange(UmaHistogramMemory)
197198
//
198-
// Used to measure common KB-granularity memory stats. Sample is in KB. Range is
199-
// from 1000KB (see crbug.com/40526504) to 500M. For measuring sizes less than
200-
// 1000K, use `UmaHistogramCounts`.
201-
BASE_EXPORT void UmaHistogramMemoryKB(std::string_view name, int sample);
202-
// Used to measure common MB-granularity memory stats. Sample is in MB. Range is
203-
// 1MB to ~1G.
204-
BASE_EXPORT void UmaHistogramMemoryMB(std::string_view name, int sample);
199+
// Used to measure common KB-granularity memory stats. Range is from 1000KB
200+
// (see crbug.com/40526504) to 500M. For measuring sizes less than 1000K, use
201+
// `UmaHistogramCounts`.
202+
BASE_EXPORT void UmaHistogramMemoryKB(std::string_view name, int sample_kb);
203+
BASE_EXPORT void UmaHistogramMemoryKB(std::string_view name, ByteCount sample);
204+
// Used to measure common MB-granularity memory stats. Range is 1MB to ~1G.
205+
BASE_EXPORT void UmaHistogramMemoryMB(std::string_view name, int sample_mb);
206+
BASE_EXPORT void UmaHistogramMemoryMB(std::string_view name, ByteCount sample);
205207
// Used to measure common MB-granularity memory stats. Range is 1MB to ~64G.
206-
BASE_EXPORT void UmaHistogramMemoryLargeMB(std::string_view name, int sample);
208+
BASE_EXPORT void UmaHistogramMemoryLargeMB(std::string_view name,
209+
int sample_mb);
210+
BASE_EXPORT void UmaHistogramMemoryLargeMB(std::string_view name,
211+
ByteCount sample);
207212
// LINT.ThenChange(/base/metrics/histogram_functions_internal_overloads.h:UmaHistogramMemory)
208213

209214
// For recording sparse histograms.

metrics/histogram_functions_internal_overloads.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <type_traits>
1515

1616
#include "base/base_export.h"
17+
#include "base/byte_count.h"
1718
#include "base/check_op.h"
1819
#include "base/metrics/histogram.h"
1920
#include "base/metrics/histogram_base.h"
@@ -180,12 +181,21 @@ BASE_EXPORT void UmaHistogramMicrosecondsTimes(const char* name,
180181
// LINT.IfChange(UmaHistogramMemory)
181182
BASE_EXPORT void UmaHistogramMemoryKB(const std::string& name, int sample);
182183
BASE_EXPORT void UmaHistogramMemoryKB(const char* name, int sample);
184+
BASE_EXPORT void UmaHistogramMemoryKB(const std::string& name,
185+
ByteCount sample);
186+
BASE_EXPORT void UmaHistogramMemoryKB(const char* name, ByteCount sample);
183187

184188
BASE_EXPORT void UmaHistogramMemoryMB(const std::string& name, int sample);
185189
BASE_EXPORT void UmaHistogramMemoryMB(const char* name, int sample);
190+
BASE_EXPORT void UmaHistogramMemoryMB(const std::string& name,
191+
ByteCount sample);
192+
BASE_EXPORT void UmaHistogramMemoryMB(const char* name, ByteCount sample);
186193

187194
BASE_EXPORT void UmaHistogramMemoryLargeMB(const std::string& name, int sample);
188195
BASE_EXPORT void UmaHistogramMemoryLargeMB(const char* name, int sample);
196+
BASE_EXPORT void UmaHistogramMemoryLargeMB(const std::string& name,
197+
ByteCount sample);
198+
BASE_EXPORT void UmaHistogramMemoryLargeMB(const char* name, ByteCount sample);
189199
// LINT.ThenChange(/base/metrics/histogram_functions.h:UmaHistogramMemory)
190200

191201
// LINT.IfChange(UmaHistogramSparse)

0 commit comments

Comments
 (0)