| OLD | NEW |
| 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 #ifndef COMPONENTS_METRICS_PROFILER_TRACKING_SYNCHRONIZER_OBSERVER_H_ | 5 #ifndef COMPONENTS_METRICS_PROFILER_TRACKING_SYNCHRONIZER_OBSERVER_H_ |
| 6 #define COMPONENTS_METRICS_PROFILER_TRACKING_SYNCHRONIZER_OBSERVER_H_ | 6 #define COMPONENTS_METRICS_PROFILER_TRACKING_SYNCHRONIZER_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| 11 #include "base/time/time.h" |
| 11 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" | 12 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" |
| 12 #include "content/public/common/process_type.h" | 13 #include "content/public/common/process_type.h" |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 class TimeDelta; | 16 class TimeDelta; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace tracked_objects { | 19 namespace tracked_objects { |
| 19 struct ProcessDataPhaseSnapshot; | 20 struct ProcessDataPhaseSnapshot; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace metrics { | 23 namespace metrics { |
| 23 | 24 |
| 24 // Set of profiling events, in no guaranteed order. Implemented as a vector | 25 // Set of profiling events, in no guaranteed order. Implemented as a vector |
| 25 // because we don't need to have an efficient .find() on it, so vector<> is more | 26 // because we don't need to have an efficient .find() on it, so vector<> is more |
| 26 // efficient. | 27 // efficient. |
| 27 typedef std::vector<ProfilerEventProto::ProfilerEvent> ProfilerEvents; | 28 typedef std::vector<ProfilerEventProto::ProfilerEvent> ProfilerEvents; |
| 28 | 29 |
| 30 // Attributes of profiler data passed to |
| 31 // TrackingSynchronizerObserver::ReceivedProfilerData. |
| 32 struct ProfilerDataAttributes { |
| 33 ProfilerDataAttributes(int profiling_phase, |
| 34 base::ProcessId process_id, |
| 35 content::ProcessType process_type, |
| 36 base::TimeTicks phase_start, |
| 37 base::TimeTicks phase_finish); |
| 38 |
| 39 // 0-indexed profiling phase number. |
| 40 const int profiling_phase; |
| 41 |
| 42 // ID of the process that reported the data. |
| 43 const base::ProcessId process_id; |
| 44 |
| 45 // Type of the process that reported the data. |
| 46 const content::ProcessType process_type; |
| 47 |
| 48 // Time of the profiling phase start. |
| 49 const base::TimeTicks phase_start; |
| 50 |
| 51 // Time of the profiling phase finish. |
| 52 const base::TimeTicks phase_finish; |
| 53 }; |
| 54 |
| 29 // Observer for notifications from the TrackingSynchronizer class. | 55 // Observer for notifications from the TrackingSynchronizer class. |
| 30 class TrackingSynchronizerObserver { | 56 class TrackingSynchronizerObserver { |
| 31 public: | 57 public: |
| 32 // TODO(vadimt): Consider isherman@ idea: I'd change the phase_start and | 58 // Received |process_data_phase| for profiling phase and process defined by |
| 33 // phase_finish from TimeDeltas to TimeTicks. And I'd omit the |past_events| | 59 // |attributes|. |
| 34 // list -- either in favor of a single ProfilerEvent that corresponds to the | 60 // Each completed phase is associated with an event that triggered the |
| 35 // phase, or a method on the TrackingSynchronizer that can translate a | 61 // completion of the phase. |past_events| contains the set of events that |
| 36 // profiling_phase to a ProfilerEvent. | 62 // completed prior to the reported phase. This data structure is useful for |
| 37 | 63 // quickly computing the full set of profiled traces that occurred before or |
| 38 // Received |process_data_phase| for profiling phase |profiling_phase| from a | 64 // after a given event. |
| 39 // single process of |process_type|. The phase start and finish times, | |
| 40 // relative to the start time are |phase_start| and | |
| 41 // |phase_finish|. All profiling phases prior to the reported one have already | |
| 42 // completed, and each completion was associated with an instance of | |
| 43 // ProfilerEventProto::ProfilerEvent. |past_events| contains events associated | |
| 44 // with completions of phases prior to the reported one. | |
| 45 // The observer should assume there might be more data coming until | 65 // The observer should assume there might be more data coming until |
| 46 // FinishedReceivingData() is called. | 66 // FinishedReceivingData() is called. |
| 47 virtual void ReceivedProfilerData( | 67 virtual void ReceivedProfilerData( |
| 68 const ProfilerDataAttributes& attributes, |
| 48 const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase, | 69 const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase, |
| 49 base::ProcessId process_id, | |
| 50 content::ProcessType process_type, | |
| 51 int profiling_phase, | |
| 52 base::TimeDelta phase_start, | |
| 53 base::TimeDelta phase_finish, | |
| 54 const ProfilerEvents& past_events) = 0; | 70 const ProfilerEvents& past_events) = 0; |
| 55 | 71 |
| 56 // The observer should not expect any more calls to |ReceivedProfilerData()| | 72 // The observer should not expect any more calls to |ReceivedProfilerData()| |
| 57 // (without re-registering). This is sent either when data from all processes | 73 // (without re-registering). This is sent either when data from all processes |
| 58 // has been gathered, or when the request times out. | 74 // has been gathered, or when the request times out. |
| 59 virtual void FinishedReceivingProfilerData() {} | 75 virtual void FinishedReceivingProfilerData() {} |
| 60 | 76 |
| 61 protected: | 77 protected: |
| 62 TrackingSynchronizerObserver() {} | 78 TrackingSynchronizerObserver() {} |
| 63 virtual ~TrackingSynchronizerObserver() {} | 79 virtual ~TrackingSynchronizerObserver() {} |
| 64 | 80 |
| 65 private: | 81 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(TrackingSynchronizerObserver); | 82 DISALLOW_COPY_AND_ASSIGN(TrackingSynchronizerObserver); |
| 67 }; | 83 }; |
| 68 | 84 |
| 69 } // namespace metrics | 85 } // namespace metrics |
| 70 | 86 |
| 71 #endif // COMPONENTS_METRICS_PROFILER_TRACKING_SYNCHRONIZER_OBSERVER_H_ | 87 #endif // COMPONENTS_METRICS_PROFILER_TRACKING_SYNCHRONIZER_OBSERVER_H_ |
| OLD | NEW |