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

Side by Side Diff: remoting/client/plugin/chromoting_instance.cc

Issue 1181743005: Report video and network stats averaged over 1s, and create corresponding UMA metrics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Set time-window for display stats rate-counters to 3. Created 5 years, 5 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
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 "remoting/client/plugin/chromoting_instance.h" 5 #include "remoting/client/plugin/chromoting_instance.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #if defined(OS_NACL) 10 #if defined(OS_NACL)
(...skipping 14 matching lines...) Expand all
25 #include "base/threading/thread.h" 25 #include "base/threading/thread.h"
26 #include "base/values.h" 26 #include "base/values.h"
27 #include "crypto/random.h" 27 #include "crypto/random.h"
28 #include "jingle/glue/thread_wrapper.h" 28 #include "jingle/glue/thread_wrapper.h"
29 #include "media/base/yuv_convert.h" 29 #include "media/base/yuv_convert.h"
30 #include "net/socket/ssl_server_socket.h" 30 #include "net/socket/ssl_server_socket.h"
31 #include "ppapi/cpp/completion_callback.h" 31 #include "ppapi/cpp/completion_callback.h"
32 #include "ppapi/cpp/dev/url_util_dev.h" 32 #include "ppapi/cpp/dev/url_util_dev.h"
33 #include "ppapi/cpp/image_data.h" 33 #include "ppapi/cpp/image_data.h"
34 #include "ppapi/cpp/input_event.h" 34 #include "ppapi/cpp/input_event.h"
35 #include "ppapi/cpp/private/uma_private.h"
35 #include "ppapi/cpp/rect.h" 36 #include "ppapi/cpp/rect.h"
36 #include "ppapi/cpp/var_array_buffer.h" 37 #include "ppapi/cpp/var_array_buffer.h"
37 #include "ppapi/cpp/var_dictionary.h" 38 #include "ppapi/cpp/var_dictionary.h"
38 #include "remoting/base/constants.h" 39 #include "remoting/base/constants.h"
39 #include "remoting/base/util.h" 40 #include "remoting/base/util.h"
40 #include "remoting/client/chromoting_client.h" 41 #include "remoting/client/chromoting_client.h"
41 #include "remoting/client/plugin/delegating_signal_strategy.h" 42 #include "remoting/client/plugin/delegating_signal_strategy.h"
42 #include "remoting/client/plugin/normalizing_input_filter_cros.h" 43 #include "remoting/client/plugin/normalizing_input_filter_cros.h"
43 #include "remoting/client/plugin/normalizing_input_filter_mac.h" 44 #include "remoting/client/plugin/normalizing_input_filter_mac.h"
44 #include "remoting/client/plugin/pepper_audio_player.h" 45 #include "remoting/client/plugin/pepper_audio_player.h"
(...skipping 15 matching lines...) Expand all
60 #undef PostMessage 61 #undef PostMessage
61 #endif 62 #endif
62 63
63 namespace remoting { 64 namespace remoting {
64 65
65 namespace { 66 namespace {
66 67
67 // Default DPI to assume for old clients that use notifyClientResolution. 68 // Default DPI to assume for old clients that use notifyClientResolution.
68 const int kDefaultDPI = 96; 69 const int kDefaultDPI = 96;
69 70
70 // Interval at which to sample performance statistics.
71 const int kPerfStatsIntervalMs = 1000;
72
73 // URL scheme used by Chrome apps and extensions. 71 // URL scheme used by Chrome apps and extensions.
74 const char kChromeExtensionUrlScheme[] = "chrome-extension"; 72 const char kChromeExtensionUrlScheme[] = "chrome-extension";
75 73
74 // The boundary value for the FPS histogram: we don't expect video frame-rate to
75 // be greater than 40fps.
76 // Histograms expect samples to be less than the boundary value, so set to 41.
77 const int kMaxFrameRate = 41;
78 // For bandwidth, we'll use a histogram ranging from 0 to 1MB/s, spread across
79 // 1000 buckets.
80 // Histograms are log-scaled by default. This results in fine-grained buckets at
81 // lower values and wider-ranged buckets closer to the maximum.
82 // Values above the maximum defined here end up in the right-most bucket.
83 // See $/src/base/metrics/histogram.h for more details.
84 const int kBandwidthHistogramMin = 1;
85 const int kBandwidthHistogramMax = 1024000;
86 const int kBandwidthHistogramNumBuckets = 1000;
87
88 // For the latency metrics, we'll set the max histogram value to 20,000ms, split
89 // over 1000 buckets.
90 const int kLatencyHistogramMin = 1;
91 const int kLatencyHistogramMax = 20000;
92 const int kLatencyHistogramNumBuckets = 1000;
93
76 #if defined(USE_OPENSSL) 94 #if defined(USE_OPENSSL)
77 // Size of the random seed blob used to initialize RNG in libjingle. Libjingle 95 // Size of the random seed blob used to initialize RNG in libjingle. Libjingle
78 // uses the seed only for OpenSSL builds. OpenSSL needs at least 32 bytes of 96 // uses the seed only for OpenSSL builds. OpenSSL needs at least 32 bytes of
79 // entropy (see http://wiki.openssl.org/index.php/Random_Numbers), but stores 97 // entropy (see http://wiki.openssl.org/index.php/Random_Numbers), but stores
80 // 1039 bytes of state, so we initialize it with 1k or random data. 98 // 1039 bytes of state, so we initialize it with 1k or random data.
81 const int kRandomSeedSize = 1024; 99 const int kRandomSeedSize = 1024;
82 #endif // defined(USE_OPENSSL) 100 #endif // defined(USE_OPENSSL)
83 101
84 std::string ConnectionStateToString(protocol::ConnectionToHost::State state) { 102 std::string ConnectionStateToString(protocol::ConnectionToHost::State state) {
85 // Values returned by this function must match the 103 // Values returned by this function must match the
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 host_public_key)); 739 host_public_key));
722 scoped_ptr<protocol::Authenticator> authenticator( 740 scoped_ptr<protocol::Authenticator> authenticator(
723 new protocol::NegotiatingClientAuthenticator( 741 new protocol::NegotiatingClientAuthenticator(
724 client_pairing_id, client_paired_secret, authentication_tag, 742 client_pairing_id, client_paired_secret, authentication_tag,
725 fetch_secret_callback, token_fetcher.Pass(), auth_methods)); 743 fetch_secret_callback, token_fetcher.Pass(), auth_methods));
726 744
727 // Kick off the connection. 745 // Kick off the connection.
728 client_->Start(signal_strategy_.get(), authenticator.Pass(), 746 client_->Start(signal_strategy_.get(), authenticator.Pass(),
729 transport_factory.Pass(), host_jid, capabilities); 747 transport_factory.Pass(), host_jid, capabilities);
730 748
731 // Start timer that periodically sends perf stats. 749 // Start timers that periodically send perf stats, for display and for UMA.
732 plugin_task_runner_->PostDelayedTask( 750 plugin_task_runner_->PostDelayedTask(
733 FROM_HERE, base::Bind(&ChromotingInstance::SendPerfStats, 751 FROM_HERE, base::Bind(&ChromotingInstance::SendDisplayPerfStats,
734 weak_factory_.GetWeakPtr()), 752 weak_factory_.GetWeakPtr()),
735 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); 753 base::TimeDelta::FromSeconds(
754 video_renderer_->GetStats()->kDisplayStatsUpdateWindowInSeconds));
755 plugin_task_runner_->PostDelayedTask(
756 FROM_HERE, base::Bind(&ChromotingInstance::SendUMAPerfStats,
757 weak_factory_.GetWeakPtr()),
758 base::TimeDelta::FromSeconds(
759 video_renderer_->GetStats()->kUMAStatsTimeWindowInSeconds));
736 } 760 }
737 761
738 void ChromotingInstance::HandleDisconnect(const base::DictionaryValue& data) { 762 void ChromotingInstance::HandleDisconnect(const base::DictionaryValue& data) {
739 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 763 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
740 Disconnect(); 764 Disconnect();
741 } 765 }
742 766
743 void ChromotingInstance::HandleOnIncomingIq(const base::DictionaryValue& data) { 767 void ChromotingInstance::HandleOnIncomingIq(const base::DictionaryValue& data) {
744 std::string iq; 768 std::string iq;
745 if (!data.GetString("iq", &iq)) { 769 if (!data.GetString("iq", &iq)) {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 data->SetBoolean("pressed", pressed); 1061 data->SetBoolean("pressed", pressed);
1038 PostLegacyJsonMessage("trappedKeyEvent", data.Pass()); 1062 PostLegacyJsonMessage("trappedKeyEvent", data.Pass());
1039 } 1063 }
1040 1064
1041 void ChromotingInstance::SendOutgoingIq(const std::string& iq) { 1065 void ChromotingInstance::SendOutgoingIq(const std::string& iq) {
1042 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); 1066 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
1043 data->SetString("iq", iq); 1067 data->SetString("iq", iq);
1044 PostLegacyJsonMessage("sendOutgoingIq", data.Pass()); 1068 PostLegacyJsonMessage("sendOutgoingIq", data.Pass());
1045 } 1069 }
1046 1070
1047 void ChromotingInstance::SendPerfStats() { 1071 void ChromotingInstance::SendDisplayPerfStats() {
1048 if (!video_renderer_.get()) { 1072 if (!video_renderer_.get()) {
1049 return; 1073 return;
1050 } 1074 }
1051 1075
1076 ChromotingStats* stats = video_renderer_->GetStats();
Sergey Ulanov 2015/07/08 20:06:47 you can keep this line where it was - the consts i
anandc 2015/07/08 22:43:34 Done.
1052 plugin_task_runner_->PostDelayedTask( 1077 plugin_task_runner_->PostDelayedTask(
1053 FROM_HERE, base::Bind(&ChromotingInstance::SendPerfStats, 1078 FROM_HERE, base::Bind(&ChromotingInstance::SendDisplayPerfStats,
1054 weak_factory_.GetWeakPtr()), 1079 weak_factory_.GetWeakPtr()),
1055 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); 1080 base::TimeDelta::FromSeconds(stats->kDisplayStatsUpdateWindowInSeconds));
1056 1081
1082 // Update performance stats, averaged over the past few seconds.
1083 // These are eventually upstreamed to the client and available for display to
1084 // the user.
1057 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); 1085 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
1058 ChromotingStats* stats = video_renderer_->GetStats(); 1086 data->SetDouble("videoBandwidth", stats->video_bandwidth_display()->Rate());
1059 data->SetDouble("videoBandwidth", stats->video_bandwidth()->Rate()); 1087 data->SetDouble("videoFrameRate", stats->video_frame_rate_display()->Rate());
1060 data->SetDouble("videoFrameRate", stats->video_frame_rate()->Rate());
1061 data->SetDouble("captureLatency", stats->video_capture_ms()->Average()); 1088 data->SetDouble("captureLatency", stats->video_capture_ms()->Average());
1062 data->SetDouble("encodeLatency", stats->video_encode_ms()->Average()); 1089 data->SetDouble("encodeLatency", stats->video_encode_ms()->Average());
1063 data->SetDouble("decodeLatency", stats->video_decode_ms()->Average()); 1090 data->SetDouble("decodeLatency", stats->video_decode_ms()->Average());
1064 data->SetDouble("renderLatency", stats->video_paint_ms()->Average()); 1091 data->SetDouble("renderLatency", stats->video_paint_ms()->Average());
1065 data->SetDouble("roundtripLatency", stats->round_trip_ms()->Average()); 1092 data->SetDouble("roundtripLatency", stats->round_trip_ms()->Average());
1066 PostLegacyJsonMessage("onPerfStats", data.Pass()); 1093 PostLegacyJsonMessage("onPerfStats", data.Pass());
1067 } 1094 }
1068 1095
1096 void ChromotingInstance::SendUMAPerfStats() {
1097 if (!video_renderer_.get()) {
1098 return;
1099 }
1100
1101 ChromotingStats* stats = video_renderer_->GetStats();
Sergey Ulanov 2015/07/08 20:06:47 move this below, before uma_interface calls.
anandc 2015/07/08 22:43:34 Done.
1102 plugin_task_runner_->PostDelayedTask(
1103 FROM_HERE, base::Bind(&ChromotingInstance::SendUMAPerfStats,
1104 weak_factory_.GetWeakPtr()),
1105 base::TimeDelta::FromSeconds(stats->kUMAStatsTimeWindowInSeconds));
1106
1107 // Update UMA histograms for video frame-rate, bandwidth and latencies.
1108 // These metrics will be averaged over the last second.
1109 pp::UMAPrivate uma_interface(this);
Sergey Ulanov 2015/07/08 20:06:47 Maybe call this uma?
anandc 2015/07/08 22:43:34 Done.
1110 uma_interface.HistogramEnumeration("Chromoting.Video.FrameRate",
1111 stats->video_frame_rate_uma()->Rate(), kMaxFrameRate);
1112 uma_interface.HistogramEnumeration("Chromoting.Video.PacketRate",
1113 stats->video_packet_rate_uma()->Rate(), kMaxFrameRate);
1114 uma_interface.HistogramCustomCounts("Chromoting.Video.Bandwidth",
1115 stats->video_bandwidth_uma()->Rate(), kBandwidthHistogramMin,
1116 kBandwidthHistogramMax, kBandwidthHistogramNumBuckets);
1117 uma_interface.HistogramCustomTimes("Chromoting.Video.CaptureLatency",
1118 stats->video_capture_ms()->Average(), kLatencyHistogramMin,
1119 kLatencyHistogramMax, kLatencyHistogramNumBuckets);
1120 uma_interface.HistogramCustomTimes("Chromoting.Video.EncodeLatency",
1121 stats->video_encode_ms()->Average(), kLatencyHistogramMin,
1122 kLatencyHistogramMax, kLatencyHistogramNumBuckets);
1123 uma_interface.HistogramCustomTimes("Chromoting.Video.RoundTripLatency",
1124 stats->round_trip_ms()->Average(), kLatencyHistogramMin,
1125 kLatencyHistogramMax, kLatencyHistogramNumBuckets);
1126 }
1127
1069 // static 1128 // static
1070 void ChromotingInstance::RegisterLogMessageHandler() { 1129 void ChromotingInstance::RegisterLogMessageHandler() {
1071 base::AutoLock lock(g_logging_lock.Get()); 1130 base::AutoLock lock(g_logging_lock.Get());
1072 1131
1073 VLOG(1) << "Registering global log handler"; 1132 VLOG(1) << "Registering global log handler";
1074 1133
1075 // Record previous handler so we can call it in a chain. 1134 // Record previous handler so we can call it in a chain.
1076 g_logging_old_handler = logging::GetLogMessageHandler(); 1135 g_logging_old_handler = logging::GetLogMessageHandler();
1077 1136
1078 // Set up log message handler. 1137 // Set up log message handler.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 1255
1197 #if !defined(OS_NACL) 1256 #if !defined(OS_NACL)
1198 // Log messages are forwarded to the webapp only in PNaCl version of the 1257 // Log messages are forwarded to the webapp only in PNaCl version of the
1199 // plugin, so ProcessLogToUI() needs to be called explicitly in the non-PNaCl 1258 // plugin, so ProcessLogToUI() needs to be called explicitly in the non-PNaCl
1200 // version. 1259 // version.
1201 ProcessLogToUI(message); 1260 ProcessLogToUI(message);
1202 #endif // !defined(OS_NACL) 1261 #endif // !defined(OS_NACL)
1203 } 1262 }
1204 1263
1205 } // namespace remoting 1264 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698