| Index: chrome/browser/metrics/tracking_synchronizer.h
|
| ===================================================================
|
| --- chrome/browser/metrics/tracking_synchronizer.h (revision 110669)
|
| +++ chrome/browser/metrics/tracking_synchronizer.h (working copy)
|
| @@ -13,16 +13,18 @@
|
| #include "base/basictypes.h"
|
| #include "base/memory/ref_counted.h"
|
| #include "base/memory/weak_ptr.h"
|
| +#include "base/message_loop.h"
|
| +#include "base/process.h"
|
| #include "base/time.h"
|
| #include "base/values.h"
|
| #include "chrome/browser/ui/webui/profiler_ui.h"
|
| -#include "content/common/child_process_info.h"
|
| +#include "content/browser/profiler_controller.h"
|
| #include "content/public/browser/browser_thread.h"
|
|
|
| -// This class maintains state that is used to upload tracking data from the
|
| +// This class maintains state that is used to upload profiler data from the
|
| // various processes, into the browser process. Such transactions are usually
|
| // instigated by the browser. In general, a process will respond by gathering
|
| -// tracking data, and transmitting the pickled tracking data. We collect the
|
| +// profiler data, and transmitting the pickled profiler data. We collect the
|
| // data in asynchronous mode that doesn't block the UI thread.
|
| //
|
| // To assure that all the processes have responded, a counter is maintained
|
| @@ -31,24 +33,29 @@
|
| // create RequestContext object which stores the sequence number, pending
|
| // processes and the callback_object that needs to be notified when we receive
|
| // an update from processes. When an update arrives we find the RequestContext
|
| -// associated with sequence number and send the unpickled tracking data to the
|
| +// associated with sequence number and send the unpickled profiler data to the
|
| // |callback_object_|.
|
|
|
| namespace chrome_browser_metrics {
|
|
|
| -class TrackingSynchronizer : public
|
| - base::RefCountedThreadSafe<TrackingSynchronizer> {
|
| +class TrackingSynchronizer
|
| + : public ProfilerSubscriber,
|
| + public base::RefCountedThreadSafe<TrackingSynchronizer> {
|
| public:
|
| // The "RequestContext" structure describes an individual request received
|
| // from the UI.
|
| struct RequestContext {
|
| RequestContext(const base::WeakPtr<ProfilerUI>& callback_object,
|
| int sequence_number,
|
| - int processes_pending,
|
| + int ui_processes_pending,
|
| + int io_processes_pending,
|
| + int threads_pending,
|
| base::TimeTicks callback_start_time)
|
| : callback_object_(callback_object),
|
| sequence_number_(sequence_number),
|
| - processes_pending_(processes_pending),
|
| + ui_processes_pending_(ui_processes_pending),
|
| + io_processes_pending_(io_processes_pending),
|
| + threads_pending_(threads_pending),
|
| request_start_time_(callback_start_time) {
|
| }
|
|
|
| @@ -61,9 +68,21 @@
|
| // processes.
|
| int sequence_number_;
|
|
|
| - // The number of processes that have not yet responded to requests.
|
| - int processes_pending_;
|
| + // The number of renderer processes that have not yet responded to requests.
|
| + // This is updated on UI thread.
|
| + int ui_processes_pending_;
|
|
|
| + // The number of browser child processes that have not yet responded to
|
| + // requests. This is updated on IO thread.
|
| + int io_processes_pending_;
|
| +
|
| + // The number of threads (UI and IO) we are waiting for. This is initialized
|
| + // to 2. This is decremented by 1 whenever either ui_processes_pending_ or
|
| + // io_processes_pending_ become zero (in other words, this will be zero when
|
| + // ui_processes_pending_ and io_processes_pending_ are zero).
|
| + // This is updated on UI thread.
|
| + int threads_pending_;
|
| +
|
| // The time when we were told to start the fetching of data from processes.
|
| base::TimeTicks request_start_time_;
|
| };
|
| @@ -71,91 +90,169 @@
|
| // A map from sequence_number_ to the actual RequestContexts.
|
| typedef std::map<int, RequestContext*> RequestContextMap;
|
|
|
| + // The DecrementProcessesCallback receives one argument:
|
| + // RequestContext request - the request in which we need to decrement the
|
| + // pending processes count (either ui_processes_pending_ or
|
| + // io_processes_pending_).
|
| + typedef base::Callback<void(RequestContext*)> DecrementProcessesCallback;
|
| +
|
| // Construction also sets up the global singleton instance. This instance is
|
| // used to communicate between the IO and UI thread, and is destroyed only as
|
| // the main thread (browser_main) terminates, which means the IO thread has
|
| // already completed, and will not need this instance any further.
|
| TrackingSynchronizer();
|
|
|
| - // Return pointer to the singleton instance, which is allocated and
|
| - // deallocated on the main UI thread (during system startup and teardown).
|
| - static TrackingSynchronizer* CurrentSynchronizer();
|
| -
|
| // Contact all processes, and get them to upload to the browser any/all
|
| - // changes to tracking data. It calls |callback_object|'s SetData method with
|
| + // changes to profiler data. It calls |callback_object|'s SetData method with
|
| // the data received from each sub-process.
|
| // This method is accessible on UI thread.
|
| - static void FetchTrackingDataAsynchronously(
|
| + static void FetchProfilerDataAsynchronously(
|
| const base::WeakPtr<ProfilerUI>& callback_object);
|
|
|
| - // Contact all processes and set tracking status to |enable|.
|
| + // Contact all processes and set profiler status to |enable|.
|
| // This method is accessible on UI thread.
|
| - static void SetTrackingStatus(bool enable);
|
| + static void SetProfilerStatus(bool enable);
|
|
|
| - // Respond to this message from the renderer by setting the tracking status
|
| - // (SetTrackingStatusInProcess) in that renderer process.
|
| - // |process_id| is used to find the renderer process.
|
| + // Respond to this message from the renderer by setting the profiler status
|
| + // (SendRendererSetProfilerStatusOnUI) in that renderer process.
|
| + // |renderer_process_id| is used to find the renderer process.
|
| // This method is accessible on IO thread.
|
| - static void IsTrackingEnabled(int process_id);
|
| + static void IsProfilerEnabledForRenderer(int renderer_process_id);
|
|
|
| - // Get the current tracking status from the browser process and set it in the
|
| - // renderer process. |process_id| is used to find the renderer process.
|
| - // This method is accessible on UI thread.
|
| - static void SetTrackingStatusInProcess(int process_id);
|
| -
|
| - // Deserialize the tracking data and record that we have received tracking
|
| - // data from a process. This method posts a task to call
|
| - // DeserializeTrackingListOnUI on UI thread to send the |tracking_data| to
|
| - // callback_object_. This method is accessible on IO thread.
|
| - static void DeserializeTrackingList(
|
| + // Deserialize the profiler data and record that we have received profiler
|
| + // data from a renderer process. This method posts a task to call
|
| + // OnRendererProfilerDatatCollectedOnUI on UI thread to send the
|
| + // |profiler_data| to callback_object_.
|
| + // This method is accessible on IO thread.
|
| + static void OnRendererProfilerDatatCollected(
|
| int sequence_number,
|
| - const std::string& tracking_data,
|
| - ChildProcessInfo::ProcessType process_type);
|
| + const std::string& profiler_data);
|
|
|
| - // Deserialize the tracking data and record that we have received tracking
|
| - // data from a process. This method is accessible on UI thread.
|
| - static void DeserializeTrackingListOnUI(
|
| + // ------------------------------------------------------
|
| + // ProfilerSubscriber methods for browser child processes
|
| + // ------------------------------------------------------
|
| +
|
| + // Deserialize the profiler data and record that we have received profiler
|
| + // data from a browser child process. This method is accessible on IO thread.
|
| + virtual void OnBrowserChildProfilerDataCollected(
|
| int sequence_number,
|
| - const std::string& tracking_data,
|
| - ChildProcessInfo::ProcessType process_type);
|
| + const std::string& profiler_data) OVERRIDE;
|
|
|
| + // Respond to this message from the browser child process by setting the
|
| + // profiler status in that browser child process. |child_process_id| is used
|
| + // to find the child process. This method is accessible on IO thread.
|
| + virtual void OnIsProfilerEnabledForChildProcess(
|
| + base::ProcessId child_process_id) OVERRIDE;
|
| +
|
| private:
|
| friend class base::RefCountedThreadSafe<TrackingSynchronizer>;
|
|
|
| virtual ~TrackingSynchronizer();
|
|
|
| + // Return pointer to the singleton instance, which is allocated and
|
| + // deallocated on the main UI thread (during system startup and teardown).
|
| + static TrackingSynchronizer* CurrentSynchronizer();
|
| +
|
| // Establish a new sequence_number_, and use it to notify all the processes of
|
| - // the need to supply, to the browser, their tracking data. It also registers
|
| + // the need to supply, to the browser, their profiler data. It also registers
|
| // |callback_object| in |outstanding_requests_| map. Return the
|
| // sequence_number_ that was used. This method is accessible on UI thread.
|
| int RegisterAndNotifyAllProcesses(
|
| const base::WeakPtr<ProfilerUI>& callback_object);
|
|
|
| - // It finds the |callback_object_| in |outstanding_requests_| map for the
|
| - // given |sequence_number| and notifies the |callback_object_| about the
|
| - // |value|. This is called whenever we receive tracked data from processes. It
|
| - // also records that we are waiting for one less tracking data from a process
|
| - // for the given sequence number. If we have received a response from all
|
| - // renderers, then it deletes the entry for sequence_number from
|
| - // |outstanding_requests_| map. This method is accessible on UI thread.
|
| - void DecrementPendingProcessesAndSendData(int sequence_number,
|
| - base::DictionaryValue* value);
|
| + // Notify all renderer processes that they need to supply, to the browser,
|
| + // their profiler data. This method is accessible on UI thread.
|
| + void NotifyAllRendererProcesses(RequestContext* request);
|
|
|
| - // Records that we are waiting for one less tracking data from a process for
|
| - // the given sequence number.
|
| + // Notify all browser child processes that they need to supply, to the
|
| + // browser, their profiler data. This method is accessible on IO thread.
|
| + void NotifyAllChildProcesses(RequestContext* request);
|
| +
|
| + // Deserialize the profiler data and record that we have received profiler
|
| + // data from a renderer process. This method is accessible on UI thread.
|
| + static void OnRendererProfilerDatatCollectedOnUI(
|
| + int sequence_number,
|
| + const std::string& profiler_data);
|
| +
|
| + // It builds a DecrementProcessesCallback for DecrementUIProcesses to record
|
| + // that we are waiting for one less profiler data from a process for the given
|
| + // sequence number and it calls DecrementPendingProcessesAndSendData to send
|
| + // the data to requester. This method is accessible on UI thread.
|
| + void DecrementPendingProcessesAndSendDataOnUI(int sequence_number,
|
| + base::DictionaryValue* value);
|
| +
|
| + // It builds a DecrementProcessesCallback for DecrementIOProcesses to record
|
| + // that we are waiting for one less profiler data from a process for the given
|
| + // sequence number and it calls DecrementPendingProcessesAndSendData to send
|
| + // the data to requester. This method is accessible on IO thread.
|
| + void DecrementPendingProcessesAndSendDataOnIO(int sequence_number,
|
| + base::DictionaryValue* value);
|
| +
|
| + // It finds the Request in |outstanding_requests_| map for the given
|
| + // |sequence_number| and notifies the Request's |callback_object_| about the
|
| + // |value|. It posts a task (RunDecrementProcessesCallback) on
|
| + // |callback_thread| to call |decrement_pending_process_cb| (which records
|
| + // that we are waiting for one less profiler data from a process for the
|
| + // given sequence number). This method is accessible on UI thread.
|
| + void DecrementPendingProcessesAndSendData(
|
| + int sequence_number,
|
| + base::DictionaryValue* value,
|
| + MessageLoop* callback_thread,
|
| + const DecrementProcessesCallback& decrement_pending_process_cb);
|
| +
|
| + // Records that we are waiting for one less profiler data from a process for
|
| + // the given sequence number. If we have received a response from all
|
| + // renderers, then it calls DeleteIfAllDone which will delete the entry for
|
| + // sequence_number from |outstanding_requests_| map if |request|'s
|
| + // |threads_pending_| is zero.
|
| + // This method is accessible on UI thread (for renderer process).
|
| + void DecrementUIProcesses(RequestContext* request);
|
| +
|
| + // Records that we are waiting for one less profiler data from a process for
|
| + // the given sequence number. If we have received a response from all child
|
| + // processes, then it posts a task on UI thread to call DeleteIfAllDone which
|
| + // will delete the entry for sequence_number from |outstanding_requests_| map
|
| + // if |request|'s |threads_pending_| is zero.
|
| + // This method is accessible on IO thread (for browser child process).
|
| + void DecrementIOProcesses(RequestContext* request);
|
| +
|
| + // Deletes the entry for sequence_number from |outstanding_requests_| map (by
|
| + // calling ForceProfilerSynchronizationDoneCallback) if we have heard from all
|
| + // child and renderer processes.
|
| // This method is accessible on UI thread.
|
| - void DecrementPendingProcesses(int sequence_number);
|
| + void DeleteIfAllDone(RequestContext* request);
|
|
|
| // When all changes have been acquired, or when the wait time expires
|
| // (whichever is sooner), this method is called. This method deletes the entry
|
| // for the given sequence_number from |outstanding_requests_| map.
|
| // This method is accessible on UI thread.
|
| - void ForceTrackingSynchronizationDoneCallback(int sequence_number);
|
| + void ForceProfilerSynchronizationDoneCallback(int sequence_number);
|
|
|
| // Get a new sequence number to be sent to processes from browser process.
|
| // This method is accessible on UI thread.
|
| int GetNextAvailableSequenceNumber();
|
|
|
| + // Runs the |decrement_pending_process_cb| callback.
|
| + // |decrement_pending_process_cb| is either |DecrementUIProcesses| or
|
| + // |DecrementIOProcesses| which decrements |request|'s pending process count.
|
| + void RunDecrementProcessesCallback(
|
| + const DecrementProcessesCallback& decrement_pending_process_cb,
|
| + RequestContext* request);
|
| +
|
| + // Contact all browser child processes and set profiler status to |enable|.
|
| + // This method is accessible on IO thread.
|
| + static void SetProfilerStatusInChildProcesses(bool enable);
|
| +
|
| + // Get the current profiler status from the browser process and set it in the
|
| + // renderer process. |renderer_process_id| is used to find the renderer
|
| + // process. This method is accessible on UI thread.
|
| + static void SendRendererSetProfilerStatusOnUI(int renderer_process_id);
|
| +
|
| + // Get the current profiler status from the browser process and set it in the
|
| + // browser child process. |child_process_id| is used to find the browser child
|
| + // process. This method is accessible on IO thread.
|
| + static void SendChildSetProfilerStatusOnIO(base::ProcessId child_process_id);
|
| +
|
| // Map of all outstanding RequestContexts, from sequence_number_ to
|
| // RequestContext.
|
| RequestContextMap outstanding_requests_;
|
| @@ -173,7 +270,7 @@
|
| // portion of main(). It initializes globals to provide support for all future
|
| // calls. This object is created on the UI thread, and it is destroyed after
|
| // all the other threads have gone away. As a result, it is ok to call it
|
| - // from the UI thread, or for about:tracking.
|
| + // from the UI thread, or for about:profiler.
|
| static TrackingSynchronizer* tracking_synchronizer_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(TrackingSynchronizer);
|
|
|