Use string for Histogram names since these are all ASCII anyway.
Wide-character literals cause problems between platforms.
Review URL: http://codereview.chromium.org/28046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10276 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: 553dba6dd707ee02e609910462d2b7977f284af2
diff --git a/base/histogram.cc b/base/histogram.cc
index 173cf40..79e9497 100644
--- a/base/histogram.cc
+++ b/base/histogram.cc
@@ -23,10 +23,10 @@
// static
const int Histogram::kHexRangePrintingFlag = 0x8000;
-Histogram::Histogram(const wchar_t* name, Sample minimum,
+Histogram::Histogram(const char* name, Sample minimum,
Sample maximum, size_t bucket_count)
- : StatsRate(WideToASCII(name).c_str()),
- histogram_name_(WideToASCII(name)),
+ : StatsRate(name),
+ histogram_name_(name),
declared_min_(minimum),
declared_max_(maximum),
bucket_count_(bucket_count),
@@ -37,10 +37,10 @@
Initialize();
}
-Histogram::Histogram(const wchar_t* name, TimeDelta minimum,
+Histogram::Histogram(const char* name, TimeDelta minimum,
TimeDelta maximum, size_t bucket_count)
- : StatsRate(WideToASCII(name).c_str()),
- histogram_name_(WideToASCII(name)),
+ : StatsRate(name),
+ histogram_name_(name),
declared_min_(static_cast<int> (minimum.InMilliseconds())),
declared_max_(static_cast<int> (maximum.InMilliseconds())),
bucket_count_(bucket_count),
@@ -415,14 +415,14 @@
// buckets.
//------------------------------------------------------------------------------
-LinearHistogram::LinearHistogram(const wchar_t* name,
+LinearHistogram::LinearHistogram(const char* name,
Sample minimum, Sample maximum, size_t bucket_count)
: Histogram(name, minimum >= 1 ? minimum : 1, maximum, bucket_count) {
InitializeBucketRange();
DCHECK(ValidateBucketRanges());
}
-LinearHistogram::LinearHistogram(const wchar_t* name,
+LinearHistogram::LinearHistogram(const char* name,
TimeDelta minimum, TimeDelta maximum, size_t bucket_count)
: Histogram(name, minimum >= TimeDelta::FromMilliseconds(1) ?
minimum : TimeDelta::FromMilliseconds(1),
@@ -487,7 +487,7 @@
// This section provides implementation for ThreadSafeHistogram.
//------------------------------------------------------------------------------
-ThreadSafeHistogram::ThreadSafeHistogram(const wchar_t* name, Sample minimum,
+ThreadSafeHistogram::ThreadSafeHistogram(const char* name, Sample minimum,
Sample maximum, size_t bucket_count)
: Histogram(name, minimum, maximum, bucket_count),
lock_() {
@@ -650,4 +650,3 @@
Lock* StatisticsRecorder::lock_ = NULL;
// static
bool StatisticsRecorder::dump_on_exit_ = false;
-
diff --git a/base/histogram.h b/base/histogram.h
index 624f80a..cf80c09 100644
--- a/base/histogram.h
+++ b/base/histogram.h
@@ -218,9 +218,9 @@
};
//----------------------------------------------------------------------------
- Histogram(const wchar_t* name, Sample minimum,
+ Histogram(const char* name, Sample minimum,
Sample maximum, size_t bucket_count);
- Histogram(const wchar_t* name, base::TimeDelta minimum,
+ Histogram(const char* name, base::TimeDelta minimum,
base::TimeDelta maximum, size_t bucket_count);
virtual ~Histogram();
@@ -357,9 +357,9 @@
Sample sample;
const char* description; // Null means end of a list of pairs.
};
- LinearHistogram(const wchar_t* name, Sample minimum,
+ LinearHistogram(const char* name, Sample minimum,
Sample maximum, size_t bucket_count);
- LinearHistogram(const wchar_t* name, base::TimeDelta minimum,
+ LinearHistogram(const char* name, base::TimeDelta minimum,
base::TimeDelta maximum, size_t bucket_count);
~LinearHistogram() {}
@@ -397,7 +397,7 @@
// BooleanHistogram is a histogram for booleans.
class BooleanHistogram : public LinearHistogram {
public:
- explicit BooleanHistogram(const wchar_t* name)
+ explicit BooleanHistogram(const char* name)
: LinearHistogram(name, 0, 2, 3) {
}
@@ -413,7 +413,7 @@
class ThreadSafeHistogram : public Histogram {
public:
- ThreadSafeHistogram(const wchar_t* name, Sample minimum,
+ ThreadSafeHistogram(const char* name, Sample minimum,
Sample maximum, size_t bucket_count);
// Provide the analog to Add()
@@ -485,4 +485,3 @@
};
#endif // BASE_HISTOGRAM_H__
-
diff --git a/base/histogram_unittest.cc b/base/histogram_unittest.cc
index 7085f97..b54ad7f 100644
--- a/base/histogram_unittest.cc
+++ b/base/histogram_unittest.cc
@@ -20,20 +20,20 @@
// Check for basic syntax and use.
TEST(HistogramTest, StartupShutdownTest) {
// Try basic construction
- Histogram histogram(L"TestHistogram", 1, 1000, 10);
- Histogram histogram1(L"Test1Histogram", 1, 1000, 10);
+ Histogram histogram("TestHistogram", 1, 1000, 10);
+ Histogram histogram1("Test1Histogram", 1, 1000, 10);
- LinearHistogram linear_histogram(L"TestLinearHistogram", 1, 1000, 10);
- LinearHistogram linear_histogram1(L"Test1LinearHistogram", 1, 1000, 10);
+ LinearHistogram linear_histogram("TestLinearHistogram", 1, 1000, 10);
+ LinearHistogram linear_histogram1("Test1LinearHistogram", 1, 1000, 10);
// Use standard macros (but with fixed samples)
- HISTOGRAM_TIMES(L"Test2Histogram", TimeDelta::FromDays(1));
- HISTOGRAM_COUNTS(L"Test3Histogram", 30);
+ HISTOGRAM_TIMES("Test2Histogram", TimeDelta::FromDays(1));
+ HISTOGRAM_COUNTS("Test3Histogram", 30);
- DHISTOGRAM_TIMES(L"Test4Histogram", TimeDelta::FromDays(1));
- DHISTOGRAM_COUNTS(L"Test5Histogram", 30);
+ DHISTOGRAM_TIMES("Test4Histogram", TimeDelta::FromDays(1));
+ DHISTOGRAM_COUNTS("Test5Histogram", 30);
- ASSET_HISTOGRAM_COUNTS(L"Test6Histogram", 129);
+ ASSET_HISTOGRAM_COUNTS("Test6Histogram", 129);
// Try to construct samples.
Histogram::SampleSet sample1;
@@ -58,35 +58,35 @@
EXPECT_EQ(0U, histograms.size());
// Try basic construction
- Histogram histogram(L"TestHistogram", 1, 1000, 10);
+ Histogram histogram("TestHistogram", 1, 1000, 10);
histograms.clear();
StatisticsRecorder::GetHistograms(&histograms); // Load up lists
EXPECT_EQ(1U, histograms.size());
- Histogram histogram1(L"Test1Histogram", 1, 1000, 10);
+ Histogram histogram1("Test1Histogram", 1, 1000, 10);
histograms.clear();
StatisticsRecorder::GetHistograms(&histograms); // Load up lists
EXPECT_EQ(2U, histograms.size());
- LinearHistogram linear_histogram(L"TestLinearHistogram", 1, 1000, 10);
- LinearHistogram linear_histogram1(L"Test1LinearHistogram", 1, 1000, 10);
+ LinearHistogram linear_histogram("TestLinearHistogram", 1, 1000, 10);
+ LinearHistogram linear_histogram1("Test1LinearHistogram", 1, 1000, 10);
histograms.clear();
StatisticsRecorder::GetHistograms(&histograms); // Load up lists
EXPECT_EQ(4U, histograms.size());
// Use standard macros (but with fixed samples)
- HISTOGRAM_TIMES(L"Test2Histogram", TimeDelta::FromDays(1));
- HISTOGRAM_COUNTS(L"Test3Histogram", 30);
+ HISTOGRAM_TIMES("Test2Histogram", TimeDelta::FromDays(1));
+ HISTOGRAM_COUNTS("Test3Histogram", 30);
histograms.clear();
StatisticsRecorder::GetHistograms(&histograms); // Load up lists
EXPECT_EQ(6U, histograms.size());
- ASSET_HISTOGRAM_COUNTS(L"TestAssetHistogram", 1000);
+ ASSET_HISTOGRAM_COUNTS("TestAssetHistogram", 1000);
histograms.clear();
StatisticsRecorder::GetHistograms(&histograms); // Load up lists
EXPECT_EQ(7U, histograms.size());
- DHISTOGRAM_TIMES(L"Test4Histogram", TimeDelta::FromDays(1));
- DHISTOGRAM_COUNTS(L"Test5Histogram", 30);
+ DHISTOGRAM_TIMES("Test4Histogram", TimeDelta::FromDays(1));
+ DHISTOGRAM_COUNTS("Test5Histogram", 30);
histograms.clear();
StatisticsRecorder::GetHistograms(&histograms); // Load up lists
#ifndef NDEBUG
@@ -103,7 +103,7 @@
recorder.GetHistograms(&histograms);
EXPECT_EQ(0U, histograms.size());
- Histogram histogram(L"Histogram", 1, 64, 8); // As mentioned in header file.
+ Histogram histogram("Histogram", 1, 64, 8); // As mentioned in header file.
// Check that we got a nice exponential when there was enough rooom.
EXPECT_EQ(0, histogram.ranges(0));
int power_of_2 = 1;
@@ -113,26 +113,26 @@
}
EXPECT_EQ(INT_MAX, histogram.ranges(8));
- Histogram short_histogram(L"Histogram Shortened", 1, 7, 8);
+ Histogram short_histogram("Histogram Shortened", 1, 7, 8);
// Check that when the number of buckets is short, we get a linear histogram
// for lack of space to do otherwise.
for (int i = 0; i < 8; i++)
EXPECT_EQ(i, short_histogram.ranges(i));
EXPECT_EQ(INT_MAX, short_histogram.ranges(8));
- LinearHistogram linear_histogram(L"Linear", 1, 7, 8);
+ LinearHistogram linear_histogram("Linear", 1, 7, 8);
// We also get a nice linear set of bucket ranges when we ask for it
for (int i = 0; i < 8; i++)
EXPECT_EQ(i, linear_histogram.ranges(i));
EXPECT_EQ(INT_MAX, linear_histogram.ranges(8));
- LinearHistogram linear_broad_histogram(L"Linear widened", 2, 14, 8);
+ LinearHistogram linear_broad_histogram("Linear widened", 2, 14, 8);
// ...but when the list has more space, then the ranges naturally spread out.
for (int i = 0; i < 8; i++)
EXPECT_EQ(2 * i, linear_broad_histogram.ranges(i));
EXPECT_EQ(INT_MAX, linear_broad_histogram.ranges(8));
- ThreadSafeHistogram threadsafe_histogram(L"ThreadSafe", 1, 32, 15);
+ ThreadSafeHistogram threadsafe_histogram("ThreadSafe", 1, 32, 15);
// When space is a little tight, we transition from linear to exponential.
// This is what happens in both the basic histogram, and the threadsafe
// variant (which is derived).
@@ -160,7 +160,7 @@
// Make sure histogram handles out-of-bounds data gracefully.
TEST(HistogramTest, BoundsTest) {
const size_t kBucketCount = 50;
- Histogram histogram(L"Bounded", 10, 100, kBucketCount);
+ Histogram histogram("Bounded", 10, 100, kBucketCount);
// Put two samples "out of bounds" above and below.
histogram.Add(5);
@@ -182,7 +182,7 @@
// Check to be sure samples land as expected is "correct" buckets.
TEST(HistogramTest, BucketPlacementTest) {
- Histogram histogram(L"Histogram", 1, 64, 8); // As mentioned in header file.
+ Histogram histogram("Histogram", 1, 64, 8); // As mentioned in header file.
// Check that we got a nice exponential since there was enough rooom.
EXPECT_EQ(0, histogram.ranges(0));
@@ -211,8 +211,8 @@
EXPECT_EQ(i + 1, sample.counts(i));
}
-static const wchar_t* kAssetTestHistogramName = L"AssetCountTest";
-static const wchar_t* kAssetTestDebugHistogramName = L"DAssetCountTest";
+static const char kAssetTestHistogramName[] = "AssetCountTest";
+static const char kAssetTestDebugHistogramName[] = "DAssetCountTest";
void AssetCountFunction(int sample) {
ASSET_HISTOGRAM_COUNTS(kAssetTestHistogramName, sample);
DASSET_HISTOGRAM_COUNTS(kAssetTestDebugHistogramName, sample);
@@ -229,16 +229,14 @@
StatisticsRecorder::Histograms histogram_list;
StatisticsRecorder::GetHistograms(&histogram_list);
ASSERT_NE(0U, histogram_list.size());
- std::string ascii_name = WideToASCII(kAssetTestHistogramName);
- std::string debug_ascii_name = WideToASCII(kAssetTestDebugHistogramName);
const Histogram* our_histogram = NULL;
const Histogram* our_debug_histogram = NULL;
for (StatisticsRecorder::Histograms::iterator it = histogram_list.begin();
it != histogram_list.end();
++it) {
- if (!(*it)->histogram_name().compare(ascii_name))
+ if (!(*it)->histogram_name().compare(kAssetTestHistogramName))
our_histogram = *it;
- else if (!(*it)->histogram_name().compare(debug_ascii_name)) {
+ else if (!(*it)->histogram_name().compare(kAssetTestDebugHistogramName)) {
our_debug_histogram = *it;
}
}
@@ -294,4 +292,3 @@
}
} // namespace
-
diff --git a/base/message_loop.cc b/base/message_loop.cc
index 12ad3fa..a57946b 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -504,11 +504,11 @@
if (enable_histogrammer_ && !message_histogram_.get()
&& StatisticsRecorder::WasStarted()) {
DCHECK(!thread_name_.empty());
- message_histogram_.reset(new LinearHistogram(
- ASCIIToWide("MsgLoop:" + thread_name_).c_str(),
- kLeastNonZeroMessageId,
- kMaxMessageId,
- kNumberOfDistinctMessagesDisplayed));
+ message_histogram_.reset(
+ new LinearHistogram(("MsgLoop:" + thread_name_).c_str(),
+ kLeastNonZeroMessageId,
+ kMaxMessageId,
+ kNumberOfDistinctMessagesDisplayed));
message_histogram_->SetFlags(message_histogram_->kHexRangePrintingFlag);
message_histogram_->SetRangeDescriptions(event_descriptions_);
}