diff options
author | evanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-21 21:27:45 +0000 |
---|---|---|
committer | evanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-21 21:27:45 +0000 |
commit | 778cb2f49af834951ab17e95c9143c313e5bf1a2 (patch) | |
tree | 8d3c27c95cb8dcd0fd43576fe2a5d85793c11279 /base | |
parent | a0dde12f2e4f92f1a59885c45cfecd10dbfdfdfd (diff) | |
download | chromium_src-778cb2f49af834951ab17e95c9143c313e5bf1a2.zip chromium_src-778cb2f49af834951ab17e95c9143c313e5bf1a2.tar.gz chromium_src-778cb2f49af834951ab17e95c9143c313e5bf1a2.tar.bz2 |
Rollback "Remove use of wide characters in stats table identifiers."
This reverts commit r5847.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5850 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/histogram.cc | 4 | ||||
-rw-r--r-- | base/stats_counters.h | 16 | ||||
-rw-r--r-- | base/stats_table.cc | 72 | ||||
-rw-r--r-- | base/stats_table.h | 20 | ||||
-rw-r--r-- | base/stats_table_unittest.cc | 128 |
5 files changed, 120 insertions, 120 deletions
diff --git a/base/histogram.cc b/base/histogram.cc index 2b05077..384716d 100644 --- a/base/histogram.cc +++ b/base/histogram.cc @@ -25,7 +25,7 @@ const int Histogram::kHexRangePrintingFlag = 0x8000; Histogram::Histogram(const wchar_t* name, Sample minimum, Sample maximum, size_t bucket_count) - : StatsRate(WideToASCII(name).c_str()), + : StatsRate(name), histogram_name_(WideToASCII(name)), declared_min_(minimum), declared_max_(maximum), @@ -39,7 +39,7 @@ Histogram::Histogram(const wchar_t* name, Sample minimum, Histogram::Histogram(const wchar_t* name, TimeDelta minimum, TimeDelta maximum, size_t bucket_count) - : StatsRate(WideToASCII(name).c_str()), + : StatsRate(name), histogram_name_(WideToASCII(name)), declared_min_(static_cast<int> (minimum.InMilliseconds())), declared_max_(static_cast<int> (maximum.InMilliseconds())), diff --git a/base/stats_counters.h b/base/stats_counters.h index 9927c19..5dc7b89c 100644 --- a/base/stats_counters.h +++ b/base/stats_counters.h @@ -74,10 +74,10 @@ class StatsCounter { public: // Create a StatsCounter object. - explicit StatsCounter(const std::string& name) + explicit StatsCounter(const std::wstring& name) : counter_id_(-1) { // We prepend the name with 'c:' to indicate that it is a counter. - name_ = "c:"; + name_ = L"c:"; name_.append(name); }; @@ -146,7 +146,7 @@ class StatsCounter { if (counter_id_ == -1) { counter_id_ = table->FindCounter(name_); if (table->GetSlot() == 0) { - if (!table->RegisterThread("")) { + if (!table->RegisterThread(L"")) { // There is no room for this thread. This thread // cannot use counters. counter_id_ = 0; @@ -163,7 +163,7 @@ class StatsCounter { return NULL; } - std::string name_; + std::wstring name_; // The counter id in the table. We initialize to -1 (an invalid value) // and then cache it once it has been looked up. The counter_id is // valid across all threads and processes. @@ -177,9 +177,9 @@ class StatsCounter { class StatsCounterTimer : protected StatsCounter { public: // Constructs and starts the timer. - explicit StatsCounterTimer(const std::string& name) { + explicit StatsCounterTimer(const std::wstring& name) { // we prepend the name with 't:' to indicate that it is a timer. - name_ = "t:"; + name_ = L"t:"; name_.append(name); } @@ -230,10 +230,10 @@ class StatsCounterTimer : protected StatsCounter { class StatsRate : public StatsCounterTimer { public: // Constructs and starts the timer. - explicit StatsRate(const char* name) + explicit StatsRate(const wchar_t* name) : StatsCounterTimer(name), counter_(name), - largest_add_(std::string(" ").append(name).append("MAX").c_str()) { + largest_add_(std::wstring(L" ").append(name).append(L"MAX").c_str()) { } virtual void Add(int value) { diff --git a/base/stats_table.cc b/base/stats_table.cc index 1f25457..72cc5ab 100644 --- a/base/stats_table.cc +++ b/base/stats_table.cc @@ -70,7 +70,7 @@ namespace { const int kTableVersion = 0x13131313; // The name for un-named counters and threads in the table. -const char kUnknownName[] = "<unknown>"; +const wchar_t kUnknownName[] = L"<unknown>"; // Calculates delta to align an offset to the size of an int inline int AlignOffset(int offset) { @@ -109,7 +109,7 @@ class StatsTablePrivate { // Construct a new StatsTablePrivate based on expected size parameters, or // return NULL on failure. - static StatsTablePrivate* New(const std::string& name, int size, + static StatsTablePrivate* New(const std::wstring& name, int size, int max_threads, int max_counters); base::SharedMemory* shared_memory() { return &shared_memory_; } @@ -122,7 +122,7 @@ class StatsTablePrivate { int max_threads() const { return table_header_->max_threads; } // Accessors for our tables - char* thread_name(int slot_id) const { + wchar_t* thread_name(int slot_id) const { return &thread_names_table_[ (slot_id-1) * (StatsTable::kMaxThreadNameLength)]; } @@ -132,7 +132,7 @@ class StatsTablePrivate { int* thread_pid(int slot_id) const { return &(thread_pid_table_[slot_id-1]); } - char* counter_name(int counter_id) const { + wchar_t* counter_name(int counter_id) const { return &counter_names_table_[ (counter_id-1) * (StatsTable::kMaxCounterNameLength)]; } @@ -154,21 +154,21 @@ class StatsTablePrivate { base::SharedMemory shared_memory_; TableHeader* table_header_; - char* thread_names_table_; + wchar_t* thread_names_table_; int* thread_tid_table_; int* thread_pid_table_; - char* counter_names_table_; + wchar_t* counter_names_table_; int* data_table_; }; // static -StatsTablePrivate* StatsTablePrivate::New(const std::string& name, +StatsTablePrivate* StatsTablePrivate::New(const std::wstring& name, int size, int max_threads, int max_counters) { scoped_ptr<StatsTablePrivate> priv(new StatsTablePrivate()); - if (!priv->shared_memory_.Create(UTF8ToWide(name), false, true, size)) + if (!priv->shared_memory_.Create(name, false, true, size)) return NULL; if (!priv->shared_memory_.Map(size)) return NULL; @@ -212,8 +212,8 @@ void StatsTablePrivate::ComputeMappedPointers(void* memory) { // Verify we're looking at a valid StatsTable. DCHECK_EQ(table_header_->version, kTableVersion); - thread_names_table_ = reinterpret_cast<char*>(data + offset); - offset += sizeof(char) * + thread_names_table_ = reinterpret_cast<wchar_t*>(data + offset); + offset += sizeof(wchar_t) * max_threads() * StatsTable::kMaxThreadNameLength; offset += AlignOffset(offset); @@ -225,8 +225,8 @@ void StatsTablePrivate::ComputeMappedPointers(void* memory) { offset += sizeof(int) * max_threads(); offset += AlignOffset(offset); - counter_names_table_ = reinterpret_cast<char*>(data + offset); - offset += sizeof(char) * + counter_names_table_ = reinterpret_cast<wchar_t*>(data + offset); + offset += sizeof(wchar_t) * max_counters() * StatsTable::kMaxCounterNameLength; offset += AlignOffset(offset); @@ -241,14 +241,14 @@ void StatsTablePrivate::ComputeMappedPointers(void* memory) { // We keep a singleton table which can be easily accessed. StatsTable* StatsTable::global_table_ = NULL; -StatsTable::StatsTable(const std::string& name, int max_threads, +StatsTable::StatsTable(const std::wstring& name, int max_threads, int max_counters) : impl_(NULL), tls_index_(SlotReturnFunction) { int table_size = AlignedSize(sizeof(StatsTablePrivate::TableHeader)) + - AlignedSize((max_counters * sizeof(char) * kMaxCounterNameLength)) + - AlignedSize((max_threads * sizeof(char) * kMaxThreadNameLength)) + + AlignedSize((max_counters * sizeof(wchar_t) * kMaxCounterNameLength)) + + AlignedSize((max_threads * sizeof(wchar_t) * kMaxThreadNameLength)) + AlignedSize(max_threads * sizeof(int)) + AlignedSize(max_threads * sizeof(int)) + AlignedSize((sizeof(int) * (max_counters * max_threads))); @@ -282,7 +282,7 @@ StatsTable::~StatsTable() { global_table_ = NULL; } -int StatsTable::RegisterThread(const std::string& name) { +int StatsTable::RegisterThread(const std::wstring& name) { int slot = 0; // Registering a thread requires that we lock the shared memory @@ -298,10 +298,10 @@ int StatsTable::RegisterThread(const std::string& name) { DCHECK(impl_); // We have space, so consume a column in the table. - std::string thread_name = name; + std::wstring thread_name = name; if (name.empty()) thread_name = kUnknownName; - base::strlcpy(impl_->thread_name(slot), thread_name.c_str(), + base::wcslcpy(impl_->thread_name(slot), thread_name.c_str(), kMaxThreadNameLength); *(impl_->thread_tid(slot)) = PlatformThread::CurrentId(); *(impl_->thread_pid(slot)) = base::GetCurrentProcId(); @@ -336,8 +336,8 @@ void StatsTable::UnregisterThread(StatsTableTLSData* data) { DCHECK(impl_); // Mark the slot free by zeroing out the thread name. - char* name = impl_->thread_name(data->slot); - *name = '\0'; + wchar_t* name = impl_->thread_name(data->slot); + *name = L'\0'; // Remove the calling thread's TLS so that it cannot use the slot. tls_index_.Set(NULL); @@ -363,8 +363,8 @@ int StatsTable::CountThreadsRegistered() const { // We intentionally do not lock the table during the operation. int count = 0; for (int index = 1; index <= impl_->max_threads(); index++) { - char* name = impl_->thread_name(index); - if (*name != '\0') + wchar_t* name = impl_->thread_name(index); + if (*name != L'\0') count++; } return count; @@ -391,7 +391,7 @@ int StatsTable::FindEmptyThread() const { int index = 1; for (; index <= impl_->max_threads(); index++) { - char* name = impl_->thread_name(index); + wchar_t* name = impl_->thread_name(index); if (!*name) break; } @@ -400,7 +400,7 @@ int StatsTable::FindEmptyThread() const { return index; } -int StatsTable::FindCounterOrEmptyRow(const std::string& name) const { +int StatsTable::FindCounterOrEmptyRow(const std::wstring& name) const { // Note: the API returns slots numbered from 1..N, although // internally, the array is 0..N-1. This is so that we can return // zero as "not found". @@ -413,16 +413,16 @@ int StatsTable::FindCounterOrEmptyRow(const std::string& name) const { int free_slot = 0; for (int index = 1; index <= impl_->max_counters(); index++) { - char* row_name = impl_->counter_name(index); + wchar_t* row_name = impl_->counter_name(index); if (!*row_name && !free_slot) free_slot = index; // save that we found a free slot - else if (!strncmp(row_name, name.c_str(), kMaxCounterNameLength)) + else if (!wcsncmp(row_name, name.c_str(), kMaxCounterNameLength)) return index; } return free_slot; } -int StatsTable::FindCounter(const std::string& name) { +int StatsTable::FindCounter(const std::wstring& name) { // Note: the API returns counters numbered from 1..N, although // internally, the array is 0..N-1. This is so that we can return // zero as "not found". @@ -444,7 +444,7 @@ int StatsTable::FindCounter(const std::string& name) { return AddCounter(name); } -int StatsTable::AddCounter(const std::string& name) { +int StatsTable::AddCounter(const std::wstring& name) { DCHECK(impl_); if (!impl_) @@ -461,10 +461,10 @@ int StatsTable::AddCounter(const std::string& name) { if (!counter_id) return 0; - std::string counter_name = name; + std::wstring counter_name = name; if (name.empty()) counter_name = kUnknownName; - base::strlcpy(impl_->counter_name(counter_id), counter_name.c_str(), + base::wcslcpy(impl_->counter_name(counter_id), counter_name.c_str(), kMaxCounterNameLength); } @@ -486,7 +486,7 @@ int* StatsTable::GetLocation(int counter_id, int slot_id) const { return &(row[slot_id-1]); } -const char* StatsTable::GetRowName(int index) const { +const wchar_t* StatsTable::GetRowName(int index) const { if (!impl_) return NULL; @@ -510,7 +510,7 @@ int StatsTable::GetRowValue(int index) const { return GetRowValue(index, 0); } -int StatsTable::GetCounterValue(const std::string& name, int pid) { +int StatsTable::GetCounterValue(const std::wstring& name, int pid) { if (!impl_) return 0; @@ -520,7 +520,7 @@ int StatsTable::GetCounterValue(const std::string& name, int pid) { return GetRowValue(row, pid); } -int StatsTable::GetCounterValue(const std::string& name) { +int StatsTable::GetCounterValue(const std::wstring& name) { return GetCounterValue(name, 0); } @@ -536,7 +536,7 @@ int StatsTable::GetMaxThreads() const { return impl_->max_threads(); } -int* StatsTable::FindLocation(const char* name) { +int* StatsTable::FindLocation(const wchar_t* name) { // Get the static StatsTable StatsTable *table = StatsTable::current(); if (!table) @@ -545,11 +545,11 @@ int* StatsTable::FindLocation(const char* name) { // Get the slot for this thread. Try to register // it if none exists. int slot = table->GetSlot(); - if (!slot && !(slot = table->RegisterThread(""))) + if (!slot && !(slot = table->RegisterThread(L""))) return NULL; // Find the counter id for the counter. - std::string str_name(name); + std::wstring str_name(name); int counter = table->FindCounter(str_name); // Now we can find the location in the table. diff --git a/base/stats_table.h b/base/stats_table.h index 18fb3dba..48da71a 100644 --- a/base/stats_table.h +++ b/base/stats_table.h @@ -46,7 +46,7 @@ class StatsTable { // // max_counters is the maximum number of counters the table will support. // If the StatsTable already exists, this number is ignored. - StatsTable(const std::string& name, int max_threads, int max_counters); + StatsTable(const std::wstring& name, int max_threads, int max_counters); // Destroys the StatsTable. When the last StatsTable is destroyed // (across all processes), the StatsTable is removed from disk. @@ -74,7 +74,7 @@ class StatsTable { // // On success, returns the slot id for this thread. On failure, // returns 0. - int RegisterThread(const std::string& name); + int RegisterThread(const std::wstring& name); // Returns the number of threads currently registered. This is really not // useful except for diagnostics and debugging. @@ -86,7 +86,7 @@ class StatsTable { // If the counter does not exist, attempts to create a row for the new // counter. If there is no space in the table for the new counter, // returns 0. - int FindCounter(const std::string& name); + int FindCounter(const std::wstring& name); // TODO(mbelshe): implement RemoveCounter. @@ -96,7 +96,7 @@ class StatsTable { // Gets the counter name at a particular row. If the row is empty, // returns NULL. - const char* GetRowName(int index) const; + const wchar_t* GetRowName(int index) const; // Gets the sum of the values for a particular row. int GetRowValue(int index) const; @@ -106,11 +106,11 @@ class StatsTable { // Gets the sum of the values for a particular counter. If the counter // does not exist, creates the counter. - int GetCounterValue(const std::string& name); + int GetCounterValue(const std::wstring& name); // Gets the sum of the values for a particular counter for a given pid. // If the counter does not exist, creates the counter. - int GetCounterValue(const std::string& name, int pid); + int GetCounterValue(const std::wstring& name, int pid); // The maxinum number of counters/rows in the table. int GetMaxCounters() const; @@ -129,7 +129,7 @@ class StatsTable { // Convenience function to lookup a counter location for a // counter by name for the calling thread. Will register // the thread if it is not already registered. - static int* FindLocation(const char *name); + static int* FindLocation(const wchar_t *name); private: // Returns the space occupied by a thread in the table. Generally used @@ -154,7 +154,7 @@ class StatsTable { // Locates a counter in the table or finds an empty row. Returns a // number > 0 on success, or 0 on failure. The caller must hold the // shared_memory_lock when calling this function. - int FindCounterOrEmptyRow(const std::string& name) const; + int FindCounterOrEmptyRow(const std::wstring& name) const; // Internal function to add a counter to the StatsTable. Assumes that // the counter does not already exist in the table. @@ -164,13 +164,13 @@ class StatsTable { // // On success, returns the counter_id for the newly added counter. // On failure, returns 0. - int AddCounter(const std::string& name); + int AddCounter(const std::wstring& name); // Get the TLS data for the calling thread. Returns NULL if none is // initialized. StatsTableTLSData* GetTLSData() const; - typedef base::hash_map<std::string, int> CountersMap; + typedef base::hash_map<std::wstring, int> CountersMap; bool opened_; StatsTablePrivate* impl_; diff --git a/base/stats_table_unittest.cc b/base/stats_table_unittest.cc index 59b1215..68a07ac 100644 --- a/base/stats_table_unittest.cc +++ b/base/stats_table_unittest.cc @@ -24,27 +24,27 @@ class StatsTableTest : public MultiProcessTest { // Open a StatsTable and verify that we can write to each of the // locations in the table. TEST_F(StatsTableTest, VerifySlots) { - const std::string kTableName = "VerifySlotsStatTable"; + const std::wstring kTableName = L"VerifySlotsStatTable"; const int kMaxThreads = 1; const int kMaxCounter = 5; StatsTable table(kTableName, kMaxThreads, kMaxCounter); // Register a single thread. - std::string thread_name = "mainThread"; + std::wstring thread_name = L"mainThread"; int slot_id = table.RegisterThread(thread_name); EXPECT_TRUE(slot_id); // Fill up the table with counters. - std::string counter_base_name = "counter"; + std::wstring counter_base_name = L"counter"; for (int index=0; index < kMaxCounter; index++) { - std::string counter_name = counter_base_name; - StringAppendF(&counter_name, "counter.ctr%d", index); + std::wstring counter_name = counter_base_name; + StringAppendF(&counter_name, L"counter.ctr%d", index); int counter_id = table.FindCounter(counter_name); EXPECT_GT(counter_id, 0); } // Try to allocate an additional thread. Verify it fails. - slot_id = table.RegisterThread("too many threads"); + slot_id = table.RegisterThread(L"too many threads"); EXPECT_EQ(slot_id, 0); // Try to allocate an additional counter. Verify it fails. @@ -53,16 +53,16 @@ TEST_F(StatsTableTest, VerifySlots) { } // CounterZero will continually be set to 0. -const std::string kCounterZero = "CounterZero"; +const std::wstring kCounterZero = L"CounterZero"; // Counter1313 will continually be set to 1313. -const std::string kCounter1313 = "Counter1313"; +const std::wstring kCounter1313 = L"Counter1313"; // CounterIncrement will be incremented each time. -const std::string kCounterIncrement = "CounterIncrement"; +const std::wstring kCounterIncrement = L"CounterIncrement"; // CounterDecrement will be decremented each time. -const std::string kCounterDecrement = "CounterDecrement"; +const std::wstring kCounterDecrement = L"CounterDecrement"; // CounterMixed will be incremented by odd numbered threads and // decremented by even threads. -const std::string kCounterMixed = "CounterMixed"; +const std::wstring kCounterMixed = L"CounterMixed"; // The number of thread loops that we will do. const int kThreadLoops = 1000; @@ -101,7 +101,7 @@ void StatsTableThread::Run() { // Create a few threads and have them poke on their counters. TEST_F(StatsTableTest, MultipleThreads) { // Create a stats table. - const std::string kTableName = "MultipleThreadStatTable"; + const std::wstring kTableName = L"MultipleThreadStatTable"; const int kMaxThreads = 20; const int kMaxCounter = 5; StatsTable table(kTableName, kMaxThreads, kMaxCounter); @@ -133,25 +133,25 @@ TEST_F(StatsTableTest, MultipleThreads) { StatsCounter mixed_counter(kCounterMixed); // Verify the various counters are correct. - std::string name; - name = "c:" + kCounterZero; + std::wstring name; + name = L"c:" + kCounterZero; EXPECT_EQ(0, table.GetCounterValue(name)); - name = "c:" + kCounter1313; + name = L"c:" + kCounter1313; EXPECT_EQ(1313 * kMaxThreads, table.GetCounterValue(name)); - name = "c:" + kCounterIncrement; + name = L"c:" + kCounterIncrement; EXPECT_EQ(kMaxThreads * kThreadLoops, table.GetCounterValue(name)); - name = "c:" + kCounterDecrement; + name = L"c:" + kCounterDecrement; EXPECT_EQ(-kMaxThreads * kThreadLoops, table.GetCounterValue(name)); - name = "c:" + kCounterMixed; + name = L"c:" + kCounterMixed; EXPECT_EQ((kMaxThreads % 2) * kThreadLoops, table.GetCounterValue(name)); EXPECT_EQ(0, table.CountThreadsRegistered()); } -const std::string kTableName = "MultipleProcessStatTable"; +const std::wstring kTableName = L"MultipleProcessStatTable"; MULTIPROCESS_TEST_MAIN(StatsTableMultipleProcessMain) { // Each process will open the shared memory and set counters @@ -177,7 +177,7 @@ MULTIPROCESS_TEST_MAIN(StatsTableMultipleProcessMain) { // Create a few processes and have them poke on their counters. TEST_F(StatsTableTest, MultipleProcesses) { // Create a stats table. - const std::string kTableName = "MultipleProcessStatTable"; + const std::wstring kTableName = L"MultipleProcessStatTable"; const int kMaxProcs = 20; const int kMaxCounter = 5; StatsTable table(kTableName, kMaxProcs, kMaxCounter); @@ -207,16 +207,16 @@ TEST_F(StatsTableTest, MultipleProcesses) { StatsCounter decrement_counter(kCounterDecrement); // Verify the various counters are correct. - std::string name; - name = "c:" + kCounterZero; + std::wstring name; + name = L"c:" + kCounterZero; EXPECT_EQ(0, table.GetCounterValue(name)); - name = "c:" + kCounter1313; + name = L"c:" + kCounter1313; EXPECT_EQ(1313 * kMaxProcs, table.GetCounterValue(name)); - name = "c:" + kCounterIncrement; + name = L"c:" + kCounterIncrement; EXPECT_EQ(kMaxProcs * kThreadLoops, table.GetCounterValue(name)); - name = "c:" + kCounterDecrement; + name = L"c:" + kCounterDecrement; EXPECT_EQ(-kMaxProcs * kThreadLoops, table.GetCounterValue(name)); EXPECT_EQ(0, table.CountThreadsRegistered()); @@ -224,7 +224,7 @@ TEST_F(StatsTableTest, MultipleProcesses) { class MockStatsCounter : public StatsCounter { public: - MockStatsCounter(const std::string& name) + MockStatsCounter(const std::wstring& name) : StatsCounter(name) {} int* Pointer() { return GetPtr(); } }; @@ -232,50 +232,50 @@ class MockStatsCounter : public StatsCounter { // Test some basic StatsCounter operations TEST_F(StatsTableTest, StatsCounter) { // Create a stats table. - const std::string kTableName = "StatTable"; + const std::wstring kTableName = L"StatTable"; const int kMaxThreads = 20; const int kMaxCounter = 5; StatsTable table(kTableName, kMaxThreads, kMaxCounter); StatsTable::set_current(&table); - MockStatsCounter foo("foo"); + MockStatsCounter foo(L"foo"); // Test initial state. EXPECT_TRUE(foo.Enabled()); EXPECT_NE(foo.Pointer(), static_cast<int*>(0)); - EXPECT_EQ(0, table.GetCounterValue("c:foo")); + EXPECT_EQ(0, table.GetCounterValue(L"c:foo")); EXPECT_EQ(0, *(foo.Pointer())); // Test Increment. while(*(foo.Pointer()) < 123) foo.Increment(); - EXPECT_EQ(123, table.GetCounterValue("c:foo")); + EXPECT_EQ(123, table.GetCounterValue(L"c:foo")); foo.Add(0); - EXPECT_EQ(123, table.GetCounterValue("c:foo")); + EXPECT_EQ(123, table.GetCounterValue(L"c:foo")); foo.Add(-1); - EXPECT_EQ(122, table.GetCounterValue("c:foo")); + EXPECT_EQ(122, table.GetCounterValue(L"c:foo")); // Test Set. foo.Set(0); - EXPECT_EQ(0, table.GetCounterValue("c:foo")); + EXPECT_EQ(0, table.GetCounterValue(L"c:foo")); foo.Set(100); - EXPECT_EQ(100, table.GetCounterValue("c:foo")); + EXPECT_EQ(100, table.GetCounterValue(L"c:foo")); foo.Set(-1); - EXPECT_EQ(-1, table.GetCounterValue("c:foo")); + EXPECT_EQ(-1, table.GetCounterValue(L"c:foo")); foo.Set(0); - EXPECT_EQ(0, table.GetCounterValue("c:foo")); + EXPECT_EQ(0, table.GetCounterValue(L"c:foo")); // Test Decrement. foo.Decrement(1); - EXPECT_EQ(-1, table.GetCounterValue("c:foo")); + EXPECT_EQ(-1, table.GetCounterValue(L"c:foo")); foo.Decrement(0); - EXPECT_EQ(-1, table.GetCounterValue("c:foo")); + EXPECT_EQ(-1, table.GetCounterValue(L"c:foo")); foo.Decrement(-1); - EXPECT_EQ(0, table.GetCounterValue("c:foo")); + EXPECT_EQ(0, table.GetCounterValue(L"c:foo")); } class MockStatsCounterTimer : public StatsCounterTimer { public: - MockStatsCounterTimer(const std::string& name) + MockStatsCounterTimer(const std::wstring& name) : StatsCounterTimer(name) {} TimeTicks start_time() { return start_time_; } @@ -285,13 +285,13 @@ class MockStatsCounterTimer : public StatsCounterTimer { // Test some basic StatsCounterTimer operations TEST_F(StatsTableTest, StatsCounterTimer) { // Create a stats table. - const std::string kTableName = "StatTable"; + const std::wstring kTableName = L"StatTable"; const int kMaxThreads = 20; const int kMaxCounter = 5; StatsTable table(kTableName, kMaxThreads, kMaxCounter); StatsTable::set_current(&table); - MockStatsCounterTimer bar("bar"); + MockStatsCounterTimer bar(L"bar"); // Test initial state. EXPECT_FALSE(bar.Running()); @@ -302,62 +302,62 @@ TEST_F(StatsTableTest, StatsCounterTimer) { bar.Start(); PlatformThread::Sleep(500); bar.Stop(); - EXPECT_LE(500, table.GetCounterValue("t:bar")); + EXPECT_LE(500, table.GetCounterValue(L"t:bar")); // Verify that timing again is additive. bar.Start(); PlatformThread::Sleep(500); bar.Stop(); - EXPECT_LE(1000, table.GetCounterValue("t:bar")); + EXPECT_LE(1000, table.GetCounterValue(L"t:bar")); } // Test some basic StatsRate operations TEST_F(StatsTableTest, StatsRate) { // Create a stats table. - const std::string kTableName = "StatTable"; + const std::wstring kTableName = L"StatTable"; const int kMaxThreads = 20; const int kMaxCounter = 5; StatsTable table(kTableName, kMaxThreads, kMaxCounter); StatsTable::set_current(&table); - StatsRate baz("baz"); + StatsRate baz(L"baz"); // Test initial state. EXPECT_FALSE(baz.Running()); - EXPECT_EQ(0, table.GetCounterValue("c:baz")); - EXPECT_EQ(0, table.GetCounterValue("t:baz")); + EXPECT_EQ(0, table.GetCounterValue(L"c:baz")); + EXPECT_EQ(0, table.GetCounterValue(L"t:baz")); // Do some timing. baz.Start(); PlatformThread::Sleep(500); baz.Stop(); - EXPECT_EQ(1, table.GetCounterValue("c:baz")); - EXPECT_LE(500, table.GetCounterValue("t:baz")); + EXPECT_EQ(1, table.GetCounterValue(L"c:baz")); + EXPECT_LE(500, table.GetCounterValue(L"t:baz")); // Verify that timing again is additive. baz.Start(); PlatformThread::Sleep(500); baz.Stop(); - EXPECT_EQ(2, table.GetCounterValue("c:baz")); - EXPECT_LE(1000, table.GetCounterValue("t:baz")); + EXPECT_EQ(2, table.GetCounterValue(L"c:baz")); + EXPECT_LE(1000, table.GetCounterValue(L"t:baz")); } // Test some basic StatsScope operations TEST_F(StatsTableTest, StatsScope) { // Create a stats table. - const std::string kTableName = "StatTable"; + const std::wstring kTableName = L"StatTable"; const int kMaxThreads = 20; const int kMaxCounter = 5; StatsTable table(kTableName, kMaxThreads, kMaxCounter); StatsTable::set_current(&table); - StatsCounterTimer foo("foo"); - StatsRate bar("bar"); + StatsCounterTimer foo(L"foo"); + StatsRate bar(L"bar"); // Test initial state. - EXPECT_EQ(0, table.GetCounterValue("t:foo")); - EXPECT_EQ(0, table.GetCounterValue("t:bar")); - EXPECT_EQ(0, table.GetCounterValue("c:bar")); + EXPECT_EQ(0, table.GetCounterValue(L"t:foo")); + EXPECT_EQ(0, table.GetCounterValue(L"t:bar")); + EXPECT_EQ(0, table.GetCounterValue(L"c:bar")); // Try a scope. { @@ -365,9 +365,9 @@ TEST_F(StatsTableTest, StatsScope) { StatsScope<StatsRate> timer2(bar); PlatformThread::Sleep(500); } - EXPECT_LE(500, table.GetCounterValue("t:foo")); - EXPECT_LE(500, table.GetCounterValue("t:bar")); - EXPECT_EQ(1, table.GetCounterValue("c:bar")); + EXPECT_LE(500, table.GetCounterValue(L"t:foo")); + EXPECT_LE(500, table.GetCounterValue(L"t:bar")); + EXPECT_EQ(1, table.GetCounterValue(L"c:bar")); // Try a second scope. { @@ -375,9 +375,9 @@ TEST_F(StatsTableTest, StatsScope) { StatsScope<StatsRate> timer2(bar); PlatformThread::Sleep(500); } - EXPECT_LE(1000, table.GetCounterValue("t:foo")); - EXPECT_LE(1000, table.GetCounterValue("t:bar")); - EXPECT_EQ(2, table.GetCounterValue("c:bar")); + EXPECT_LE(1000, table.GetCounterValue(L"t:foo")); + EXPECT_LE(1000, table.GetCounterValue(L"t:bar")); + EXPECT_EQ(2, table.GetCounterValue(L"c:bar")); } } // namespace base |