Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/test/fake_connection_event_logger.h" | 5 #include "remoting/test/fake_connection_event_logger.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 | 112 |
| 113 int64_t NoBarrierAtomicInt64::operator*() const { | 113 int64_t NoBarrierAtomicInt64::operator*() const { |
| 114 AutoLock l(lock_); | 114 AutoLock l(lock_); |
| 115 return i_; | 115 return i_; |
| 116 } | 116 } |
| 117 | 117 |
| 118 #endif // ifdef ARCH_CPU_64_BITS | 118 #endif // ifdef ARCH_CPU_64_BITS |
| 119 | 119 |
| 120 class MessageCounter { | 120 class MessageCounter { |
| 121 public: | 121 public: |
| 122 MessageCounter(const char* name, const char* unit); | |
| 122 explicit MessageCounter(const char* name); | 123 explicit MessageCounter(const char* name); |
| 123 | 124 |
| 124 int message_count() const { return *count_; } | 125 int message_count() const { return *count_; } |
| 125 int64_t message_size() const { return *size_; } | 126 int64_t message_size() const { return *size_; } |
| 126 int last_message_size() const { return last_size_; } | 127 int last_message_size() const { return last_size_; } |
| 127 double DurationSeconds() const; | 128 double DurationSeconds() const; |
| 128 double MessagesPerSecond() const; | 129 double MessagesPerSecond() const; |
| 129 double SizePerSecond() const; | 130 double SizePerSecond() const; |
| 130 double AverageMessageSize() const; | 131 double AverageMessageSize() const; |
| 131 void LogMessage(const ::google::protobuf::MessageLite& message); | 132 void LogMessage(const ::google::protobuf::MessageLite& message); |
| 132 void DisplayStatistics(std::ostream& os); | 133 void LogMessage(int size); |
| 134 virtual void DisplayStatistics(std::ostream& os); | |
| 133 | 135 |
| 134 private: | 136 private: |
| 135 std::string name_; | 137 const std::string name_; |
| 138 const std::string unit_; | |
| 136 NoBarrierAtomicInt32 count_; | 139 NoBarrierAtomicInt32 count_; |
| 137 NoBarrierAtomicInt64 size_; | 140 NoBarrierAtomicInt64 size_; |
| 138 int last_size_ = 0; | 141 int last_size_ = 0; |
| 139 base::Time start_time_; | 142 base::Time start_time_; |
| 140 | 143 |
| 141 // Copy or assign the start_time_ of a MessageCounter is senseless. | 144 // Copy or assign the start_time_ of a MessageCounter is senseless. |
| 142 DISALLOW_COPY_AND_ASSIGN(MessageCounter); | 145 DISALLOW_COPY_AND_ASSIGN(MessageCounter); |
| 143 }; | 146 }; |
| 144 | 147 |
| 145 MessageCounter::MessageCounter(const char* name) | 148 MessageCounter::MessageCounter(const char* name, const char* unit) |
| 146 : name_(name), | 149 : name_(name), |
| 150 unit_(unit), | |
| 147 count_(), | 151 count_(), |
| 148 size_(), | 152 size_(), |
| 149 start_time_(base::Time::Now()) {} | 153 start_time_(base::Time::Now()) {} |
| 150 | 154 |
| 155 MessageCounter::MessageCounter(const char* name) | |
| 156 : MessageCounter(name, "bytes") {} | |
| 157 | |
| 151 double MessageCounter::DurationSeconds() const { | 158 double MessageCounter::DurationSeconds() const { |
| 152 return (base::Time::Now() - start_time_).InSecondsF(); | 159 return (base::Time::Now() - start_time_).InSecondsF(); |
| 153 } | 160 } |
| 154 | 161 |
| 155 double MessageCounter::MessagesPerSecond() const { | 162 double MessageCounter::MessagesPerSecond() const { |
| 156 return static_cast<double>(message_count()) / DurationSeconds(); | 163 return static_cast<double>(message_count()) / DurationSeconds(); |
| 157 } | 164 } |
| 158 double MessageCounter::SizePerSecond() const { | 165 double MessageCounter::SizePerSecond() const { |
| 159 return static_cast<double>(message_size()) / DurationSeconds(); | 166 return static_cast<double>(message_size()) / DurationSeconds(); |
| 160 } | 167 } |
| 161 | 168 |
| 162 double MessageCounter::AverageMessageSize() const { | 169 double MessageCounter::AverageMessageSize() const { |
| 163 return static_cast<double>(message_size()) / message_count(); | 170 return static_cast<double>(message_size()) / message_count(); |
| 164 } | 171 } |
| 165 | 172 |
| 166 void MessageCounter::LogMessage( | 173 void MessageCounter::LogMessage( |
| 167 const ::google::protobuf::MessageLite& message) { | 174 const ::google::protobuf::MessageLite& message) { |
| 175 LogMessage(message.ByteSize()); | |
| 176 } | |
| 177 | |
| 178 void MessageCounter::LogMessage(int size) { | |
| 168 count_++; | 179 count_++; |
| 169 last_size_ = message.ByteSize(); | 180 last_size_ = size; |
| 170 size_ += message.ByteSize(); | 181 size_ += size; |
| 171 } | 182 } |
| 172 | 183 |
| 173 void MessageCounter::DisplayStatistics(std::ostream& os) { | 184 void MessageCounter::DisplayStatistics(std::ostream& os) { |
| 174 os << name_ | 185 os << name_ |
| 175 << ": " | 186 << ": " |
| 176 << message_size() | 187 << message_size() |
| 177 << " bytes in " | 188 << " " |
| 189 << unit_ | |
| 190 << " in " | |
|
joedow
2016/09/09 19:23:05
nit, this would be a bit more readble if you moved
Hzj_jie
2016/09/09 21:33:25
Done.
| |
| 178 << message_count() | 191 << message_count() |
| 179 << " packages, last package " | 192 << " packages, last package " |
| 180 << last_message_size() | 193 << last_message_size() |
| 181 << " bytes, " | 194 << " " |
| 195 << unit_ | |
| 196 << ", " | |
| 182 << AverageMessageSize() | 197 << AverageMessageSize() |
| 183 << " bytes/package, " | 198 << " " |
| 199 << unit_ | |
| 200 << "/package, " | |
| 184 << MessagesPerSecond() | 201 << MessagesPerSecond() |
| 185 << " packages/sec, " | 202 << " packages/sec, " |
| 186 << SizePerSecond() | 203 << SizePerSecond() |
| 187 << " bytes/sec" | 204 << " " |
| 205 << unit_ | |
| 206 << "/sec" | |
| 188 << std::endl; | 207 << std::endl; |
| 189 } | 208 } |
| 190 | 209 |
| 191 } // namespace | 210 } // namespace |
| 192 | 211 |
| 193 // Analyzes messages from DeliverHostMessage function. | 212 // Analyzes messages from DeliverHostMessage function. |
| 194 class FakeConnectionEventLogger::CounterClientStub | 213 class FakeConnectionEventLogger::CounterClientStub |
| 195 : public protocol::ClientStub, public MessageCounter { | 214 : public protocol::ClientStub, public MessageCounter { |
| 196 public: | 215 public: |
| 197 CounterClientStub(); | 216 CounterClientStub(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 } | 279 } |
| 261 done.Run(); | 280 done.Run(); |
| 262 } | 281 } |
| 263 | 282 |
| 264 // Analyzes messages from ProcessVideoPacket function. | 283 // Analyzes messages from ProcessVideoPacket function. |
| 265 class FakeConnectionEventLogger::CounterVideoStub | 284 class FakeConnectionEventLogger::CounterVideoStub |
| 266 : public protocol::VideoStub, public MessageCounter { | 285 : public protocol::VideoStub, public MessageCounter { |
| 267 public: | 286 public: |
| 268 CounterVideoStub(protocol::FakeConnectionToClient* connection); | 287 CounterVideoStub(protocol::FakeConnectionToClient* connection); |
| 269 | 288 |
| 289 void DisplayStatistics(std::ostream& os) override; | |
| 290 | |
| 270 private: | 291 private: |
| 271 void ProcessVideoPacket(std::unique_ptr<VideoPacket> video_packet, | 292 void ProcessVideoPacket(std::unique_ptr<VideoPacket> video_packet, |
| 272 const base::Closure& done) override; | 293 const base::Closure& done) override; |
| 273 | 294 |
| 274 protocol::FakeConnectionToClient* connection_ = nullptr; | 295 protocol::FakeConnectionToClient* connection_ = nullptr; |
| 296 MessageCounter video_data_; | |
| 297 MessageCounter capture_time_; | |
| 298 MessageCounter encode_time_; | |
| 275 }; | 299 }; |
| 276 | 300 |
| 277 FakeConnectionEventLogger::CounterVideoStub::CounterVideoStub( | 301 FakeConnectionEventLogger::CounterVideoStub::CounterVideoStub( |
| 278 protocol::FakeConnectionToClient* connection) | 302 protocol::FakeConnectionToClient* connection) |
| 279 : MessageCounter("video"), | 303 : MessageCounter("video"), |
| 280 connection_(connection) {} | 304 connection_(connection), |
| 305 video_data_("video-data"), | |
| 306 capture_time_("capture-time", "ms"), | |
| 307 encode_time_("encode-time", "ms") {} | |
| 308 | |
| 309 void FakeConnectionEventLogger::CounterVideoStub::DisplayStatistics( | |
| 310 std::ostream& os) { | |
| 311 MessageCounter::DisplayStatistics(os); | |
| 312 video_data_.DisplayStatistics(os); | |
| 313 capture_time_.DisplayStatistics(os); | |
| 314 encode_time_.DisplayStatistics(os); | |
| 315 } | |
| 281 | 316 |
| 282 void FakeConnectionEventLogger::CounterVideoStub::ProcessVideoPacket( | 317 void FakeConnectionEventLogger::CounterVideoStub::ProcessVideoPacket( |
| 283 std::unique_ptr<VideoPacket> video_packet, | 318 std::unique_ptr<VideoPacket> video_packet, |
| 284 const base::Closure& done) { | 319 const base::Closure& done) { |
| 285 if (video_packet && video_packet->has_capture_overhead_time_ms()) { | 320 if (video_packet && video_packet->has_capture_overhead_time_ms()) { |
| 286 // Not a keepalive packet. | 321 // Not a keepalive packet. |
| 287 if (connection_ && | 322 if (connection_ && |
| 288 connection_->video_feedback_stub()) { | 323 connection_->video_feedback_stub()) { |
| 289 std::unique_ptr<VideoAck> ack(new VideoAck()); | 324 std::unique_ptr<VideoAck> ack(new VideoAck()); |
| 290 ack->set_frame_id(video_packet->frame_id()); | 325 ack->set_frame_id(video_packet->frame_id()); |
| 291 connection_->video_feedback_stub()->ProcessVideoAck(std::move(ack)); | 326 connection_->video_feedback_stub()->ProcessVideoAck(std::move(ack)); |
| 292 } | 327 } |
| 293 LogMessage(*video_packet); | 328 LogMessage(*video_packet); |
| 329 video_data_.LogMessage(video_packet->data().size()); | |
| 330 capture_time_.LogMessage(video_packet->capture_time_ms()); | |
| 331 encode_time_.LogMessage(video_packet->encode_time_ms()); | |
| 294 } | 332 } |
| 295 done.Run(); | 333 done.Run(); |
| 296 } | 334 } |
| 297 | 335 |
| 298 FakeConnectionEventLogger::FakeConnectionEventLogger( | 336 FakeConnectionEventLogger::FakeConnectionEventLogger( |
| 299 protocol::FakeConnectionToClient* connection) | 337 protocol::FakeConnectionToClient* connection) |
| 300 : client_stub_(new CounterClientStub()), | 338 : client_stub_(new CounterClientStub()), |
| 301 host_stub_(new CounterHostStub()), | 339 host_stub_(new CounterHostStub()), |
| 302 audio_stub_(new CounterAudioStub()), | 340 audio_stub_(new CounterAudioStub()), |
| 303 video_stub_(new CounterVideoStub(connection)) {} | 341 video_stub_(new CounterVideoStub(connection)) {} |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 324 const FakeConnectionEventLogger& logger) { | 362 const FakeConnectionEventLogger& logger) { |
| 325 logger.audio_stub_->DisplayStatistics(os); | 363 logger.audio_stub_->DisplayStatistics(os); |
| 326 logger.video_stub_->DisplayStatistics(os); | 364 logger.video_stub_->DisplayStatistics(os); |
| 327 logger.client_stub_->DisplayStatistics(os); | 365 logger.client_stub_->DisplayStatistics(os); |
| 328 logger.host_stub_->DisplayStatistics(os); | 366 logger.host_stub_->DisplayStatistics(os); |
| 329 return os; | 367 return os; |
| 330 } | 368 } |
| 331 | 369 |
| 332 } // namespace test | 370 } // namespace test |
| 333 } // namespace remoting | 371 } // namespace remoting |
| OLD | NEW |