OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <numeric> | 5 #include <numeric> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/base64.h" | 8 #include "base/base64.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 if (!done.is_null()) | 156 if (!done.is_null()) |
157 done.Run(); | 157 done.Run(); |
158 } | 158 } |
159 | 159 |
160 protocol::FrameConsumer::PixelFormat GetPixelFormat() override { | 160 protocol::FrameConsumer::PixelFormat GetPixelFormat() override { |
161 return FORMAT_BGRA; | 161 return FORMAT_BGRA; |
162 } | 162 } |
163 | 163 |
164 // FrameStatsConsumer interface. | 164 // FrameStatsConsumer interface. |
165 void OnVideoFrameStats(const protocol::FrameStats& frame_stats) override { | 165 void OnVideoFrameStats(const protocol::FrameStats& frame_stats) override { |
| 166 // Ignore store stats for empty frames. |
| 167 if (!frame_stats.host_stats.frame_size) |
| 168 return; |
| 169 |
166 frame_stats_.push_back(frame_stats); | 170 frame_stats_.push_back(frame_stats); |
167 | 171 |
168 if (waiting_frame_stats_loop_ && | 172 if (waiting_frame_stats_loop_ && |
169 frame_stats_.size() >= num_expected_frame_stats_) { | 173 frame_stats_.size() >= num_expected_frame_stats_) { |
170 waiting_frame_stats_loop_->Quit(); | 174 waiting_frame_stats_loop_->Quit(); |
171 } | 175 } |
172 } | 176 } |
173 | 177 |
174 // HostStatusObserver interface. | 178 // HostStatusObserver interface. |
| 179 void OnClientAuthenticated(const std::string& jid) override { |
| 180 if (event_timestamp_source_) { |
| 181 auto& session = host_->client_sessions_for_tests().front(); |
| 182 session->SetEventTimestampsSourceForTests( |
| 183 std::move(event_timestamp_source_)); |
| 184 } |
| 185 } |
| 186 |
175 void OnClientConnected(const std::string& jid) override { | 187 void OnClientConnected(const std::string& jid) override { |
176 message_loop_.task_runner()->PostTask( | 188 message_loop_.task_runner()->PostTask( |
177 FROM_HERE, base::Bind(&ProtocolPerfTest::OnHostConnectedMainThread, | 189 FROM_HERE, base::Bind(&ProtocolPerfTest::OnHostConnectedMainThread, |
178 base::Unretained(this))); | 190 base::Unretained(this))); |
179 } | 191 } |
180 | 192 |
181 protected: | 193 protected: |
182 void WaitConnected() { | 194 void WaitConnected() { |
183 client_connected_ = false; | 195 client_connected_ = false; |
184 host_connected_ = false; | 196 host_connected_ = false; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 base::MessageLoopForIO message_loop_; | 365 base::MessageLoopForIO message_loop_; |
354 | 366 |
355 scoped_refptr<FakeNetworkDispatcher> fake_network_dispatcher_; | 367 scoped_refptr<FakeNetworkDispatcher> fake_network_dispatcher_; |
356 | 368 |
357 base::Thread host_thread_; | 369 base::Thread host_thread_; |
358 base::Thread capture_thread_; | 370 base::Thread capture_thread_; |
359 base::Thread encode_thread_; | 371 base::Thread encode_thread_; |
360 base::Thread decode_thread_; | 372 base::Thread decode_thread_; |
361 std::unique_ptr<FakeDesktopEnvironmentFactory> desktop_environment_factory_; | 373 std::unique_ptr<FakeDesktopEnvironmentFactory> desktop_environment_factory_; |
362 | 374 |
| 375 scoped_refptr<protocol::InputEventTimestampsSource> event_timestamp_source_; |
| 376 |
363 FakeCursorShapeStub cursor_shape_stub_; | 377 FakeCursorShapeStub cursor_shape_stub_; |
364 | 378 |
365 std::unique_ptr<protocol::CandidateSessionConfig> protocol_config_; | 379 std::unique_ptr<protocol::CandidateSessionConfig> protocol_config_; |
366 | 380 |
367 std::unique_ptr<FakeSignalStrategy> host_signaling_; | 381 std::unique_ptr<FakeSignalStrategy> host_signaling_; |
368 std::unique_ptr<FakeSignalStrategy> client_signaling_; | 382 std::unique_ptr<FakeSignalStrategy> client_signaling_; |
369 | 383 |
370 std::unique_ptr<ChromotingHost> host_; | 384 std::unique_ptr<ChromotingHost> host_; |
371 std::unique_ptr<ClientContext> client_context_; | 385 std::unique_ptr<ClientContext> client_context_; |
372 std::unique_ptr<SoftwareVideoRenderer> video_renderer_; | 386 std::unique_ptr<SoftwareVideoRenderer> video_renderer_; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 NetworkPerformanceParams(100000, 30000, 130, 5, 0.00), | 443 NetworkPerformanceParams(100000, 30000, 130, 5, 0.00), |
430 NetworkPerformanceParams(100000, 200000, 130, 5, 0.00))); | 444 NetworkPerformanceParams(100000, 200000, 130, 5, 0.00))); |
431 | 445 |
432 // TotalLatency[Ice|Webrtc] tests measure video latency in the case when the | 446 // TotalLatency[Ice|Webrtc] tests measure video latency in the case when the |
433 // whole screen is updated occasionally. It's intended to simulate the case when | 447 // whole screen is updated occasionally. It's intended to simulate the case when |
434 // user actions (e.g. Alt-Tab, click on the task bar) cause whole screen to be | 448 // user actions (e.g. Alt-Tab, click on the task bar) cause whole screen to be |
435 // updated. | 449 // updated. |
436 void ProtocolPerfTest::MeasureTotalLatency(bool use_webrtc) { | 450 void ProtocolPerfTest::MeasureTotalLatency(bool use_webrtc) { |
437 scoped_refptr<test::CyclicFrameGenerator> frame_generator = | 451 scoped_refptr<test::CyclicFrameGenerator> frame_generator = |
438 test::CyclicFrameGenerator::Create(); | 452 test::CyclicFrameGenerator::Create(); |
439 frame_generator->set_draw_barcode(true); | |
440 | |
441 desktop_environment_factory_->set_frame_generator( | 453 desktop_environment_factory_->set_frame_generator( |
442 base::Bind(&test::CyclicFrameGenerator::GenerateFrame, frame_generator)); | 454 base::Bind(&test::CyclicFrameGenerator::GenerateFrame, frame_generator)); |
| 455 event_timestamp_source_ = frame_generator; |
443 | 456 |
444 StartHostAndClient(use_webrtc); | 457 StartHostAndClient(use_webrtc); |
445 ASSERT_NO_FATAL_FAILURE(WaitConnected()); | 458 ASSERT_NO_FATAL_FAILURE(WaitConnected()); |
446 | 459 |
447 int skipped_frames = 0; | 460 int total_frames = 0; |
448 while (skipped_frames < 10) { | 461 |
449 std::unique_ptr<webrtc::DesktopFrame> frame = ReceiveFrame(); | 462 const base::TimeDelta kWarmUpTime = base::TimeDelta::FromSeconds(2); |
450 test::CyclicFrameGenerator::ChangeInfoList changes = | 463 const base::TimeDelta kTestTime = base::TimeDelta::FromSeconds(5); |
451 frame_generator->GetChangeList(frame.get()); | 464 |
452 skipped_frames += changes.size(); | 465 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 466 while ((base::TimeTicks::Now() - start_time) < (kWarmUpTime + kTestTime)) { |
| 467 ReceiveFrame(); |
| 468 ++total_frames; |
453 } | 469 } |
454 | 470 |
455 base::TimeDelta total_latency_big_frames; | 471 WaitFrameStats(total_frames); |
456 int big_frame_count = 0; | |
457 base::TimeDelta total_latency_small_frames; | |
458 int small_frame_count = 0; | |
459 | 472 |
460 while (big_frame_count + small_frame_count < 30) { | 473 int warm_up_frames = 0; |
461 std::unique_ptr<webrtc::DesktopFrame> frame = ReceiveFrame(); | 474 |
462 base::TimeTicks frame_received_time = base::TimeTicks::Now(); | 475 int big_update_count = 0; |
| 476 base::TimeDelta total_latency_big_updates; |
| 477 int small_update_count = 0; |
| 478 base::TimeDelta total_latency_small_updates; |
| 479 for (int i = 0; i < total_frames; ++i) { |
| 480 const protocol::FrameStats& stats = frame_stats_[i]; |
| 481 |
| 482 // CyclicFrameGenerator::TakeLastEventTimestamps() always returns non-null |
| 483 // timestamps. |
| 484 CHECK(!stats.host_stats.latest_event_timestamp.is_null()); |
| 485 |
463 test::CyclicFrameGenerator::ChangeInfoList changes = | 486 test::CyclicFrameGenerator::ChangeInfoList changes = |
464 frame_generator->GetChangeList(frame.get()); | 487 frame_generator->GetChangeList(stats.host_stats.latest_event_timestamp); |
| 488 |
| 489 // Allow 2 seconds for the connection to warm-up, e.g. to get bandwidth |
| 490 // estimate, etc. These frames are ignored when calculating stats below. |
| 491 if (stats.client_stats.time_rendered < (start_time + kWarmUpTime)) { |
| 492 ++warm_up_frames; |
| 493 continue; |
| 494 } |
| 495 |
465 for (auto& change_info : changes) { | 496 for (auto& change_info : changes) { |
466 base::TimeDelta latency = frame_received_time - change_info.timestamp; | 497 base::TimeDelta latency = |
| 498 stats.client_stats.time_rendered - change_info.timestamp; |
467 switch (change_info.type) { | 499 switch (change_info.type) { |
468 case test::CyclicFrameGenerator::ChangeType::NO_CHANGES: | 500 case test::CyclicFrameGenerator::ChangeType::NO_CHANGES: |
469 NOTREACHED(); | 501 NOTREACHED(); |
470 break; | 502 break; |
471 case test::CyclicFrameGenerator::ChangeType::FULL: | 503 case test::CyclicFrameGenerator::ChangeType::FULL: |
472 total_latency_big_frames += latency; | 504 total_latency_big_updates += latency; |
473 ++big_frame_count; | 505 ++big_update_count; |
474 break; | 506 break; |
475 case test::CyclicFrameGenerator::ChangeType::CURSOR: | 507 case test::CyclicFrameGenerator::ChangeType::CURSOR: |
476 total_latency_small_frames += latency; | 508 total_latency_small_updates += latency; |
477 ++small_frame_count; | 509 ++small_update_count; |
478 break; | 510 break; |
479 } | 511 } |
480 } | 512 } |
481 } | 513 } |
482 | 514 |
483 CHECK(big_frame_count); | 515 CHECK(big_update_count); |
484 VLOG(0) << "Average latency for big frames: " | 516 VLOG(0) << "Average latency for big updates: " |
485 << (total_latency_big_frames / big_frame_count).InMillisecondsF(); | 517 << (total_latency_big_updates / big_update_count).InMillisecondsF(); |
486 | 518 |
487 if (small_frame_count) { | 519 if (small_update_count) { |
488 VLOG(0) | 520 VLOG(0) |
489 << "Average latency for small frames: " | 521 << "Average latency for small updates: " |
490 << (total_latency_small_frames / small_frame_count).InMillisecondsF(); | 522 << (total_latency_small_updates / small_update_count).InMillisecondsF(); |
491 } | 523 } |
492 } | 524 } |
493 | 525 |
494 TEST_P(ProtocolPerfTest, TotalLatencyIce) { | 526 TEST_P(ProtocolPerfTest, TotalLatencyIce) { |
495 MeasureTotalLatency(false); | 527 MeasureTotalLatency(false); |
496 } | 528 } |
497 | 529 |
498 TEST_P(ProtocolPerfTest, TotalLatencyWebrtc) { | 530 TEST_P(ProtocolPerfTest, TotalLatencyWebrtc) { |
499 MeasureTotalLatency(true); | 531 MeasureTotalLatency(true); |
500 } | 532 } |
501 | 533 |
502 // ScrollPerformance[Ice|Webrtc] tests simulate whole screen being scrolled | 534 // ScrollPerformance[Ice|Webrtc] tests simulate whole screen being scrolled |
503 // continuously. They measure FPS and video latency. | 535 // continuously. They measure FPS and video latency. |
504 void ProtocolPerfTest::MeasureScrollPerformance(bool use_webrtc) { | 536 void ProtocolPerfTest::MeasureScrollPerformance(bool use_webrtc) { |
505 scoped_refptr<test::ScrollFrameGenerator> frame_generator = | 537 scoped_refptr<test::ScrollFrameGenerator> frame_generator = |
506 new test::ScrollFrameGenerator(); | 538 new test::ScrollFrameGenerator(); |
507 | |
508 desktop_environment_factory_->set_frame_generator( | 539 desktop_environment_factory_->set_frame_generator( |
509 base::Bind(&test::ScrollFrameGenerator::GenerateFrame, frame_generator)); | 540 base::Bind(&test::ScrollFrameGenerator::GenerateFrame, frame_generator)); |
| 541 event_timestamp_source_ = frame_generator; |
510 | 542 |
511 StartHostAndClient(use_webrtc); | 543 StartHostAndClient(use_webrtc); |
512 ASSERT_NO_FATAL_FAILURE(WaitConnected()); | 544 ASSERT_NO_FATAL_FAILURE(WaitConnected()); |
513 | 545 |
514 int warm_up_frames = 0; | |
515 | |
516 base::TimeTicks start_time = base::TimeTicks::Now(); | |
517 const base::TimeDelta kWarmUpTime = base::TimeDelta::FromSeconds(2); | 546 const base::TimeDelta kWarmUpTime = base::TimeDelta::FromSeconds(2); |
518 while ((base::TimeTicks::Now() - start_time) < kWarmUpTime) { | |
519 ReceiveFrame(); | |
520 ++warm_up_frames; | |
521 } | |
522 | |
523 client_socket_factory_->ResetStats(); | |
524 | |
525 // Run the test for 2 seconds. | |
526 const base::TimeDelta kTestTime = base::TimeDelta::FromSeconds(2); | 547 const base::TimeDelta kTestTime = base::TimeDelta::FromSeconds(2); |
527 | 548 |
528 int num_frames = 0; | 549 int num_frames = 0; |
529 base::TimeDelta latency_sum; | 550 int warm_up_frames = 0; |
530 start_time = base::TimeTicks::Now(); | 551 base::TimeTicks start_time = base::TimeTicks::Now(); |
531 while ((base::TimeTicks::Now() - start_time) < kTestTime) { | 552 while ((base::TimeTicks::Now() - start_time) < (kTestTime + kWarmUpTime)) { |
532 std::unique_ptr<webrtc::DesktopFrame> frame = ReceiveFrame(); | 553 ReceiveFrame(); |
533 ++num_frames; | 554 ++num_frames; |
534 latency_sum += frame_generator->GetFrameLatency(*frame); | 555 |
| 556 // Allow 2 seconds for the connection to warm-up, e.g. to get bandwidth |
| 557 // estimate, etc. These frames are ignored when calculating stats below. |
| 558 if ((base::TimeTicks::Now() - start_time) < kWarmUpTime) { |
| 559 ++warm_up_frames; |
| 560 client_socket_factory_->ResetStats(); |
| 561 } |
535 } | 562 } |
536 | 563 |
537 base::TimeDelta total_time = (base::TimeTicks::Now() - start_time); | 564 base::TimeDelta total_time = (base::TimeTicks::Now() - start_time); |
538 | 565 |
539 WaitFrameStats(warm_up_frames + num_frames); | 566 WaitFrameStats(warm_up_frames + num_frames); |
540 | 567 |
541 int total_size = | 568 int total_size = |
542 std::accumulate(frame_stats_.begin() + warm_up_frames, | 569 std::accumulate(frame_stats_.begin() + warm_up_frames, |
543 frame_stats_.begin() + warm_up_frames + num_frames, 0, | 570 frame_stats_.begin() + warm_up_frames + num_frames, 0, |
544 [](int sum, const protocol::FrameStats& stats) { | 571 [](int sum, const protocol::FrameStats& stats) { |
545 return sum + stats.host_stats.frame_size; | 572 return sum + stats.host_stats.frame_size; |
546 }); | 573 }); |
547 | 574 |
| 575 base::TimeDelta latency_sum = std::accumulate( |
| 576 frame_stats_.begin() + warm_up_frames, |
| 577 frame_stats_.begin() + warm_up_frames + num_frames, base::TimeDelta(), |
| 578 [](base::TimeDelta sum, const protocol::FrameStats& stats) { |
| 579 return sum + (stats.client_stats.time_rendered - |
| 580 stats.host_stats.latest_event_timestamp); |
| 581 }); |
| 582 |
548 VLOG(0) << "FPS: " << num_frames / total_time.InSecondsF(); | 583 VLOG(0) << "FPS: " << num_frames / total_time.InSecondsF(); |
549 VLOG(0) << "Average latency: " << latency_sum.InMillisecondsF() / num_frames | 584 VLOG(0) << "Average latency: " << latency_sum.InMillisecondsF() / num_frames |
550 << " ms"; | 585 << " ms"; |
551 VLOG(0) << "Total size: " << total_size << " bytes"; | 586 VLOG(0) << "Total size: " << total_size << " bytes"; |
552 VLOG(0) << "Bandwidth utilization: " | 587 VLOG(0) << "Bandwidth utilization: " |
553 << 100 * total_size / (total_time.InSecondsF() * GetParam().bandwidth) | 588 << 100 * total_size / (total_time.InSecondsF() * GetParam().bandwidth) |
554 << "%"; | 589 << "%"; |
555 VLOG(0) << "Network buffer delay (bufferbloat), average: " | 590 VLOG(0) << "Network buffer delay (bufferbloat), average: " |
556 << client_socket_factory_->average_buffer_delay().InMilliseconds() | 591 << client_socket_factory_->average_buffer_delay().InMilliseconds() |
557 << " ms, max:" | 592 << " ms, max:" |
558 << client_socket_factory_->max_buffer_delay().InMilliseconds() | 593 << client_socket_factory_->max_buffer_delay().InMilliseconds() |
559 << " ms"; | 594 << " ms"; |
560 VLOG(0) << "Packet drop rate: " << client_socket_factory_->drop_rate(); | 595 VLOG(0) << "Packet drop rate: " << client_socket_factory_->drop_rate(); |
561 } | 596 } |
562 | 597 |
563 TEST_P(ProtocolPerfTest, ScrollPerformanceIce) { | 598 TEST_P(ProtocolPerfTest, ScrollPerformanceIce) { |
564 MeasureScrollPerformance(false); | 599 MeasureScrollPerformance(false); |
565 } | 600 } |
566 | 601 |
567 TEST_P(ProtocolPerfTest, ScrollPerformanceWebrtc) { | 602 TEST_P(ProtocolPerfTest, ScrollPerformanceWebrtc) { |
568 MeasureScrollPerformance(true); | 603 MeasureScrollPerformance(true); |
569 } | 604 } |
570 | 605 |
571 } // namespace remoting | 606 } // namespace remoting |
OLD | NEW |