Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: base/stats_table.cc

Issue 10895: Add Terminate() to the Process object, have RenderProcessHost use this to avo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/shared_memory_win.cc ('k') | base/stats_table_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 int size; 105 int size;
106 int max_counters; 106 int max_counters;
107 int max_threads; 107 int max_threads;
108 }; 108 };
109 109
110 // Construct a new StatsTablePrivate based on expected size parameters, or 110 // Construct a new StatsTablePrivate based on expected size parameters, or
111 // return NULL on failure. 111 // return NULL on failure.
112 static StatsTablePrivate* New(const std::wstring& name, int size, 112 static StatsTablePrivate* New(const std::wstring& name, int size,
113 int max_threads, int max_counters); 113 int max_threads, int max_counters);
114 114
115 SharedMemory* shared_memory() { return &shared_memory_; } 115 base::SharedMemory* shared_memory() { return &shared_memory_; }
116 116
117 // Accessors for our header pointers 117 // Accessors for our header pointers
118 TableHeader* table_header() const { return table_header_; } 118 TableHeader* table_header() const { return table_header_; }
119 int version() const { return table_header_->version; } 119 int version() const { return table_header_->version; }
120 int size() const { return table_header_->size; } 120 int size() const { return table_header_->size; }
121 int max_counters() const { return table_header_->max_counters; } 121 int max_counters() const { return table_header_->max_counters; }
122 int max_threads() const { return table_header_->max_threads; } 122 int max_threads() const { return table_header_->max_threads; }
123 123
124 // Accessors for our tables 124 // Accessors for our tables
125 wchar_t* thread_name(int slot_id) const { 125 wchar_t* thread_name(int slot_id) const {
(...skipping 19 matching lines...) Expand all
145 StatsTablePrivate() {} 145 StatsTablePrivate() {}
146 146
147 // Initializes the table on first access. Sets header values 147 // Initializes the table on first access. Sets header values
148 // appropriately and zeroes all counters. 148 // appropriately and zeroes all counters.
149 void InitializeTable(void* memory, int size, int max_counters, 149 void InitializeTable(void* memory, int size, int max_counters,
150 int max_threads); 150 int max_threads);
151 151
152 // Initializes our in-memory pointers into a pre-created StatsTable. 152 // Initializes our in-memory pointers into a pre-created StatsTable.
153 void ComputeMappedPointers(void* memory); 153 void ComputeMappedPointers(void* memory);
154 154
155 SharedMemory shared_memory_; 155 base::SharedMemory shared_memory_;
156 TableHeader* table_header_; 156 TableHeader* table_header_;
157 wchar_t* thread_names_table_; 157 wchar_t* thread_names_table_;
158 int* thread_tid_table_; 158 int* thread_tid_table_;
159 int* thread_pid_table_; 159 int* thread_pid_table_;
160 wchar_t* counter_names_table_; 160 wchar_t* counter_names_table_;
161 int* data_table_; 161 int* data_table_;
162 }; 162 };
163 163
164 // static 164 // static
165 StatsTablePrivate* StatsTablePrivate::New(const std::wstring& name, 165 StatsTablePrivate* StatsTablePrivate::New(const std::wstring& name,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 global_table_ = NULL; 282 global_table_ = NULL;
283 } 283 }
284 284
285 int StatsTable::RegisterThread(const std::wstring& name) { 285 int StatsTable::RegisterThread(const std::wstring& name) {
286 int slot = 0; 286 int slot = 0;
287 287
288 // Registering a thread requires that we lock the shared memory 288 // Registering a thread requires that we lock the shared memory
289 // so that two threads don't grab the same slot. Fortunately, 289 // so that two threads don't grab the same slot. Fortunately,
290 // thread creation shouldn't happen in inner loops. 290 // thread creation shouldn't happen in inner loops.
291 { 291 {
292 SharedMemoryAutoLock lock(impl_->shared_memory()); 292 base::SharedMemoryAutoLock lock(impl_->shared_memory());
293 slot = FindEmptyThread(); 293 slot = FindEmptyThread();
294 if (!slot) { 294 if (!slot) {
295 return 0; 295 return 0;
296 } 296 }
297 297
298 DCHECK(impl_); 298 DCHECK(impl_);
299 299
300 // We have space, so consume a column in the table. 300 // We have space, so consume a column in the table.
301 std::wstring thread_name = name; 301 std::wstring thread_name = name;
302 if (name.empty()) 302 if (name.empty())
303 thread_name = kUnknownName; 303 thread_name = kUnknownName;
304 base::wcslcpy(impl_->thread_name(slot), thread_name.c_str(), 304 base::wcslcpy(impl_->thread_name(slot), thread_name.c_str(),
305 kMaxThreadNameLength); 305 kMaxThreadNameLength);
306 *(impl_->thread_tid(slot)) = PlatformThread::CurrentId(); 306 *(impl_->thread_tid(slot)) = PlatformThread::CurrentId();
307 *(impl_->thread_pid(slot)) = process_util::GetCurrentProcId(); 307 *(impl_->thread_pid(slot)) = base::GetCurrentProcId();
308 } 308 }
309 309
310 // Set our thread local storage. 310 // Set our thread local storage.
311 StatsTableTLSData* data = new StatsTableTLSData; 311 StatsTableTLSData* data = new StatsTableTLSData;
312 data->table = this; 312 data->table = this;
313 data->slot = slot; 313 data->slot = slot;
314 tls_index_.Set(data); 314 tls_index_.Set(data);
315 return slot; 315 return slot;
316 } 316 }
317 317
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 int StatsTable::AddCounter(const std::wstring& name) { 447 int StatsTable::AddCounter(const std::wstring& name) {
448 DCHECK(impl_); 448 DCHECK(impl_);
449 449
450 if (!impl_) 450 if (!impl_)
451 return 0; 451 return 0;
452 452
453 int counter_id = 0; 453 int counter_id = 0;
454 { 454 {
455 // To add a counter to the shared memory, we need the 455 // To add a counter to the shared memory, we need the
456 // shared memory lock. 456 // shared memory lock.
457 SharedMemoryAutoLock lock(impl_->shared_memory()); 457 base::SharedMemoryAutoLock lock(impl_->shared_memory());
458 458
459 // We have space, so create a new counter. 459 // We have space, so create a new counter.
460 counter_id = FindCounterOrEmptyRow(name); 460 counter_id = FindCounterOrEmptyRow(name);
461 if (!counter_id) 461 if (!counter_id)
462 return 0; 462 return 0;
463 463
464 std::wstring counter_name = name; 464 std::wstring counter_name = name;
465 if (name.empty()) 465 if (name.empty())
466 counter_name = kUnknownName; 466 counter_name = kUnknownName;
467 base::wcslcpy(impl_->counter_name(counter_id), counter_name.c_str(), 467 base::wcslcpy(impl_->counter_name(counter_id), counter_name.c_str(),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 return NULL; 549 return NULL;
550 550
551 // Find the counter id for the counter. 551 // Find the counter id for the counter.
552 std::wstring str_name(name); 552 std::wstring str_name(name);
553 int counter = table->FindCounter(str_name); 553 int counter = table->FindCounter(str_name);
554 554
555 // Now we can find the location in the table. 555 // Now we can find the location in the table.
556 return table->GetLocation(counter, slot); 556 return table->GetLocation(counter, slot);
557 } 557 }
558 558
OLDNEW
« no previous file with comments | « base/shared_memory_win.cc ('k') | base/stats_table_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698