| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/metrics/tracking_synchronizer.h" | 5 #include "chrome/browser/metrics/tracking_synchronizer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
| 14 #include "chrome/browser/ui/webui/tracing_ui.h" | 14 #include "chrome/browser/ui/webui/tracing_ui.h" |
| 15 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
| 16 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
| 17 #include "content/common/child_process_info.h" | |
| 18 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/common/process_type.h" |
| 20 | 20 |
| 21 using base::TimeTicks; | 21 using base::TimeTicks; |
| 22 using content::BrowserThread; | 22 using content::BrowserThread; |
| 23 | 23 |
| 24 namespace chrome_browser_metrics { | 24 namespace chrome_browser_metrics { |
| 25 | 25 |
| 26 // Negative numbers are never used as sequence numbers. We explicitly pick a | 26 // Negative numbers are never used as sequence numbers. We explicitly pick a |
| 27 // negative number that is "so negative" that even when we add one (as is done | 27 // negative number that is "so negative" that even when we add one (as is done |
| 28 // when we generated the next sequence number) that it will still be negative. | 28 // when we generated the next sequence number) that it will still be negative. |
| 29 // We have code that handles wrapping around on an overflow into negative | 29 // We have code that handles wrapping around on an overflow into negative |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 TrackingSynchronizer* current_synchronizer = CurrentSynchronizer(); | 148 TrackingSynchronizer* current_synchronizer = CurrentSynchronizer(); |
| 149 if (current_synchronizer == NULL) | 149 if (current_synchronizer == NULL) |
| 150 return; | 150 return; |
| 151 | 151 |
| 152 base::Value* value = | 152 base::Value* value = |
| 153 base::JSONReader().JsonToValue(tracking_data, false, true); | 153 base::JSONReader().JsonToValue(tracking_data, false, true); |
| 154 DCHECK(value->GetType() == base::Value::TYPE_DICTIONARY); | 154 DCHECK(value->GetType() == base::Value::TYPE_DICTIONARY); |
| 155 base::DictionaryValue* dictionary_value = | 155 base::DictionaryValue* dictionary_value = |
| 156 static_cast<DictionaryValue*>(value); | 156 static_cast<DictionaryValue*>(value); |
| 157 dictionary_value->SetString( | 157 dictionary_value->SetString( |
| 158 "process_type", ChildProcessInfo::GetTypeNameInEnglish(process_type)); | 158 "process_type", content::GetProcessTypeNameInEnglish(process_type)); |
| 159 | 159 |
| 160 current_synchronizer->DecrementPendingProcessesAndSendData( | 160 current_synchronizer->DecrementPendingProcessesAndSendData( |
| 161 sequence_number, dictionary_value); | 161 sequence_number, dictionary_value); |
| 162 } | 162 } |
| 163 | 163 |
| 164 int TrackingSynchronizer::RegisterAndNotifyAllProcesses( | 164 int TrackingSynchronizer::RegisterAndNotifyAllProcesses( |
| 165 const base::WeakPtr<ProfilerUI>& callback_object) { | 165 const base::WeakPtr<ProfilerUI>& callback_object) { |
| 166 // To iterate over all processes, or to send messages to the hosts, we need | 166 // To iterate over all processes, or to send messages to the hosts, we need |
| 167 // to be on the UI thread. | 167 // to be on the UI thread. |
| 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 188 ++request->processes_pending_; | 188 ++request->processes_pending_; |
| 189 if (!render_process_host->Send( | 189 if (!render_process_host->Send( |
| 190 new ChromeViewMsg_GetRendererTrackedData(sequence_number))) { | 190 new ChromeViewMsg_GetRendererTrackedData(sequence_number))) { |
| 191 DecrementPendingProcesses(sequence_number); | 191 DecrementPendingProcesses(sequence_number); |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 // Get the ThreadData for the browser process and send it back. | 195 // Get the ThreadData for the browser process and send it back. |
| 196 base::DictionaryValue* value = tracked_objects::ThreadData::ToValue(); | 196 base::DictionaryValue* value = tracked_objects::ThreadData::ToValue(); |
| 197 const std::string process_type = | 197 const std::string process_type = |
| 198 ChildProcessInfo::GetTypeNameInEnglish(content::PROCESS_TYPE_BROWSER); | 198 content::GetProcessTypeNameInEnglish(content::PROCESS_TYPE_BROWSER); |
| 199 value->SetString("process_type", process_type); | 199 value->SetString("process_type", process_type); |
| 200 value->SetInteger("process_id", base::GetCurrentProcId()); | 200 value->SetInteger("process_id", base::GetCurrentProcId()); |
| 201 DCHECK_GT(request->processes_pending_, 0); | 201 DCHECK_GT(request->processes_pending_, 0); |
| 202 DecrementPendingProcessesAndSendData(sequence_number, value); | 202 DecrementPendingProcessesAndSendData(sequence_number, value); |
| 203 | 203 |
| 204 return sequence_number; | 204 return sequence_number; |
| 205 } | 205 } |
| 206 | 206 |
| 207 void TrackingSynchronizer::DecrementPendingProcessesAndSendData( | 207 void TrackingSynchronizer::DecrementPendingProcessesAndSendData( |
| 208 int sequence_number, | 208 int sequence_number, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // Watch out for wrapping to a negative number. | 266 // Watch out for wrapping to a negative number. |
| 267 if (last_used_sequence_number_ < 0) | 267 if (last_used_sequence_number_ < 0) |
| 268 last_used_sequence_number_ = 1; | 268 last_used_sequence_number_ = 1; |
| 269 return last_used_sequence_number_; | 269 return last_used_sequence_number_; |
| 270 } | 270 } |
| 271 | 271 |
| 272 // static | 272 // static |
| 273 TrackingSynchronizer* TrackingSynchronizer::tracking_synchronizer_ = NULL; | 273 TrackingSynchronizer* TrackingSynchronizer::tracking_synchronizer_ = NULL; |
| 274 | 274 |
| 275 } // namespace chrome_browser_metrics | 275 } // namespace chrome_browser_metrics |
| OLD | NEW |