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

Side by Side Diff: base/debug/trace_event_impl.cc

Issue 374043002: Fix tracing 64-bit to 32-bit truncations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « base/debug/trace_event_impl.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/debug/trace_event_impl.h" 5 #include "base/debug/trace_event_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 uintptr_t category_ptr = reinterpret_cast<uintptr_t>(category_group_enabled); 1202 uintptr_t category_ptr = reinterpret_cast<uintptr_t>(category_group_enabled);
1203 DCHECK(category_ptr >= category_begin && 1203 DCHECK(category_ptr >= category_begin &&
1204 category_ptr < reinterpret_cast<uintptr_t>( 1204 category_ptr < reinterpret_cast<uintptr_t>(
1205 g_category_group_enabled + MAX_CATEGORY_GROUPS)) << 1205 g_category_group_enabled + MAX_CATEGORY_GROUPS)) <<
1206 "out of bounds category pointer"; 1206 "out of bounds category pointer";
1207 uintptr_t category_index = 1207 uintptr_t category_index =
1208 (category_ptr - category_begin) / sizeof(g_category_group_enabled[0]); 1208 (category_ptr - category_begin) / sizeof(g_category_group_enabled[0]);
1209 return g_category_groups[category_index]; 1209 return g_category_groups[category_index];
1210 } 1210 }
1211 1211
1212 void TraceLog::UpdateCategoryGroupEnabledFlag(int category_index) { 1212 void TraceLog::UpdateCategoryGroupEnabledFlag(size_t category_index) {
1213 unsigned char enabled_flag = 0; 1213 unsigned char enabled_flag = 0;
1214 const char* category_group = g_category_groups[category_index]; 1214 const char* category_group = g_category_groups[category_index];
1215 if (mode_ == RECORDING_MODE && 1215 if (mode_ == RECORDING_MODE &&
1216 category_filter_.IsCategoryGroupEnabled(category_group)) 1216 category_filter_.IsCategoryGroupEnabled(category_group))
1217 enabled_flag |= ENABLED_FOR_RECORDING; 1217 enabled_flag |= ENABLED_FOR_RECORDING;
1218 else if (mode_ == MONITORING_MODE && 1218 else if (mode_ == MONITORING_MODE &&
1219 category_filter_.IsCategoryGroupEnabled(category_group)) 1219 category_filter_.IsCategoryGroupEnabled(category_group))
1220 enabled_flag |= ENABLED_FOR_MONITORING; 1220 enabled_flag |= ENABLED_FOR_MONITORING;
1221 if (event_callback_ && 1221 if (event_callback_ &&
1222 event_callback_category_filter_.IsCategoryGroupEnabled(category_group)) 1222 event_callback_category_filter_.IsCategoryGroupEnabled(category_group))
1223 enabled_flag |= ENABLED_FOR_EVENT_CALLBACK; 1223 enabled_flag |= ENABLED_FOR_EVENT_CALLBACK;
1224 g_category_group_enabled[category_index] = enabled_flag; 1224 g_category_group_enabled[category_index] = enabled_flag;
1225 } 1225 }
1226 1226
1227 void TraceLog::UpdateCategoryGroupEnabledFlags() { 1227 void TraceLog::UpdateCategoryGroupEnabledFlags() {
1228 int category_index = base::subtle::NoBarrier_Load(&g_category_index); 1228 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index);
1229 for (int i = 0; i < category_index; i++) 1229 for (size_t i = 0; i < category_index; i++)
1230 UpdateCategoryGroupEnabledFlag(i); 1230 UpdateCategoryGroupEnabledFlag(i);
1231 } 1231 }
1232 1232
1233 void TraceLog::UpdateSyntheticDelaysFromCategoryFilter() { 1233 void TraceLog::UpdateSyntheticDelaysFromCategoryFilter() {
1234 ResetTraceEventSyntheticDelays(); 1234 ResetTraceEventSyntheticDelays();
1235 const CategoryFilter::StringList& delays = 1235 const CategoryFilter::StringList& delays =
1236 category_filter_.GetSyntheticDelayValues(); 1236 category_filter_.GetSyntheticDelayValues();
1237 CategoryFilter::StringList::const_iterator ci; 1237 CategoryFilter::StringList::const_iterator ci;
1238 for (ci = delays.begin(); ci != delays.end(); ++ci) { 1238 for (ci = delays.begin(); ci != delays.end(); ++ci) {
1239 StringTokenizer tokens(*ci, ";"); 1239 StringTokenizer tokens(*ci, ";");
(...skipping 17 matching lines...) Expand all
1257 } 1257 }
1258 } 1258 }
1259 } 1259 }
1260 } 1260 }
1261 1261
1262 const unsigned char* TraceLog::GetCategoryGroupEnabledInternal( 1262 const unsigned char* TraceLog::GetCategoryGroupEnabledInternal(
1263 const char* category_group) { 1263 const char* category_group) {
1264 DCHECK(!strchr(category_group, '"')) << 1264 DCHECK(!strchr(category_group, '"')) <<
1265 "Category groups may not contain double quote"; 1265 "Category groups may not contain double quote";
1266 // The g_category_groups is append only, avoid using a lock for the fast path. 1266 // The g_category_groups is append only, avoid using a lock for the fast path.
1267 int current_category_index = base::subtle::Acquire_Load(&g_category_index); 1267 size_t current_category_index = base::subtle::Acquire_Load(&g_category_index);
1268 1268
1269 // Search for pre-existing category group. 1269 // Search for pre-existing category group.
1270 for (int i = 0; i < current_category_index; ++i) { 1270 for (size_t i = 0; i < current_category_index; ++i) {
1271 if (strcmp(g_category_groups[i], category_group) == 0) { 1271 if (strcmp(g_category_groups[i], category_group) == 0) {
1272 return &g_category_group_enabled[i]; 1272 return &g_category_group_enabled[i];
1273 } 1273 }
1274 } 1274 }
1275 1275
1276 unsigned char* category_group_enabled = NULL; 1276 unsigned char* category_group_enabled = NULL;
1277 // This is the slow path: the lock is not held in the case above, so more 1277 // This is the slow path: the lock is not held in the case above, so more
1278 // than one thread could have reached here trying to add the same category. 1278 // than one thread could have reached here trying to add the same category.
1279 // Only hold to lock when actually appending a new category, and 1279 // Only hold to lock when actually appending a new category, and
1280 // check the categories groups again. 1280 // check the categories groups again.
1281 AutoLock lock(lock_); 1281 AutoLock lock(lock_);
1282 int category_index = base::subtle::Acquire_Load(&g_category_index); 1282 size_t category_index = base::subtle::Acquire_Load(&g_category_index);
1283 for (int i = 0; i < category_index; ++i) { 1283 for (size_t i = 0; i < category_index; ++i) {
1284 if (strcmp(g_category_groups[i], category_group) == 0) { 1284 if (strcmp(g_category_groups[i], category_group) == 0) {
1285 return &g_category_group_enabled[i]; 1285 return &g_category_group_enabled[i];
1286 } 1286 }
1287 } 1287 }
1288 1288
1289 // Create a new category group. 1289 // Create a new category group.
1290 DCHECK(category_index < MAX_CATEGORY_GROUPS) << 1290 DCHECK(category_index < MAX_CATEGORY_GROUPS) <<
1291 "must increase MAX_CATEGORY_GROUPS"; 1291 "must increase MAX_CATEGORY_GROUPS";
1292 if (category_index < MAX_CATEGORY_GROUPS) { 1292 if (category_index < MAX_CATEGORY_GROUPS) {
1293 // Don't hold on to the category_group pointer, so that we can create 1293 // Don't hold on to the category_group pointer, so that we can create
(...skipping 15 matching lines...) Expand all
1309 &g_category_group_enabled[g_category_categories_exhausted]; 1309 &g_category_group_enabled[g_category_categories_exhausted];
1310 } 1310 }
1311 return category_group_enabled; 1311 return category_group_enabled;
1312 } 1312 }
1313 1313
1314 void TraceLog::GetKnownCategoryGroups( 1314 void TraceLog::GetKnownCategoryGroups(
1315 std::vector<std::string>* category_groups) { 1315 std::vector<std::string>* category_groups) {
1316 AutoLock lock(lock_); 1316 AutoLock lock(lock_);
1317 category_groups->push_back( 1317 category_groups->push_back(
1318 g_category_groups[g_category_trace_event_overhead]); 1318 g_category_groups[g_category_trace_event_overhead]);
1319 int category_index = base::subtle::NoBarrier_Load(&g_category_index); 1319 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index);
1320 for (int i = g_num_builtin_categories; i < category_index; i++) 1320 for (size_t i = g_num_builtin_categories; i < category_index; i++)
1321 category_groups->push_back(g_category_groups[i]); 1321 category_groups->push_back(g_category_groups[i]);
1322 } 1322 }
1323 1323
1324 void TraceLog::SetEnabled(const CategoryFilter& category_filter, 1324 void TraceLog::SetEnabled(const CategoryFilter& category_filter,
1325 Mode mode, 1325 Mode mode,
1326 Options options) { 1326 Options options) {
1327 std::vector<EnabledStateObserver*> observer_list; 1327 std::vector<EnabledStateObserver*> observer_list;
1328 { 1328 {
1329 AutoLock lock(lock_); 1329 AutoLock lock(lock_);
1330 1330
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after
2428 } 2428 }
2429 2429
2430 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 2430 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
2431 if (*category_group_enabled_) { 2431 if (*category_group_enabled_) {
2432 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, 2432 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_,
2433 name_, event_handle_); 2433 name_, event_handle_);
2434 } 2434 }
2435 } 2435 }
2436 2436
2437 } // namespace trace_event_internal 2437 } // namespace trace_event_internal
OLDNEW
« no previous file with comments | « base/debug/trace_event_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698