| OLD | NEW |
| 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 #ifndef COMPONENTS_METRICS_CHILD_CALL_STACK_PROFILE_COLLECTOR_H_ | 5 #ifndef COMPONENTS_METRICS_CHILD_CALL_STACK_PROFILE_COLLECTOR_H_ |
| 6 #define COMPONENTS_METRICS_CHILD_CALL_STACK_PROFILE_COLLECTOR_H_ | 6 #define COMPONENTS_METRICS_CHILD_CALL_STACK_PROFILE_COLLECTOR_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // Sets the CallStackProfileCollector interface from |parent_collector|. This | 58 // Sets the CallStackProfileCollector interface from |parent_collector|. This |
| 59 // function MUST be invoked exactly once, regardless of whether | 59 // function MUST be invoked exactly once, regardless of whether |
| 60 // |parent_collector| is null, as it flushes pending data in either case. | 60 // |parent_collector| is null, as it flushes pending data in either case. |
| 61 void SetParentProfileCollector( | 61 void SetParentProfileCollector( |
| 62 metrics::mojom::CallStackProfileCollectorPtr parent_collector); | 62 metrics::mojom::CallStackProfileCollectorPtr parent_collector); |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 friend class ChildCallStackProfileCollectorTest; | 65 friend class ChildCallStackProfileCollectorTest; |
| 66 | 66 |
| 67 // Bundles together a set of collected profiles and the collection state for | 67 // Bundles together a set of collected profiles and the collection state for |
| 68 // storage, pending availability of the parent mojo interface. | 68 // storage, pending availability of the parent mojo interface. |profiles| |
| 69 // is not const& because it must be passed with std::move. |
| 69 struct ProfilesState { | 70 struct ProfilesState { |
| 70 ProfilesState(); | 71 ProfilesState(); |
| 71 ProfilesState(const ProfilesState&); | 72 ProfilesState(ProfilesState&&); |
| 72 ProfilesState( | 73 ProfilesState( |
| 73 const CallStackProfileParams& params, | 74 const CallStackProfileParams& params, |
| 74 base::TimeTicks start_timestamp, | 75 base::TimeTicks start_timestamp, |
| 75 const base::StackSamplingProfiler::CallStackProfiles& profiles); | 76 base::StackSamplingProfiler::CallStackProfiles profiles); |
| 76 ~ProfilesState(); | 77 ~ProfilesState(); |
| 77 | 78 |
| 79 ProfilesState& operator=(ProfilesState&&); |
| 80 |
| 78 CallStackProfileParams params; | 81 CallStackProfileParams params; |
| 79 base::TimeTicks start_timestamp; | 82 base::TimeTicks start_timestamp; |
| 80 | 83 |
| 81 // The sampled profiles. | 84 // The sampled profiles. |
| 82 base::StackSamplingProfiler::CallStackProfiles profiles; | 85 base::StackSamplingProfiler::CallStackProfiles profiles; |
| 86 |
| 87 private: |
| 88 DISALLOW_COPY_AND_ASSIGN(ProfilesState); |
| 83 }; | 89 }; |
| 84 | 90 |
| 85 using CallStackProfile = base::StackSamplingProfiler::CallStackProfile; | 91 using CallStackProfile = base::StackSamplingProfiler::CallStackProfile; |
| 86 | 92 |
| 87 void Collect(const CallStackProfileParams& params, | 93 void Collect(const CallStackProfileParams& params, |
| 88 base::TimeTicks start_timestamp, | 94 base::TimeTicks start_timestamp, |
| 89 const std::vector<CallStackProfile>& profiles); | 95 std::vector<CallStackProfile> profiles); |
| 90 | 96 |
| 91 // This object may be accessed on any thread, including the profiler | 97 // This object may be accessed on any thread, including the profiler |
| 92 // thread. The expected use case for the object is to be created and have | 98 // thread. The expected use case for the object is to be created and have |
| 93 // GetProfilerCallback before the message loop starts, which prevents the use | 99 // GetProfilerCallback before the message loop starts, which prevents the use |
| 94 // of PostTask and the like for inter-thread communication. | 100 // of PostTask and the like for inter-thread communication. |
| 95 base::Lock lock_; | 101 base::Lock lock_; |
| 96 | 102 |
| 97 // Whether to retain profiles when the interface is not set. Remains true | 103 // Whether to retain profiles when the interface is not set. Remains true |
| 98 // until the invocation of SetParentProfileCollector(), at which point it is | 104 // until the invocation of SetParentProfileCollector(), at which point it is |
| 99 // false for the rest of the object lifetime. | 105 // false for the rest of the object lifetime. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 111 // Profiles being cached by this object, pending a parent interface to be | 117 // Profiles being cached by this object, pending a parent interface to be |
| 112 // supplied. | 118 // supplied. |
| 113 std::vector<ProfilesState> profiles_; | 119 std::vector<ProfilesState> profiles_; |
| 114 | 120 |
| 115 DISALLOW_COPY_AND_ASSIGN(ChildCallStackProfileCollector); | 121 DISALLOW_COPY_AND_ASSIGN(ChildCallStackProfileCollector); |
| 116 }; | 122 }; |
| 117 | 123 |
| 118 } // namespace metrics | 124 } // namespace metrics |
| 119 | 125 |
| 120 #endif // COMPONENTS_METRICS_CHILD_CALL_STACK_PROFILE_COLLECTOR_H_ | 126 #endif // COMPONENTS_METRICS_CHILD_CALL_STACK_PROFILE_COLLECTOR_H_ |
| OLD | NEW |