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

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

Issue 2583223002: Collect stability data from global and activity scopes (Closed)
Patch Set: Merge Created 3 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/activity_tracker.h" 5 #include "base/debug/activity_tracker.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits>
9 #include <utility>
8 10
9 #include "base/debug/stack_trace.h" 11 #include "base/debug/stack_trace.h"
10 #include "base/files/file.h" 12 #include "base/files/file.h"
11 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
12 #include "base/files/memory_mapped_file.h" 14 #include "base/files/memory_mapped_file.h"
13 #include "base/logging.h" 15 #include "base/logging.h"
14 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
15 #include "base/memory/ptr_util.h"
16 #include "base/metrics/field_trial.h" 17 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram_macros.h" 18 #include "base/metrics/histogram_macros.h"
18 #include "base/pending_task.h" 19 #include "base/pending_task.h"
19 #include "base/process/process.h" 20 #include "base/process/process.h"
20 #include "base/process/process_handle.h" 21 #include "base/process/process_handle.h"
21 #include "base/stl_util.h" 22 #include "base/stl_util.h"
22 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
23 #include "base/threading/platform_thread.h" 24 #include "base/threading/platform_thread.h"
24 25
25 namespace base { 26 namespace base {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 #else 199 #else
199 activity->call_stack[0] = 0; 200 activity->call_stack[0] = 0;
200 #endif 201 #endif
201 } 202 }
202 203
203 ActivityUserData::TypedValue::TypedValue() {} 204 ActivityUserData::TypedValue::TypedValue() {}
204 ActivityUserData::TypedValue::TypedValue(const TypedValue& other) = default; 205 ActivityUserData::TypedValue::TypedValue(const TypedValue& other) = default;
205 ActivityUserData::TypedValue::~TypedValue() {} 206 ActivityUserData::TypedValue::~TypedValue() {}
206 207
207 StringPiece ActivityUserData::TypedValue::Get() const { 208 StringPiece ActivityUserData::TypedValue::Get() const {
208 DCHECK_EQ(RAW_VALUE, type); 209 DCHECK_EQ(RAW_VALUE, type_);
209 return long_value; 210 return long_value_;
210 } 211 }
211 212
212 StringPiece ActivityUserData::TypedValue::GetString() const { 213 StringPiece ActivityUserData::TypedValue::GetString() const {
213 DCHECK_EQ(STRING_VALUE, type); 214 DCHECK_EQ(STRING_VALUE, type_);
214 return long_value; 215 return long_value_;
215 } 216 }
216 217
217 bool ActivityUserData::TypedValue::GetBool() const { 218 bool ActivityUserData::TypedValue::GetBool() const {
218 DCHECK_EQ(BOOL_VALUE, type); 219 DCHECK_EQ(BOOL_VALUE, type_);
219 return short_value != 0; 220 return short_value_ != 0;
220 } 221 }
221 222
222 char ActivityUserData::TypedValue::GetChar() const { 223 char ActivityUserData::TypedValue::GetChar() const {
223 DCHECK_EQ(CHAR_VALUE, type); 224 DCHECK_EQ(CHAR_VALUE, type_);
224 return static_cast<char>(short_value); 225 return static_cast<char>(short_value_);
225 } 226 }
226 227
227 int64_t ActivityUserData::TypedValue::GetInt() const { 228 int64_t ActivityUserData::TypedValue::GetInt() const {
228 DCHECK_EQ(SIGNED_VALUE, type); 229 DCHECK_EQ(SIGNED_VALUE, type_);
229 return static_cast<int64_t>(short_value); 230 return static_cast<int64_t>(short_value_);
230 } 231 }
231 232
232 uint64_t ActivityUserData::TypedValue::GetUint() const { 233 uint64_t ActivityUserData::TypedValue::GetUint() const {
233 DCHECK_EQ(UNSIGNED_VALUE, type); 234 DCHECK_EQ(UNSIGNED_VALUE, type_);
234 return static_cast<uint64_t>(short_value); 235 return static_cast<uint64_t>(short_value_);
235 } 236 }
236 237
237 StringPiece ActivityUserData::TypedValue::GetReference() const { 238 StringPiece ActivityUserData::TypedValue::GetReference() const {
238 DCHECK_EQ(RAW_VALUE_REFERENCE, type); 239 DCHECK_EQ(RAW_VALUE_REFERENCE, type_);
239 return ref_value; 240 return ref_value_;
240 } 241 }
241 242
242 StringPiece ActivityUserData::TypedValue::GetStringReference() const { 243 StringPiece ActivityUserData::TypedValue::GetStringReference() const {
243 DCHECK_EQ(STRING_VALUE_REFERENCE, type); 244 DCHECK_EQ(STRING_VALUE_REFERENCE, type_);
244 return ref_value; 245 return ref_value_;
245 } 246 }
246 247
247 ActivityUserData::ValueInfo::ValueInfo() {} 248 ActivityUserData::ValueInfo::ValueInfo() {}
248 ActivityUserData::ValueInfo::ValueInfo(ValueInfo&&) = default; 249 ActivityUserData::ValueInfo::ValueInfo(ValueInfo&&) = default;
249 ActivityUserData::ValueInfo::~ValueInfo() {} 250 ActivityUserData::ValueInfo::~ValueInfo() {}
250 251
251 std::atomic<uint32_t> ActivityUserData::next_id_; 252 std::atomic<uint32_t> ActivityUserData::next_id_;
252 253
253 ActivityUserData::ActivityUserData(void* memory, size_t size) 254 ActivityUserData::ActivityUserData(void* memory, size_t size)
254 : memory_(reinterpret_cast<char*>(memory)), 255 : memory_(reinterpret_cast<char*>(memory)),
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 bool ActivityUserData::CreateSnapshot(Snapshot* output_snapshot) const { 423 bool ActivityUserData::CreateSnapshot(Snapshot* output_snapshot) const {
423 DCHECK(output_snapshot); 424 DCHECK(output_snapshot);
424 DCHECK(output_snapshot->empty()); 425 DCHECK(output_snapshot->empty());
425 426
426 // Find any new data that may have been added by an active instance of this 427 // Find any new data that may have been added by an active instance of this
427 // class that is adding records. 428 // class that is adding records.
428 ImportExistingData(); 429 ImportExistingData();
429 430
430 for (const auto& entry : values_) { 431 for (const auto& entry : values_) {
431 TypedValue value; 432 TypedValue value;
432 value.type = entry.second.type; 433 value.type_ = entry.second.type;
433 DCHECK_GE(entry.second.extent, 434 DCHECK_GE(entry.second.extent,
434 entry.second.size_ptr->load(std::memory_order_relaxed)); 435 entry.second.size_ptr->load(std::memory_order_relaxed));
435 436
436 switch (entry.second.type) { 437 switch (entry.second.type) {
437 case RAW_VALUE: 438 case RAW_VALUE:
438 case STRING_VALUE: 439 case STRING_VALUE:
439 value.long_value = 440 value.long_value_ =
440 std::string(reinterpret_cast<char*>(entry.second.memory), 441 std::string(reinterpret_cast<char*>(entry.second.memory),
441 entry.second.size_ptr->load(std::memory_order_relaxed)); 442 entry.second.size_ptr->load(std::memory_order_relaxed));
442 break; 443 break;
443 case RAW_VALUE_REFERENCE: 444 case RAW_VALUE_REFERENCE:
444 case STRING_VALUE_REFERENCE: { 445 case STRING_VALUE_REFERENCE: {
445 ReferenceRecord* ref = 446 ReferenceRecord* ref =
446 reinterpret_cast<ReferenceRecord*>(entry.second.memory); 447 reinterpret_cast<ReferenceRecord*>(entry.second.memory);
447 value.ref_value = StringPiece( 448 value.ref_value_ = StringPiece(
448 reinterpret_cast<char*>(static_cast<uintptr_t>(ref->address)), 449 reinterpret_cast<char*>(static_cast<uintptr_t>(ref->address)),
449 static_cast<size_t>(ref->size)); 450 static_cast<size_t>(ref->size));
450 } break; 451 } break;
451 case BOOL_VALUE: 452 case BOOL_VALUE:
452 case CHAR_VALUE: 453 case CHAR_VALUE:
453 value.short_value = *reinterpret_cast<char*>(entry.second.memory); 454 value.short_value_ = *reinterpret_cast<char*>(entry.second.memory);
454 break; 455 break;
455 case SIGNED_VALUE: 456 case SIGNED_VALUE:
456 case UNSIGNED_VALUE: 457 case UNSIGNED_VALUE:
457 value.short_value = *reinterpret_cast<uint64_t*>(entry.second.memory); 458 value.short_value_ = *reinterpret_cast<uint64_t*>(entry.second.memory);
458 break; 459 break;
459 case END_OF_VALUES: // Included for completeness purposes. 460 case END_OF_VALUES: // Included for completeness purposes.
460 NOTREACHED(); 461 NOTREACHED();
461 } 462 }
462 auto inserted = output_snapshot->insert( 463 auto inserted = output_snapshot->insert(
463 std::make_pair(entry.second.name.as_string(), std::move(value))); 464 std::make_pair(entry.second.name.as_string(), std::move(value)));
464 DCHECK(inserted.second); // True if inserted, false if existed. 465 DCHECK(inserted.second); // True if inserted, false if existed.
465 } 466 }
466 467
467 return true; 468 return true;
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 : GlobalActivityTracker::ScopedThreadActivity( 1210 : GlobalActivityTracker::ScopedThreadActivity(
1210 program_counter, 1211 program_counter,
1211 nullptr, 1212 nullptr,
1212 Activity::ACT_PROCESS_WAIT, 1213 Activity::ACT_PROCESS_WAIT,
1213 ActivityData::ForProcess(process->Pid()), 1214 ActivityData::ForProcess(process->Pid()),
1214 /*lock_allowed=*/true) {} 1215 /*lock_allowed=*/true) {}
1215 #endif 1216 #endif
1216 1217
1217 } // namespace debug 1218 } // namespace debug
1218 } // namespace base 1219 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698