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

Side by Side Diff: talk/app/webrtc/statscollector.cc

Issue 1204493002: Set / verify stats report timestamps. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 6 months 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 | « talk/app/webrtc/statscollector.h ('k') | talk/app/webrtc/statscollector_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 const std::string& proxy) { 73 const std::string& proxy) {
74 DCHECK(!proxy.empty()); 74 DCHECK(!proxy.empty());
75 cricket::ProxyTransportMap::const_iterator found = map.find(proxy); 75 cricket::ProxyTransportMap::const_iterator found = map.find(proxy);
76 if (found == map.end()) 76 if (found == map.end())
77 return StatsReport::Id(); 77 return StatsReport::Id();
78 78
79 return StatsReport::NewComponentId( 79 return StatsReport::NewComponentId(
80 found->second, cricket::ICE_CANDIDATE_COMPONENT_RTP); 80 found->second, cricket::ICE_CANDIDATE_COMPONENT_RTP);
81 } 81 }
82 82
83 void AddTrackReport(StatsCollection* reports, const std::string& track_id) { 83 StatsReport* AddTrackReport(StatsCollection* reports,
84 const std::string& track_id) {
84 // Adds an empty track report. 85 // Adds an empty track report.
85 StatsReport::Id id( 86 StatsReport::Id id(
86 StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack, track_id)); 87 StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack, track_id));
87 StatsReport* report = reports->ReplaceOrAddNew(id); 88 StatsReport* report = reports->ReplaceOrAddNew(id);
88 report->AddString(StatsReport::kStatsValueNameTrackId, track_id); 89 report->AddString(StatsReport::kStatsValueNameTrackId, track_id);
90 return report;
89 } 91 }
90 92
91 template <class TrackVector> 93 template <class TrackVector>
92 void CreateTrackReports(const TrackVector& tracks, StatsCollection* reports) { 94 void CreateTrackReports(const TrackVector& tracks, StatsCollection* reports,
93 for (const auto& track : tracks) 95 TrackIdMap& track_ids) {
94 AddTrackReport(reports, track->id()); 96 for (const auto& track : tracks) {
97 const std::string& track_id = track->id();
98 StatsReport* report = AddTrackReport(reports, track_id);
99 DCHECK(report != nullptr);
100 track_ids[track_id] = report;
101 }
95 } 102 }
96 103
97 void ExtractCommonSendProperties(const cricket::MediaSenderInfo& info, 104 void ExtractCommonSendProperties(const cricket::MediaSenderInfo& info,
98 StatsReport* report) { 105 StatsReport* report) {
99 report->AddString(StatsReport::kStatsValueNameCodecName, info.codec_name); 106 report->AddString(StatsReport::kStatsValueNameCodecName, info.codec_name);
100 report->AddInt64(StatsReport::kStatsValueNameBytesSent, info.bytes_sent); 107 report->AddInt64(StatsReport::kStatsValueNameBytesSent, info.bytes_sent);
101 report->AddInt64(StatsReport::kStatsValueNameRtt, info.rtt_ms); 108 report->AddInt64(StatsReport::kStatsValueNameRtt, info.rtt_ms);
102 } 109 }
103 110
104 void SetAudioProcessingStats(StatsReport* report, int signal_level, 111 void SetAudioProcessingStats(StatsReport* report, int signal_level,
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 return rtc::Timing::WallTimeNow() * rtc::kNumMillisecsPerSec; 365 return rtc::Timing::WallTimeNow() * rtc::kNumMillisecsPerSec;
359 } 366 }
360 367
361 // Adds a MediaStream with tracks that can be used as a |selector| in a call 368 // Adds a MediaStream with tracks that can be used as a |selector| in a call
362 // to GetStats. 369 // to GetStats.
363 void StatsCollector::AddStream(MediaStreamInterface* stream) { 370 void StatsCollector::AddStream(MediaStreamInterface* stream) {
364 DCHECK(session_->signaling_thread()->IsCurrent()); 371 DCHECK(session_->signaling_thread()->IsCurrent());
365 DCHECK(stream != NULL); 372 DCHECK(stream != NULL);
366 373
367 CreateTrackReports<AudioTrackVector>(stream->GetAudioTracks(), 374 CreateTrackReports<AudioTrackVector>(stream->GetAudioTracks(),
368 &reports_); 375 &reports_, track_ids_);
369 CreateTrackReports<VideoTrackVector>(stream->GetVideoTracks(), 376 CreateTrackReports<VideoTrackVector>(stream->GetVideoTracks(),
370 &reports_); 377 &reports_, track_ids_);
371 } 378 }
372 379
373 void StatsCollector::AddLocalAudioTrack(AudioTrackInterface* audio_track, 380 void StatsCollector::AddLocalAudioTrack(AudioTrackInterface* audio_track,
374 uint32 ssrc) { 381 uint32 ssrc) {
375 DCHECK(session_->signaling_thread()->IsCurrent()); 382 DCHECK(session_->signaling_thread()->IsCurrent());
376 DCHECK(audio_track != NULL); 383 DCHECK(audio_track != NULL);
377 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) 384 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
378 for (const auto& track : local_audio_tracks_) 385 for (const auto& track : local_audio_tracks_)
379 DCHECK(track.first != audio_track || track.second != ssrc); 386 DCHECK(track.first != audio_track || track.second != ssrc);
380 #endif 387 #endif
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 // TODO(tommi): All of these hop over to the worker thread to fetch 466 // TODO(tommi): All of these hop over to the worker thread to fetch
460 // information. We could use an AsyncInvoker to run all of these and post 467 // information. We could use an AsyncInvoker to run all of these and post
461 // the information back to the signaling thread where we can create and 468 // the information back to the signaling thread where we can create and
462 // update stats reports. That would also clean up the threading story a bit 469 // update stats reports. That would also clean up the threading story a bit
463 // since we'd be creating/updating the stats report objects consistently on 470 // since we'd be creating/updating the stats report objects consistently on
464 // the same thread (this class has no locks right now). 471 // the same thread (this class has no locks right now).
465 ExtractSessionInfo(); 472 ExtractSessionInfo();
466 ExtractVoiceInfo(); 473 ExtractVoiceInfo();
467 ExtractVideoInfo(level); 474 ExtractVideoInfo(level);
468 ExtractDataInfo(); 475 ExtractDataInfo();
476 UpdateTrackReports();
469 } 477 }
470 } 478 }
471 479
472 StatsReport* StatsCollector::PrepareReport( 480 StatsReport* StatsCollector::PrepareReport(
473 bool local, 481 bool local,
474 uint32 ssrc, 482 uint32 ssrc,
475 const StatsReport::Id& transport_id, 483 const StatsReport::Id& transport_id,
476 StatsReport::Direction direction) { 484 StatsReport::Direction direction) {
477 DCHECK(session_->signaling_thread()->IsCurrent()); 485 DCHECK(session_->signaling_thread()->IsCurrent());
478 StatsReport::Id id(StatsReport::NewIdWithDirection( 486 StatsReport::Id id(StatsReport::NewIdWithDirection(
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 LOG(LS_ERROR) << "Stats report does not exist for ssrc " << ssrc; 870 LOG(LS_ERROR) << "Stats report does not exist for ssrc " << ssrc;
863 continue; 871 continue;
864 } 872 }
865 873
866 // The same ssrc can be used by both local and remote audio tracks. 874 // The same ssrc can be used by both local and remote audio tracks.
867 const StatsReport::Value* v = 875 const StatsReport::Value* v =
868 report->FindValue(StatsReport::kStatsValueNameTrackId); 876 report->FindValue(StatsReport::kStatsValueNameTrackId);
869 if (!v || v->string_val() != track->id()) 877 if (!v || v->string_val() != track->id())
870 continue; 878 continue;
871 879
880 report->set_timestamp(stats_gathering_started_);
872 UpdateReportFromAudioTrack(track, report); 881 UpdateReportFromAudioTrack(track, report);
873 } 882 }
874 } 883 }
875 884
876 void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track, 885 void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track,
877 StatsReport* report) { 886 StatsReport* report) {
878 DCHECK(session_->signaling_thread()->IsCurrent()); 887 DCHECK(session_->signaling_thread()->IsCurrent());
879 DCHECK(track != NULL); 888 DCHECK(track != NULL);
880 889
881 int signal_level = 0; 890 int signal_level = 0;
(...skipping 27 matching lines...) Expand all
909 if (!session_->GetRemoteTrackIdBySsrc(ssrc, track_id)) { 918 if (!session_->GetRemoteTrackIdBySsrc(ssrc, track_id)) {
910 LOG(LS_WARNING) << "The SSRC " << ssrc 919 LOG(LS_WARNING) << "The SSRC " << ssrc
911 << " is not associated with a receiving track"; 920 << " is not associated with a receiving track";
912 return false; 921 return false;
913 } 922 }
914 } 923 }
915 924
916 return true; 925 return true;
917 } 926 }
918 927
928 void StatsCollector::UpdateTrackReports() {
929 DCHECK(session_->signaling_thread()->IsCurrent());
930
931 rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
932
933 for (const auto& entry : track_ids_) {
934 StatsReport* report = entry.second;
935 report->set_timestamp(stats_gathering_started_);
936 }
937
938 }
939
919 void StatsCollector::ClearUpdateStatsCacheForTest() { 940 void StatsCollector::ClearUpdateStatsCacheForTest() {
920 stats_gathering_started_ = 0; 941 stats_gathering_started_ = 0;
921 } 942 }
922 943
923 } // namespace webrtc 944 } // namespace webrtc
OLDNEW
« no previous file with comments | « talk/app/webrtc/statscollector.h ('k') | talk/app/webrtc/statscollector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698