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

Side by Side Diff: base/stats_table.cc

Issue 18677: Use PlatformThreadId, not int when dealing with thread ids. (Closed)
Patch Set: Addressing comments Created 11 years, 11 months 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
« no previous file with comments | « base/simple_thread.h ('k') | base/thread.h » ('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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 char* thread_name(int slot_id) const { 125 char* thread_name(int slot_id) const {
126 return &thread_names_table_[ 126 return &thread_names_table_[
127 (slot_id-1) * (StatsTable::kMaxThreadNameLength)]; 127 (slot_id-1) * (StatsTable::kMaxThreadNameLength)];
128 } 128 }
129 int* thread_tid(int slot_id) const { 129 PlatformThreadId* thread_tid(int slot_id) const {
130 return &(thread_tid_table_[slot_id-1]); 130 return &(thread_tid_table_[slot_id-1]);
131 } 131 }
132 int* thread_pid(int slot_id) const { 132 int* thread_pid(int slot_id) const {
133 return &(thread_pid_table_[slot_id-1]); 133 return &(thread_pid_table_[slot_id-1]);
134 } 134 }
135 char* counter_name(int counter_id) const { 135 char* counter_name(int counter_id) const {
136 return &counter_names_table_[ 136 return &counter_names_table_[
137 (counter_id-1) * (StatsTable::kMaxCounterNameLength)]; 137 (counter_id-1) * (StatsTable::kMaxCounterNameLength)];
138 } 138 }
139 int* row(int counter_id) const { 139 int* row(int counter_id) const {
140 return &data_table_[(counter_id-1) * max_threads()]; 140 return &data_table_[(counter_id-1) * max_threads()];
141 } 141 }
142 142
143 private: 143 private:
144 // Constructor is private because you should use New() instead. 144 // Constructor is private because you should use New() instead.
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 base::SharedMemory shared_memory_; 155 base::SharedMemory shared_memory_;
156 TableHeader* table_header_; 156 TableHeader* table_header_;
157 char* thread_names_table_; 157 char* thread_names_table_;
158 int* thread_tid_table_; 158 PlatformThreadId* thread_tid_table_;
159 int* thread_pid_table_; 159 int* thread_pid_table_;
160 char* counter_names_table_; 160 char* 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::string& name, 165 StatsTablePrivate* StatsTablePrivate::New(const std::string& name,
166 int size, 166 int size,
167 int max_threads, 167 int max_threads,
168 int max_counters) { 168 int max_counters) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 offset += AlignOffset(offset); 210 offset += AlignOffset(offset);
211 211
212 // Verify we're looking at a valid StatsTable. 212 // Verify we're looking at a valid StatsTable.
213 DCHECK_EQ(table_header_->version, kTableVersion); 213 DCHECK_EQ(table_header_->version, kTableVersion);
214 214
215 thread_names_table_ = reinterpret_cast<char*>(data + offset); 215 thread_names_table_ = reinterpret_cast<char*>(data + offset);
216 offset += sizeof(char) * 216 offset += sizeof(char) *
217 max_threads() * StatsTable::kMaxThreadNameLength; 217 max_threads() * StatsTable::kMaxThreadNameLength;
218 offset += AlignOffset(offset); 218 offset += AlignOffset(offset);
219 219
220 thread_tid_table_ = reinterpret_cast<int*>(data + offset); 220 thread_tid_table_ = reinterpret_cast<PlatformThreadId*>(data + offset);
221 offset += sizeof(int) * max_threads(); 221 offset += sizeof(int) * max_threads();
222 offset += AlignOffset(offset); 222 offset += AlignOffset(offset);
223 223
224 thread_pid_table_ = reinterpret_cast<int*>(data + offset); 224 thread_pid_table_ = reinterpret_cast<int*>(data + offset);
225 offset += sizeof(int) * max_threads(); 225 offset += sizeof(int) * max_threads();
226 offset += AlignOffset(offset); 226 offset += AlignOffset(offset);
227 227
228 counter_names_table_ = reinterpret_cast<char*>(data + offset); 228 counter_names_table_ = reinterpret_cast<char*>(data + offset);
229 offset += sizeof(char) * 229 offset += sizeof(char) *
230 max_counters() * StatsTable::kMaxCounterNameLength; 230 max_counters() * StatsTable::kMaxCounterNameLength;
(...skipping 318 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::string str_name(name); 552 std::string 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/simple_thread.h ('k') | base/thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698