| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/stats_table.h" | 5 #include "base/stats_table.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/platform_thread.h" | 8 #include "base/platform_thread.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| 11 #include "base/string_piece.h" |
| 11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/sys_string_conversions.h" |
| 12 #include "base/thread_local_storage.h" | 14 #include "base/thread_local_storage.h" |
| 13 | 15 |
| 14 #if defined(OS_POSIX) | 16 #if defined(OS_POSIX) |
| 15 #include "errno.h" | 17 #include "errno.h" |
| 16 #endif | 18 #endif |
| 17 | 19 |
| 18 // The StatsTable uses a shared memory segment that is laid out as follows | 20 // The StatsTable uses a shared memory segment that is laid out as follows |
| 19 // | 21 // |
| 20 // +-------------------------------------------+ | 22 // +-------------------------------------------+ |
| 21 // | Version | Size | MaxCounters | MaxThreads | | 23 // | Version | Size | MaxCounters | MaxThreads | |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 char* counter_names_table_; | 162 char* counter_names_table_; |
| 161 int* data_table_; | 163 int* data_table_; |
| 162 }; | 164 }; |
| 163 | 165 |
| 164 // static | 166 // static |
| 165 StatsTablePrivate* StatsTablePrivate::New(const std::string& name, | 167 StatsTablePrivate* StatsTablePrivate::New(const std::string& name, |
| 166 int size, | 168 int size, |
| 167 int max_threads, | 169 int max_threads, |
| 168 int max_counters) { | 170 int max_counters) { |
| 169 scoped_ptr<StatsTablePrivate> priv(new StatsTablePrivate()); | 171 scoped_ptr<StatsTablePrivate> priv(new StatsTablePrivate()); |
| 170 | 172 if (!priv->shared_memory_.Create(base::SysUTF8ToWide(name), false, true, |
| 171 if (!priv->shared_memory_.Create(UTF8ToWide(name), false, true, size)) | 173 size)) |
| 172 return NULL; | 174 return NULL; |
| 173 if (!priv->shared_memory_.Map(size)) | 175 if (!priv->shared_memory_.Map(size)) |
| 174 return NULL; | 176 return NULL; |
| 175 void* memory = priv->shared_memory_.memory(); | 177 void* memory = priv->shared_memory_.memory(); |
| 176 | 178 |
| 177 TableHeader* header = static_cast<TableHeader*>(memory); | 179 TableHeader* header = static_cast<TableHeader*>(memory); |
| 178 | 180 |
| 179 // If the version does not match, then assume the table needs | 181 // If the version does not match, then assume the table needs |
| 180 // to be initialized. | 182 // to be initialized. |
| 181 if (header->version != kTableVersion) | 183 if (header->version != kTableVersion) |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 return NULL; | 551 return NULL; |
| 550 | 552 |
| 551 // Find the counter id for the counter. | 553 // Find the counter id for the counter. |
| 552 std::string str_name(name); | 554 std::string str_name(name); |
| 553 int counter = table->FindCounter(str_name); | 555 int counter = table->FindCounter(str_name); |
| 554 | 556 |
| 555 // Now we can find the location in the table. | 557 // Now we can find the location in the table. |
| 556 return table->GetLocation(counter, slot); | 558 return table->GetLocation(counter, slot); |
| 557 } | 559 } |
| 558 | 560 |
| OLD | NEW |