| 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_ << ": " << message_size() << " " << unit_ << " in " |
| 175 << ": " | 186 << message_count() << " packages, last package " << last_message_size() |
| 176 << message_size() | 187 << " " << unit_ << ", " << AverageMessageSize() << " " << unit_ |
| 177 << " bytes in " | 188 << "/package, " << MessagesPerSecond() << " packages/sec, " |
| 178 << message_count() | 189 << SizePerSecond() << " " << unit_ << "/sec" << std::endl; |
| 179 << " packages, last package " | |
| 180 << last_message_size() | |
| 181 << " bytes, " | |
| 182 << AverageMessageSize() | |
| 183 << " bytes/package, " | |
| 184 << MessagesPerSecond() | |
| 185 << " packages/sec, " | |
| 186 << SizePerSecond() | |
| 187 << " bytes/sec" | |
| 188 << std::endl; | |
| 189 } | 190 } |
| 190 | 191 |
| 191 } // namespace | 192 } // namespace |
| 192 | 193 |
| 193 // Analyzes messages from DeliverHostMessage function. | 194 // Analyzes messages from DeliverHostMessage function. |
| 194 class FakeConnectionEventLogger::CounterClientStub | 195 class FakeConnectionEventLogger::CounterClientStub |
| 195 : public protocol::ClientStub, public MessageCounter { | 196 : public protocol::ClientStub, public MessageCounter { |
| 196 public: | 197 public: |
| 197 CounterClientStub(); | 198 CounterClientStub(); |
| 198 | 199 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 261 } |
| 261 done.Run(); | 262 done.Run(); |
| 262 } | 263 } |
| 263 | 264 |
| 264 // Analyzes messages from ProcessVideoPacket function. | 265 // Analyzes messages from ProcessVideoPacket function. |
| 265 class FakeConnectionEventLogger::CounterVideoStub | 266 class FakeConnectionEventLogger::CounterVideoStub |
| 266 : public protocol::VideoStub, public MessageCounter { | 267 : public protocol::VideoStub, public MessageCounter { |
| 267 public: | 268 public: |
| 268 CounterVideoStub(protocol::FakeConnectionToClient* connection); | 269 CounterVideoStub(protocol::FakeConnectionToClient* connection); |
| 269 | 270 |
| 271 void DisplayStatistics(std::ostream& os) override; |
| 272 |
| 270 private: | 273 private: |
| 271 void ProcessVideoPacket(std::unique_ptr<VideoPacket> video_packet, | 274 void ProcessVideoPacket(std::unique_ptr<VideoPacket> video_packet, |
| 272 const base::Closure& done) override; | 275 const base::Closure& done) override; |
| 273 | 276 |
| 274 protocol::FakeConnectionToClient* connection_ = nullptr; | 277 protocol::FakeConnectionToClient* connection_ = nullptr; |
| 278 MessageCounter video_data_; |
| 279 MessageCounter capture_time_; |
| 280 MessageCounter encode_time_; |
| 275 }; | 281 }; |
| 276 | 282 |
| 277 FakeConnectionEventLogger::CounterVideoStub::CounterVideoStub( | 283 FakeConnectionEventLogger::CounterVideoStub::CounterVideoStub( |
| 278 protocol::FakeConnectionToClient* connection) | 284 protocol::FakeConnectionToClient* connection) |
| 279 : MessageCounter("video"), | 285 : MessageCounter("video"), |
| 280 connection_(connection) {} | 286 connection_(connection), |
| 287 video_data_("video-data"), |
| 288 capture_time_("capture-time", "ms"), |
| 289 encode_time_("encode-time", "ms") {} |
| 290 |
| 291 void FakeConnectionEventLogger::CounterVideoStub::DisplayStatistics( |
| 292 std::ostream& os) { |
| 293 MessageCounter::DisplayStatistics(os); |
| 294 video_data_.DisplayStatistics(os); |
| 295 capture_time_.DisplayStatistics(os); |
| 296 encode_time_.DisplayStatistics(os); |
| 297 } |
| 281 | 298 |
| 282 void FakeConnectionEventLogger::CounterVideoStub::ProcessVideoPacket( | 299 void FakeConnectionEventLogger::CounterVideoStub::ProcessVideoPacket( |
| 283 std::unique_ptr<VideoPacket> video_packet, | 300 std::unique_ptr<VideoPacket> video_packet, |
| 284 const base::Closure& done) { | 301 const base::Closure& done) { |
| 285 if (video_packet && video_packet->has_capture_overhead_time_ms()) { | 302 if (video_packet && video_packet->has_capture_overhead_time_ms()) { |
| 286 // Not a keepalive packet. | 303 // Not a keepalive packet. |
| 287 if (connection_ && | 304 if (connection_ && |
| 288 connection_->video_feedback_stub()) { | 305 connection_->video_feedback_stub()) { |
| 289 std::unique_ptr<VideoAck> ack(new VideoAck()); | 306 std::unique_ptr<VideoAck> ack(new VideoAck()); |
| 290 ack->set_frame_id(video_packet->frame_id()); | 307 ack->set_frame_id(video_packet->frame_id()); |
| 291 connection_->video_feedback_stub()->ProcessVideoAck(std::move(ack)); | 308 connection_->video_feedback_stub()->ProcessVideoAck(std::move(ack)); |
| 292 } | 309 } |
| 293 LogMessage(*video_packet); | 310 LogMessage(*video_packet); |
| 311 video_data_.LogMessage(video_packet->data().size()); |
| 312 capture_time_.LogMessage(video_packet->capture_time_ms()); |
| 313 encode_time_.LogMessage(video_packet->encode_time_ms()); |
| 294 } | 314 } |
| 295 done.Run(); | 315 done.Run(); |
| 296 } | 316 } |
| 297 | 317 |
| 298 FakeConnectionEventLogger::FakeConnectionEventLogger( | 318 FakeConnectionEventLogger::FakeConnectionEventLogger( |
| 299 protocol::FakeConnectionToClient* connection) | 319 protocol::FakeConnectionToClient* connection) |
| 300 : client_stub_(new CounterClientStub()), | 320 : client_stub_(new CounterClientStub()), |
| 301 host_stub_(new CounterHostStub()), | 321 host_stub_(new CounterHostStub()), |
| 302 audio_stub_(new CounterAudioStub()), | 322 audio_stub_(new CounterAudioStub()), |
| 303 video_stub_(new CounterVideoStub(connection)) {} | 323 video_stub_(new CounterVideoStub(connection)) {} |
| (...skipping 20 matching lines...) Expand all Loading... |
| 324 const FakeConnectionEventLogger& logger) { | 344 const FakeConnectionEventLogger& logger) { |
| 325 logger.audio_stub_->DisplayStatistics(os); | 345 logger.audio_stub_->DisplayStatistics(os); |
| 326 logger.video_stub_->DisplayStatistics(os); | 346 logger.video_stub_->DisplayStatistics(os); |
| 327 logger.client_stub_->DisplayStatistics(os); | 347 logger.client_stub_->DisplayStatistics(os); |
| 328 logger.host_stub_->DisplayStatistics(os); | 348 logger.host_stub_->DisplayStatistics(os); |
| 329 return os; | 349 return os; |
| 330 } | 350 } |
| 331 | 351 |
| 332 } // namespace test | 352 } // namespace test |
| 333 } // namespace remoting | 353 } // namespace remoting |
| OLD | NEW |