diff options
-rw-r--r-- | base/metrics/histogram.cc | 8 | ||||
-rw-r--r-- | base/metrics/histogram.h | 50 | ||||
-rw-r--r-- | chrome/browser/spellchecker/spellchecker_mac.mm | 6 | ||||
-rw-r--r-- | chrome/renderer/spellchecker/spellcheck.cc | 4 |
4 files changed, 55 insertions, 13 deletions
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc index dbd7278..8b11ee8 100644 --- a/base/metrics/histogram.cc +++ b/base/metrics/histogram.cc @@ -114,6 +114,14 @@ Histogram* Histogram::FactoryTimeGet(const std::string& name, bucket_count, flags); } +TimeTicks Histogram::DebugNow() { +#ifndef NDEBUG + return TimeTicks::Now(); +#else + return TimeTicks(); +#endif +} + void Histogram::Add(int value) { if (value > kSampleType_MAX - 1) value = kSampleType_MAX - 1; diff --git a/base/metrics/histogram.h b/base/metrics/histogram.h index 401ece7..e8f6364 100644 --- a/base/metrics/histogram.h +++ b/base/metrics/histogram.h @@ -202,19 +202,50 @@ class Lock; HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) #else // NDEBUG +// Keep a mention of passed variables to avoid unused variable warnings in +// release build if these variables are only used in macros. +#define DISCARD_2_ARGUMENTS(a, b) \ + while (0) { \ + static_cast<void>(a); \ + static_cast<void>(b); \ + } +#define DISCARD_3_ARGUMENTS(a, b, c) \ + while (0) { \ + static_cast<void>(a); \ + static_cast<void>(b); \ + static_cast<void>(c); \ + } +#define DISCARD_5_ARGUMENTS(a, b, c, d ,e) \ + while (0) { \ + static_cast<void>(a); \ + static_cast<void>(b); \ + static_cast<void>(c); \ + static_cast<void>(d); \ + static_cast<void>(e); \ + } +#define DHISTOGRAM_TIMES(name, sample) \ + DISCARD_2_ARGUMENTS(name, sample) + +#define DHISTOGRAM_COUNTS(name, sample) \ + DISCARD_2_ARGUMENTS(name, sample) + +#define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) \ + DISCARD_2_ARGUMENTS(name, under_one_hundred) -#define DHISTOGRAM_TIMES(name, sample) do {} while (0) -#define DHISTOGRAM_COUNTS(name, sample) do {} while (0) -#define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) do {} while (0) #define DHISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ - do {} while (0) + DISCARD_5_ARGUMENTS(name, sample, min, max, bucket_count) + #define DHISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) \ - do {} while (0) + DISCARD_5_ARGUMENTS(name, sample, min, max, bucket_count) + #define DHISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \ - do {} while (0) -#define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) do {} while (0) + DISCARD_5_ARGUMENTS(name, sample, min, max, bucket_count) + +#define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) \ + DISCARD_3_ARGUMENTS(name, sample, boundary_value) + #define DHISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \ - do {} while (0) + DISCARD_3_ARGUMENTS(name, sample, custom_ranges) #endif // NDEBUG @@ -409,6 +440,9 @@ class BASE_EXPORT Histogram { base::TimeDelta maximum, size_t bucket_count, Flags flags); + // Time call for use with DHISTOGRAM*. + // Returns TimeTicks::Now() in debug and TimeTicks() in release build. + static TimeTicks DebugNow(); void Add(int value); diff --git a/chrome/browser/spellchecker/spellchecker_mac.mm b/chrome/browser/spellchecker/spellchecker_mac.mm index fa9c049..a9dcc73 100644 --- a/chrome/browser/spellchecker/spellchecker_mac.mm +++ b/chrome/browser/spellchecker/spellchecker_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -245,12 +245,12 @@ bool CheckSpelling(const string16& word_to_check, int tag) { void FillSuggestionList(const string16& wrong_word, std::vector<string16>* optional_suggestions) { NSString* NS_wrong_word = base::SysUTF16ToNSString(wrong_word); - TimeTicks begin_time = TimeTicks::Now(); + TimeTicks debug_begin_time = base::Histogram::DebugNow(); // The suggested words for |wrong_word|. NSArray* guesses = [[NSSpellChecker sharedSpellChecker] guessesForWord:NS_wrong_word]; DHISTOGRAM_TIMES("Spellcheck.SuggestTime", - TimeTicks::Now() - begin_time); + base::Histogram::DebugNow() - debug_begin_time); for (int i = 0; i < static_cast<int>([guesses count]); i++) { if (i < SpellCheckCommon::kMaxSuggestions) { diff --git a/chrome/renderer/spellchecker/spellcheck.cc b/chrome/renderer/spellchecker/spellcheck.cc index fb87366..952c2a7 100644 --- a/chrome/renderer/spellchecker/spellcheck.cc +++ b/chrome/renderer/spellchecker/spellcheck.cc @@ -195,7 +195,7 @@ void SpellCheck::InitializeHunspell() { bdict_file_.reset(new file_util::MemoryMappedFile); if (bdict_file_->Initialize(file_)) { - TimeTicks start_time = TimeTicks::Now(); + TimeTicks debug_start_time = base::Histogram::DebugNow(); hunspell_.reset( new Hunspell(bdict_file_->data(), bdict_file_->length())); @@ -207,7 +207,7 @@ void SpellCheck::InitializeHunspell() { } DHISTOGRAM_TIMES("Spellcheck.InitTime", - TimeTicks::Now() - start_time); + base::Histogram::DebugNow() - debug_start_time); } else { NOTREACHED() << "Could not mmap spellchecker dictionary."; } |