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

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

Issue 1980743002: Track thread activities in order to diagnose hangs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@readwrite-mmf
Patch Set: cleaned up for review Created 4 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef BASE_METRICS_ACTIVITY_ANALYZER_H_
6 #define BASE_METRICS_ACTIVITY_ANALYZER_H_
7
8 #include <map>
9 #include <memory>
10 #include <set>
11
12 #include "base/base_export.h"
13 #include "base/debug/activity_tracker.h"
14
15 namespace base {
16
17 namespace debug {
18
19 // Be sure not to create multiple Analyzers for given tracker data as parallel
20 // operation could lead to inconsistencies from concurrent synchronization with
21 // an active tracker.
22 class BASE_EXPORT ThreadActivityAnalyzer {
Sigurður Ásgeirsson 2016/06/14 15:28:13 describe purpose and perhaps intended usage of cla
bcwhite 2016/06/14 19:48:45 Done.
23 public:
24 using Activity = ThreadActivityTracker::Activity;
25 using ActivitySnapshot = ThreadActivityTracker::ActivitySnapshot;
26
27 class ThreadKey {
28 public:
29 ThreadKey(int64_t pid, int64_t tid) : pid_(pid), tid_(tid) {}
30
31 bool operator<(const ThreadKey& rhs) const {
32 if (pid_ != rhs.pid_)
33 return pid_ < rhs.pid_;
34 return tid_ < rhs.tid_;
35 }
36
37 bool operator==(const ThreadKey& rhs) const {
38 return (pid_ == rhs.pid_ && tid_ == rhs.tid_);
39 }
40
41 private:
42 int64_t pid_;
43 int64_t tid_;
44 };
45
46 // Creates an analyzer for an existing activity-tracker. The passed tracker
Sigurður Ásgeirsson 2016/06/14 15:28:12 nit: |tracker| throughout this comment?
bcwhite 2016/06/14 19:48:45 Done.
47 // must live at least as long as the created object. The tracker may continue
48 // to be active even with an attached analyzer.
49 explicit ThreadActivityAnalyzer(const ThreadActivityTracker* tracker);
50
51 // Creates an anaylzer for a block of memory currently or previously in-use
Sigurður Ásgeirsson 2016/06/14 15:28:12 nit: analyzer
bcwhite 2016/06/14 19:48:45 Done.
52 // by an activity-tracker. The memory must live at least as long as the
53 // created object. It's permissable for a tracker to remain active on the
54 // memory from this thread, other threads, or even other processes.
55 ThreadActivityAnalyzer(void* base, size_t size);
56
57 // Creates an anaylzer for a block of memory held within a persistent-memory
Sigurður Ásgeirsson 2016/06/14 15:28:13 nit: analyzer
bcwhite 2016/06/14 19:48:45 Done.
58 // |allocator| at the given |reference|. The memory must live at least as
59 // long as the created object. It's permissable for a tracker to remain active
60 // on the memory from this thread, other threads, or even other processes.
61 // The reference must be to an object of type kTypeIdActivityTracker.
62 ThreadActivityAnalyzer(PersistentMemoryAllocator* allocator,
Sigurður Ásgeirsson 2016/06/14 15:28:13 as a general comment on this interface, you have p
bcwhite 2016/06/14 19:48:45 Like all other constructors, passing bad data will
63 PersistentMemoryAllocator::Reference reference);
64
65 ~ThreadActivityAnalyzer();
66
67 // Returns if the contained data is valid. Results from all other methods
Sigurður Ásgeirsson 2016/06/14 15:28:13 ubernit: and if contained data is invalid, never r
bcwhite 2016/06/14 19:48:45 Done. :-)
68 // are undefined if this returns false.
69 bool IsValid() { return activity_snapshot_valid_; }
70
71 // Gets the name of the thread.
72 std::string& GetThreadName() {
Sigurður Ásgeirsson 2016/06/14 15:28:12 no non-const references.
bcwhite 2016/06/14 19:48:45 Done.
73 return activity_snapshot_.thread_name;
74 }
75
76 // Gets the TheadKey for this thread.
77 ThreadKey GetThreadKey() {
78 return ThreadKey(activity_snapshot_.process_id,
79 activity_snapshot_.thread_id);
80 }
81
82 private:
83 friend class GlobalActivityAnalyzer;
84
85 ActivitySnapshot activity_snapshot_;
86 bool activity_snapshot_valid_;
87
88 // A reference into a persistent memory allocator, used by the global
89 // analyzer to know where this tracker came from.
90 PersistentMemoryAllocator::Reference allocator_reference_ = 0;
Sigurður Ásgeirsson 2016/06/14 15:28:13 nice - I didn't know we could do this.
bcwhite 2016/06/14 19:48:45 Inline initialization? New in C++11. Very handy!
91
92 DISALLOW_COPY_AND_ASSIGN(ThreadActivityAnalyzer);
93 };
94
95
96 class BASE_EXPORT GlobalActivityAnalyzer {
Sigurður Ásgeirsson 2016/06/14 15:28:12 Describe class purpose and intended usage?
bcwhite 2016/06/14 19:48:45 Done.
97 public:
98 using ThreadKey = ThreadActivityAnalyzer::ThreadKey;
99
100 explicit GlobalActivityAnalyzer(
Sigurður Ásgeirsson 2016/06/14 15:28:12 document member functions
bcwhite 2016/06/14 19:48:45 Done.
101 std::unique_ptr<PersistentMemoryAllocator> allocator);
102 ~GlobalActivityAnalyzer();
103
104 #if !defined(OS_NACL)
105 std::unique_ptr<GlobalActivityAnalyzer> CreateWithFile(
106 const FilePath& file_path);
107 #endif // !defined(OS_NACL)
108
109 ThreadActivityAnalyzer* GetFirstAnalyzer();
Sigurður Ásgeirsson 2016/06/14 15:28:13 document member functions - presumably this class
bcwhite 2016/06/14 19:48:45 Done.
110 ThreadActivityAnalyzer* GetNextAnalyzer();
111 ThreadActivityAnalyzer* GetAnalyzerForThread(const ThreadKey& key);
112
113 private:
114 using AnalyzerMap =
115 std::map<ThreadKey, std::unique_ptr<ThreadActivityAnalyzer>>;
116
117 std::unique_ptr<PersistentMemoryAllocator> allocator_;
118 PersistentMemoryAllocator::Iterator allocator_iterator_;
119 std::set<PersistentMemoryAllocator::Reference> tracker_references_;
120 AnalyzerMap analyzers_;
121 AnalyzerMap::iterator analyzers_iterator_;
122
123 DISALLOW_COPY_AND_ASSIGN(GlobalActivityAnalyzer);
124 };
125
126 } // namespace debug
127 } // namespace base
128
129 #endif // BASE_METRICS_ACTIVITY_ANALYZER_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/debug/activity_analyzer.cc » ('j') | base/debug/activity_analyzer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698