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

Side by Side Diff: webrtc/pc/rtcstats_integrationtest.cc

Issue 2986453002: Trace the stats report as JSON instead of each stat separately. (Closed)
Patch Set: Nits. Created 3 years, 4 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 | « no previous file | webrtc/pc/rtcstatscollector.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 * Copyright 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <set> 11 #include <set>
12 #include <vector> 12 #include <vector>
13 13
14 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h" 14 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h"
15 #include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h" 15 #include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h"
16 #include "webrtc/api/datachannelinterface.h" 16 #include "webrtc/api/datachannelinterface.h"
17 #include "webrtc/api/peerconnectioninterface.h" 17 #include "webrtc/api/peerconnectioninterface.h"
18 #include "webrtc/api/stats/rtcstats_objects.h" 18 #include "webrtc/api/stats/rtcstats_objects.h"
19 #include "webrtc/api/stats/rtcstatsreport.h" 19 #include "webrtc/api/stats/rtcstatsreport.h"
20 #include "webrtc/pc/test/peerconnectiontestwrapper.h" 20 #include "webrtc/pc/test/peerconnectiontestwrapper.h"
21 #include "webrtc/pc/test/rtcstatsobtainer.h" 21 #include "webrtc/pc/test/rtcstatsobtainer.h"
22 #include "webrtc/rtc_base/checks.h" 22 #include "webrtc/rtc_base/checks.h"
23 #include "webrtc/rtc_base/event_tracer.h" 23 #include "webrtc/rtc_base/event_tracer.h"
24 #include "webrtc/rtc_base/gunit.h" 24 #include "webrtc/rtc_base/gunit.h"
25 #include "webrtc/rtc_base/refcountedobject.h" 25 #include "webrtc/rtc_base/refcountedobject.h"
26 #include "webrtc/rtc_base/scoped_ref_ptr.h" 26 #include "webrtc/rtc_base/scoped_ref_ptr.h"
27 #include "webrtc/rtc_base/trace_event.h"
27 #include "webrtc/rtc_base/virtualsocketserver.h" 28 #include "webrtc/rtc_base/virtualsocketserver.h"
28 29
29 namespace webrtc { 30 namespace webrtc {
30 31
31 namespace { 32 namespace {
32 33
33 const int64_t kGetStatsTimeoutMs = 10000; 34 const int64_t kGetStatsTimeoutMs = 10000;
34 35
35 const unsigned char* GetCategoryEnabledHandler(const char* name) { 36 const unsigned char* GetCategoryEnabledHandler(const char* name) {
36 return reinterpret_cast<const unsigned char*>("webrtc_stats"); 37 if (strcmp("webrtc_stats", name) != 0) {
38 return reinterpret_cast<const unsigned char*>("");
39 }
40 return reinterpret_cast<const unsigned char*>(name);
37 } 41 }
38 42
39 void AddTraceEventHandler(char phase, 43 class RTCStatsReportTraceListener {
40 const unsigned char* category_enabled, 44 public:
41 const char* name, 45 static void SetUp() {
42 unsigned long long id, 46 if (!traced_report_)
43 int num_args, 47 traced_report_ = new RTCStatsReportTraceListener();
44 const char** arg_names, 48 traced_report_->last_trace_ = "";
45 const unsigned char* arg_types, 49 SetupEventTracer(&GetCategoryEnabledHandler,
46 const unsigned long long* arg_values, 50 &RTCStatsReportTraceListener::AddTraceEventHandler);
47 unsigned char flags) { 51 }
48 // Do nothing 52
49 } 53 static const std::string& last_trace() {
54 RTC_DCHECK(traced_report_);
55 return traced_report_->last_trace_;
56 }
57
58 private:
59 static void AddTraceEventHandler(char phase,
60 const unsigned char* category_enabled,
61 const char* name,
62 unsigned long long id,
63 int num_args,
64 const char** arg_names,
65 const unsigned char* arg_types,
66 const unsigned long long* arg_values,
67 unsigned char flags) {
68 RTC_DCHECK(traced_report_);
69 EXPECT_EQ(traced_report_->last_trace_, "");
70 EXPECT_STREQ("webrtc_stats",
71 reinterpret_cast<const char*>(category_enabled));
72 EXPECT_STREQ("webrtc_stats", name);
73 EXPECT_EQ(1, num_args);
74 EXPECT_STREQ("report", arg_names[0]);
75 EXPECT_EQ(TRACE_VALUE_TYPE_COPY_STRING, arg_types[0]);
76
77 traced_report_->last_trace_ = reinterpret_cast<const char*>(arg_values[0]);
78 }
79
80 static RTCStatsReportTraceListener* traced_report_;
81 std::string last_trace_;
82 };
83
84 RTCStatsReportTraceListener* RTCStatsReportTraceListener::traced_report_ =
85 nullptr;
50 86
51 class RTCStatsIntegrationTest : public testing::Test { 87 class RTCStatsIntegrationTest : public testing::Test {
52 public: 88 public:
53 RTCStatsIntegrationTest() 89 RTCStatsIntegrationTest()
54 : network_thread_(new rtc::Thread(&virtual_socket_server_)), 90 : network_thread_(new rtc::Thread(&virtual_socket_server_)),
55 worker_thread_(rtc::Thread::Create()) { 91 worker_thread_(rtc::Thread::Create()) {
56 SetupEventTracer(&GetCategoryEnabledHandler, &AddTraceEventHandler); 92 RTCStatsReportTraceListener::SetUp();
57 93
58 RTC_CHECK(network_thread_->Start()); 94 RTC_CHECK(network_thread_->Start());
59 RTC_CHECK(worker_thread_->Start()); 95 RTC_CHECK(worker_thread_->Start());
60 96
61 caller_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( 97 caller_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>(
62 "caller", network_thread_.get(), worker_thread_.get()); 98 "caller", network_thread_.get(), worker_thread_.get());
63 callee_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( 99 callee_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>(
64 "callee", network_thread_.get(), worker_thread_.get()); 100 "callee", network_thread_.get(), worker_thread_.get());
65 } 101 }
66 102
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 private: 679 private:
644 rtc::scoped_refptr<const RTCStatsReport> report_; 680 rtc::scoped_refptr<const RTCStatsReport> report_;
645 }; 681 };
646 682
647 #ifdef HAVE_SCTP 683 #ifdef HAVE_SCTP
648 TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) { 684 TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) {
649 StartCall(); 685 StartCall();
650 686
651 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller(); 687 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller();
652 RTCStatsReportVerifier(report.get()).VerifyReport(); 688 RTCStatsReportVerifier(report.get()).VerifyReport();
689 EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace());
653 } 690 }
654 691
655 TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) { 692 TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) {
656 StartCall(); 693 StartCall();
657 694
658 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee(); 695 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee();
659 RTCStatsReportVerifier(report.get()).VerifyReport(); 696 RTCStatsReportVerifier(report.get()).VerifyReport();
697 EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace());
660 } 698 }
661 699
662 TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) { 700 TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) {
663 StartCall(); 701 StartCall();
664 702
665 rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer = 703 rtc::scoped_refptr<RTCStatsObtainer> stats_obtainer =
666 RTCStatsObtainer::Create(); 704 RTCStatsObtainer::Create();
667 caller_->pc()->GetStats(stats_obtainer); 705 caller_->pc()->GetStats(stats_obtainer);
668 // This will destroy the peer connection. 706 // This will destroy the peer connection.
669 caller_ = nullptr; 707 caller_ = nullptr;
670 // Any pending stats requests should have completed in the act of destroying 708 // Any pending stats requests should have completed in the act of destroying
671 // the peer connection. 709 // the peer connection.
672 EXPECT_TRUE(stats_obtainer->report()); 710 EXPECT_TRUE(stats_obtainer->report());
711 EXPECT_EQ(stats_obtainer->report()->ToJson(),
712 RTCStatsReportTraceListener::last_trace());
673 } 713 }
674 #endif // HAVE_SCTP 714 #endif // HAVE_SCTP
675 715
676 } // namespace 716 } // namespace
677 717
678 } // namespace webrtc 718 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/pc/rtcstatscollector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698