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

Side by Side Diff: content/browser/media/media_internals.cc

Issue 697463005: Add PipelineStatus UMA logging to media_internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change "pipeline_error" media_log event to enum Created 6 years, 1 month 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
« no previous file with comments | « content/browser/media/media_internals.h ('k') | media/base/media_log.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "content/browser/media/media_internals.h" 5 #include "content/browser/media/media_internals.h"
6 6
7 #include "base/metrics/histogram.h"
7 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
8 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/notification_types.h"
16 #include "content/public/browser/render_process_host.h"
11 #include "content/public/browser/web_ui.h" 17 #include "content/public/browser/web_ui.h"
12 #include "media/audio/audio_parameters.h" 18 #include "media/audio/audio_parameters.h"
13 #include "media/base/media_log.h"
14 #include "media/base/media_log_event.h" 19 #include "media/base/media_log_event.h"
15 20
16 namespace { 21 namespace {
17 22
18 static base::LazyInstance<content::MediaInternals>::Leaky g_media_internals = 23 static base::LazyInstance<content::MediaInternals>::Leaky g_media_internals =
19 LAZY_INSTANCE_INITIALIZER; 24 LAZY_INSTANCE_INITIALIZER;
20 25
21 base::string16 SerializeUpdate(const std::string& function, 26 base::string16 SerializeUpdate(const std::string& function,
22 const base::Value* value) { 27 const base::Value* value) {
23 return content::WebUI::GetJavascriptCall( 28 return content::WebUI::GetJavascriptCall(
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict); 168 FormatCacheKey(component_id), kAudioLogUpdateFunction, &dict);
164 } 169 }
165 170
166 void AudioLogImpl::StoreComponentMetadata(int component_id, 171 void AudioLogImpl::StoreComponentMetadata(int component_id,
167 base::DictionaryValue* dict) { 172 base::DictionaryValue* dict) {
168 dict->SetInteger("owner_id", owner_id_); 173 dict->SetInteger("owner_id", owner_id_);
169 dict->SetInteger("component_id", component_id); 174 dict->SetInteger("component_id", component_id);
170 dict->SetInteger("component_type", component_); 175 dict->SetInteger("component_type", component_);
171 } 176 }
172 177
178 class MediaInternals::MediaInternalsUMAHandler : public NotificationObserver {
179 public:
180 MediaInternalsUMAHandler();
181 // NotificationObserver implementation.
DaleCurtis 2014/11/12 21:41:09 Add a blank line above this.
prabhur1 2014/11/12 22:21:31 Done.
182 void Observe(int type,
183 const NotificationSource& source,
184 const NotificationDetails& details) override;
185 void LogAndClearPlayersInRenderer(int render_process_id);
DaleCurtis 2014/11/12 21:41:09 Can you add some docs for these last two methods?
prabhur1 2014/11/12 22:21:31 Did you mean adding a new line separator ?
prabhur1 2014/11/12 22:21:32 Done.
186
187 void SavePlayerState(const media::MediaLogEvent& event,
188 int render_process_id);
189
190 private:
191 NotificationRegistrar registrar_;
192
193 struct PipelineInfo {
194 media::PipelineStatus last_pipeline_status;
195 bool has_audio;
196 bool has_video;
197 std::string audio_codec_name;
198 std::string video_codec_name;
199 std::string video_decoder;
200 PipelineInfo()
201 : last_pipeline_status(media::PIPELINE_OK),
202 has_audio(false),
203 has_video(false) {}
204 };
205
206 // Key is playerid
207 typedef std::map<int, PipelineInfo> PlayerInfoMap;
208
209 // Key is renderer id
210 typedef std::map<int, PlayerInfoMap> RendererPlayerMap;
211
212 // Stores player information per renderer
213 RendererPlayerMap renderer_info_;
214
215 void ReportUMAForPipelineStatus(const PipelineInfo& player_info);
DaleCurtis 2014/11/12 21:41:08 Methods go above variable declarations. Add some c
prabhur1 2014/11/12 22:21:31 Moved after the struct because of dependency on Pi
prabhur1 2014/11/12 22:21:31 Done.
216
217 DISALLOW_COPY_AND_ASSIGN(MediaInternalsUMAHandler);
218 };
219
220 MediaInternals::MediaInternalsUMAHandler::MediaInternalsUMAHandler() {
221 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED,
222 NotificationService::AllBrowserContextsAndSources());
223 }
224
225 void MediaInternals::MediaInternalsUMAHandler::Observe(
226 int type,
227 const NotificationSource& source,
228 const NotificationDetails& details) {
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
230 DCHECK_EQ(type, NOTIFICATION_RENDERER_PROCESS_TERMINATED);
231 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr();
232 LogAndClearPlayersInRenderer(process->GetID());
233 }
234
235 void MediaInternals::MediaInternalsUMAHandler::SavePlayerState(
236 const media::MediaLogEvent& event,
237 int render_process_id) {
238 PlayerInfoMap& player_info = renderer_info_[render_process_id];
239 switch (event.type) {
240 case media::MediaLogEvent::WEBMEDIAPLAYER_CREATED: {
241 // Nothing to do here
242 break;
243 }
244 case media::MediaLogEvent::PIPELINE_ERROR: {
245 int status;
246 event.params.GetInteger("pipeline_error", &status);
247 player_info[event.id].last_pipeline_status =
248 static_cast<media::PipelineStatus>(status);
249 break;
250 }
251 case media::MediaLogEvent::PROPERTY_CHANGE:
252 if (event.params.HasKey("found_audio_stream")) {
253 event.params.GetBoolean("found_audio_stream",
254 &player_info[event.id].has_audio);
255 }
256 if (event.params.HasKey("found_video_stream")) {
257 event.params.GetBoolean("found_video_stream",
258 &player_info[event.id].has_video);
259 }
260 if (event.params.HasKey("audio_codec_name")) {
261 event.params.GetString("audio_codec_name",
262 &player_info[event.id].audio_codec_name);
263 }
264 if (event.params.HasKey("video_codec_name")) {
265 event.params.GetString("video_codec_name",
266 &player_info[event.id].video_codec_name);
267 }
268 if (event.params.HasKey("video_decoder")) {
269 event.params.GetString("video_decoder",
270 &player_info[event.id].video_decoder);
271 }
272 break;
273 default:
274 break;
275 }
276 return;
277 }
278
279 void MediaInternals::MediaInternalsUMAHandler::ReportUMAForPipelineStatus(
280 const PipelineInfo& player_info) {
281 if (player_info.has_video && player_info.has_audio) {
282 if (player_info.video_codec_name == "vp8") {
283 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo.VP8",
284 player_info.last_pipeline_status,
285 media::PIPELINE_STATUS_MAX + 1);
286 } else if (player_info.video_codec_name == "vp9") {
287 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo.VP9",
288 player_info.last_pipeline_status,
289 media::PIPELINE_STATUS_MAX + 1);
290 } else if (player_info.video_codec_name == "h264") {
291 if (player_info.video_decoder == "gpu") {
292 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo.HW.H264",
293 player_info.last_pipeline_status,
294 media::PIPELINE_STATUS_MAX + 1);
295 } else {
296 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo.SW.H264",
297 player_info.last_pipeline_status,
298 media::PIPELINE_STATUS_MAX + 1);
299 }
300 } else {
301 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.AudioVideo",
302 player_info.last_pipeline_status,
303 media::PIPELINE_STATUS_MAX + 1);
304 }
305 } else if (player_info.has_audio) {
306 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.Audio",
307 player_info.last_pipeline_status,
308 media::PIPELINE_STATUS_MAX + 1);
309 } else if (player_info.has_video) {
310 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.Video",
311 player_info.last_pipeline_status,
312 media::PIPELINE_STATUS_MAX + 1);
313 } else {
314 UMA_HISTOGRAM_ENUMERATION("Media.PipelineStatus.Unsupported",
315 player_info.last_pipeline_status,
316 media::PIPELINE_STATUS_MAX + 1);
317 }
318 }
319
320 void MediaInternals::MediaInternalsUMAHandler::LogAndClearPlayersInRenderer(
321 int render_process_id) {
322 auto players_it = renderer_info_.find(render_process_id);
323 if (players_it == renderer_info_.end())
324 return;
325 auto it = players_it->second.begin();
326 while (it != players_it->second.end()) {
327 ReportUMAForPipelineStatus(it->second);
328 players_it->second.erase(it++);
329 }
330 }
331
173 MediaInternals* MediaInternals::GetInstance() { 332 MediaInternals* MediaInternals::GetInstance() {
174 return g_media_internals.Pointer(); 333 return g_media_internals.Pointer();
175 } 334 }
176 335
177 MediaInternals::MediaInternals() : owner_ids_() {} 336 MediaInternals::MediaInternals()
337 : owner_ids_(), uma_handler_(new MediaInternalsUMAHandler()) {
338 }
339
178 MediaInternals::~MediaInternals() {} 340 MediaInternals::~MediaInternals() {}
179 341
180 void MediaInternals::OnMediaEvents( 342 void MediaInternals::OnMediaEvents(
181 int render_process_id, const std::vector<media::MediaLogEvent>& events) { 343 int render_process_id, const std::vector<media::MediaLogEvent>& events) {
182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
183 // Notify observers that |event| has occurred. 345 // Notify observers that |event| has occurred.
184 for (std::vector<media::MediaLogEvent>::const_iterator event = events.begin(); 346 for (auto event = events.begin(); event != events.end(); ++event) {
185 event != events.end(); ++event) {
186 base::DictionaryValue dict; 347 base::DictionaryValue dict;
187 dict.SetInteger("renderer", render_process_id); 348 dict.SetInteger("renderer", render_process_id);
188 dict.SetInteger("player", event->id); 349 dict.SetInteger("player", event->id);
189 dict.SetString("type", media::MediaLog::EventTypeToString(event->type)); 350 dict.SetString("type", media::MediaLog::EventTypeToString(event->type));
190 351
191 // TODO(dalecurtis): This is technically not correct. TimeTicks "can't" be 352 // TODO(dalecurtis): This is technically not correct. TimeTicks "can't" be
192 // converted to to a human readable time format. See base/time/time.h. 353 // converted to to a human readable time format. See base/time/time.h.
193 const double ticks = event->time.ToInternalValue(); 354 const double ticks = event->time.ToInternalValue();
194 const double ticks_millis = ticks / base::Time::kMicrosecondsPerMillisecond; 355 const double ticks_millis = ticks / base::Time::kMicrosecondsPerMillisecond;
195 dict.SetDouble("ticksMillis", ticks_millis); 356 dict.SetDouble("ticksMillis", ticks_millis);
196 dict.Set("params", event->params.DeepCopy()); 357
358 // Convert PipelineStatus to human readable string
359 if (event->type == media::MediaLogEvent::PIPELINE_ERROR) {
360 int status;
361 event->params.GetInteger("pipeline_error", &status);
362 media::PipelineStatus error = static_cast<media::PipelineStatus>(status);
363 base::DictionaryValue error_status;
DaleCurtis 2014/11/12 21:41:08 Why do this instead of doing event->params.SetStri
prabhur1 2014/11/12 22:21:31 event is a const_iterator and doesn't allow call t
364 error_status.SetString("pipeline_error",
365 media::MediaLog::PipelineStatusToString(error));
366 dict.Set("params", error_status.DeepCopy());
367 } else
DaleCurtis 2014/11/12 21:41:09 Need {} for else
prabhur1 2014/11/12 22:21:31 Done.
368 dict.Set("params", event->params.DeepCopy());
369
197 SendUpdate(SerializeUpdate("media.onMediaEvent", &dict)); 370 SendUpdate(SerializeUpdate("media.onMediaEvent", &dict));
371 uma_handler_->SavePlayerState(*event, render_process_id);
198 } 372 }
199 } 373 }
200 374
201 void MediaInternals::AddUpdateCallback(const UpdateCallback& callback) { 375 void MediaInternals::AddUpdateCallback(const UpdateCallback& callback) {
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
203 update_callbacks_.push_back(callback); 377 update_callbacks_.push_back(callback);
204 } 378 }
205 379
206 void MediaInternals::RemoveUpdateCallback(const UpdateCallback& callback) { 380 void MediaInternals::RemoveUpdateCallback(const UpdateCallback& callback) {
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 const std::string& function, 474 const std::string& function,
301 const base::DictionaryValue* value) { 475 const base::DictionaryValue* value) {
302 SendUpdate(SerializeUpdate(function, value)); 476 SendUpdate(SerializeUpdate(function, value));
303 477
304 base::AutoLock auto_lock(lock_); 478 base::AutoLock auto_lock(lock_);
305 scoped_ptr<base::Value> out_value; 479 scoped_ptr<base::Value> out_value;
306 CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value)); 480 CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value));
307 } 481 }
308 482
309 } // namespace content 483 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/media_internals.h ('k') | media/base/media_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698