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

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

Issue 2754483002: Add analyzer support for multiple processes. (Closed)
Patch Set: rebased Created 3 years, 9 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 // Activity tracking provides a low-overhead method of collecting information 5 // Activity tracking provides a low-overhead method of collecting information
6 // about the state of the application for analysis both while it is running 6 // about the state of the application for analysis both while it is running
7 // and after it has terminated unexpectedly. Its primary purpose is to help 7 // and after it has terminated unexpectedly. Its primary purpose is to help
8 // locate reasons the browser becomes unresponsive by providing insight into 8 // locate reasons the browser becomes unresponsive by providing insight into
9 // what all the various threads and processes are (or were) doing. 9 // what all the various threads and processes are (or were) doing.
10 10
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 // - the memory has been released back to the OS 370 // - the memory has been released back to the OS
371 // - the memory belongs to a different process's address space 371 // - the memory belongs to a different process's address space
372 // Dereferencing the returned StringPiece when the memory is not accessible 372 // Dereferencing the returned StringPiece when the memory is not accessible
373 // will cause the program to SEGV! 373 // will cause the program to SEGV!
374 StringPiece GetReference() const; 374 StringPiece GetReference() const;
375 StringPiece GetStringReference() const; 375 StringPiece GetStringReference() const;
376 376
377 private: 377 private:
378 friend class ActivityUserData; 378 friend class ActivityUserData;
379 379
380 ValueType type_; 380 ValueType type_ = END_OF_VALUES;
381 uint64_t short_value_; // Used to hold copy of numbers, etc. 381 uint64_t short_value_; // Used to hold copy of numbers, etc.
382 std::string long_value_; // Used to hold copy of raw/string data. 382 std::string long_value_; // Used to hold copy of raw/string data.
383 StringPiece ref_value_; // Used to hold reference to external data. 383 StringPiece ref_value_; // Used to hold reference to external data.
384 }; 384 };
385 385
386 using Snapshot = std::map<std::string, TypedValue>; 386 using Snapshot = std::map<std::string, TypedValue>;
387 387
388 ActivityUserData(void* memory, size_t size); 388 ActivityUserData(void* memory, size_t size);
389 virtual ~ActivityUserData(); 389 virtual ~ActivityUserData();
390 390
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 // of information. 433 // of information.
434 void SetReference(StringPiece name, const void* memory, size_t size) { 434 void SetReference(StringPiece name, const void* memory, size_t size) {
435 SetReference(name, RAW_VALUE_REFERENCE, memory, size); 435 SetReference(name, RAW_VALUE_REFERENCE, memory, size);
436 } 436 }
437 void SetStringReference(StringPiece name, StringPiece value) { 437 void SetStringReference(StringPiece name, StringPiece value) {
438 SetReference(name, STRING_VALUE_REFERENCE, value.data(), value.length()); 438 SetReference(name, STRING_VALUE_REFERENCE, value.data(), value.length());
439 } 439 }
440 440
441 // Creates a snapshot of the key/value pairs contained within. The returned 441 // Creates a snapshot of the key/value pairs contained within. The returned
442 // data will be fixed, independent of whatever changes afterward. There is 442 // data will be fixed, independent of whatever changes afterward. There is
443 // protection against concurrent modification of the values but no protection 443 // some protection against concurrent modification. This will return false
444 // against a complete overwrite of the contents; the caller must ensure that 444 // if the data is invalid or if a complete overwrite of the contents is
445 // the memory segment is not going to be re-initialized while this runs. 445 // detected.
446 bool CreateSnapshot(Snapshot* output_snapshot) const; 446 bool CreateSnapshot(Snapshot* output_snapshot) const;
447 447
448 // Gets the base memory address used for storing data. 448 // Gets the base memory address used for storing data.
449 const void* GetBaseAddress() const; 449 const void* GetBaseAddress() const;
450 450
451 // Explicitly sets the process ID. 451 // Explicitly sets the process ID.
452 void SetOwningProcessIdForTesting(ProcessId pid, int64_t stamp); 452 void SetOwningProcessIdForTesting(ProcessId pid, int64_t stamp);
453 453
454 // Gets the associated process ID, in native form, and the creation timestamp 454 // Gets the associated process ID, in native form, and the creation timestamp
455 // from tracker memory without loading the entire structure for analysis. This 455 // from tracker memory without loading the entire structure for analysis. This
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 524
525 // Information about the memory block in which new data can be stored. These 525 // Information about the memory block in which new data can be stored. These
526 // are "mutable" because they change even on "const" objects that are just 526 // are "mutable" because they change even on "const" objects that are just
527 // skipping already set values. 527 // skipping already set values.
528 mutable char* memory_; 528 mutable char* memory_;
529 mutable size_t available_; 529 mutable size_t available_;
530 530
531 // A pointer to the memory header for this instance. 531 // A pointer to the memory header for this instance.
532 MemoryHeader* const header_; 532 MemoryHeader* const header_;
533 533
534 // These hold values used when initially creating the object. They are
535 // compared against current header values to check for outside changes.
536 const uint32_t orig_data_id;
537 const int64_t orig_process_id;
538 const int64_t orig_create_stamp;
539
534 DISALLOW_COPY_AND_ASSIGN(ActivityUserData); 540 DISALLOW_COPY_AND_ASSIGN(ActivityUserData);
535 }; 541 };
536 542
537 // This class manages tracking a stack of activities for a single thread in 543 // This class manages tracking a stack of activities for a single thread in
538 // a persistent manner, implementing a bounded-size stack in a fixed-size 544 // a persistent manner, implementing a bounded-size stack in a fixed-size
539 // memory allocation. In order to support an operational mode where another 545 // memory allocation. In order to support an operational mode where another
540 // thread is analyzing this data in real-time, atomic operations are used 546 // thread is analyzing this data in real-time, atomic operations are used
541 // where necessary to guarantee a consistent view from the outside. 547 // where necessary to guarantee a consistent view from the outside.
542 // 548 //
543 // This class is not generally used directly but instead managed by the 549 // This class is not generally used directly but instead managed by the
(...skipping 14 matching lines...) Expand all
558 struct BASE_EXPORT Snapshot { 564 struct BASE_EXPORT Snapshot {
559 // Explicit constructor/destructor are needed because of complex types 565 // Explicit constructor/destructor are needed because of complex types
560 // with non-trivial default constructors and destructors. 566 // with non-trivial default constructors and destructors.
561 Snapshot(); 567 Snapshot();
562 ~Snapshot(); 568 ~Snapshot();
563 569
564 // The name of the thread as set when it was created. The name may be 570 // The name of the thread as set when it was created. The name may be
565 // truncated due to internal length limitations. 571 // truncated due to internal length limitations.
566 std::string thread_name; 572 std::string thread_name;
567 573
574 // The timestamp at which this process was created.
575 int64_t create_stamp;
576
568 // The process and thread IDs. These values have no meaning other than 577 // The process and thread IDs. These values have no meaning other than
569 // they uniquely identify a running process and a running thread within 578 // they uniquely identify a running process and a running thread within
570 // that process. Thread-IDs can be re-used across different processes 579 // that process. Thread-IDs can be re-used across different processes
571 // and both can be re-used after the process/thread exits. 580 // and both can be re-used after the process/thread exits.
572 int64_t process_id = 0; 581 int64_t process_id = 0;
573 int64_t thread_id = 0; 582 int64_t thread_id = 0;
574 583
575 // The current stack of activities that are underway for this thread. It 584 // The current stack of activities that are underway for this thread. It
576 // is limited in its maximum size with later entries being left off. 585 // is limited in its maximum size with later entries being left off.
577 std::vector<Activity> activity_stack; 586 std::vector<Activity> activity_stack;
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 ScopedProcessWaitActivity(const void* program_counter, 1270 ScopedProcessWaitActivity(const void* program_counter,
1262 const base::Process* process); 1271 const base::Process* process);
1263 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity); 1272 DISALLOW_COPY_AND_ASSIGN(ScopedProcessWaitActivity);
1264 }; 1273 };
1265 #endif 1274 #endif
1266 1275
1267 } // namespace debug 1276 } // namespace debug
1268 } // namespace base 1277 } // namespace base
1269 1278
1270 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_ 1279 #endif // BASE_DEBUG_ACTIVITY_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698