Reland of Trace the stats report as JSON instead of each stat separately. (patchset #1 id:1 of https://codereview.webrtc.org/3001683002/ )

Reason for revert:
Fixed

Original issue's description:
> Revert of Trace the stats report as JSON instead of each stat separately. (patchset #3 id:100001 of https://codereview.webrtc.org/2986453002/ )
>
> Reason for revert:
> It breaks a downstream project.
>
> Original issue's description:
> > Trace the stats report as JSON instead of each stat separately.
> >
> > Trace the whole report as a string instead of each field on it's own. And test that the traces collected are valid.
> >
> > R=tommi@webrtc.org, hbos@webrtc.org
> > BUG=chromium:653087
> >
> > Review-Url: https://codereview.webrtc.org/2986453002
> > Cr-Commit-Position: refs/heads/master@{#19341}
> > Committed: 80c65780e6
>
> TBR=hbos@webrtc.org,tommi@webrtc.org,ehmaldonado@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=chromium:653087
>
> Review-Url: https://codereview.webrtc.org/3001683002
> Cr-Commit-Position: refs/heads/master@{#19344}
> Committed: 3439c89358

BUG=chromium:653087

Review-Url: https://codereview.webrtc.org/3000943002
Cr-Commit-Position: refs/heads/master@{#19673}
This commit is contained in:
ehmaldonado
2017-09-04 14:35:04 -07:00
committed by Commit Bot
parent 3eac8002db
commit 8ab0fd80ad
2 changed files with 54 additions and 35 deletions

View File

@ -24,6 +24,7 @@
#include "webrtc/rtc_base/gunit.h"
#include "webrtc/rtc_base/refcountedobject.h"
#include "webrtc/rtc_base/scoped_ref_ptr.h"
#include "webrtc/rtc_base/trace_event.h"
#include "webrtc/rtc_base/virtualsocketserver.h"
namespace webrtc {
@ -33,27 +34,61 @@ namespace {
const int64_t kGetStatsTimeoutMs = 10000;
const unsigned char* GetCategoryEnabledHandler(const char* name) {
return reinterpret_cast<const unsigned char*>("webrtc_stats");
if (strcmp("webrtc_stats", name) != 0) {
return reinterpret_cast<const unsigned char*>("");
}
return reinterpret_cast<const unsigned char*>(name);
}
void AddTraceEventHandler(char phase,
const unsigned char* category_enabled,
const char* name,
unsigned long long id,
int num_args,
const char** arg_names,
const unsigned char* arg_types,
const unsigned long long* arg_values,
unsigned char flags) {
// Do nothing
}
class RTCStatsReportTraceListener {
public:
static void SetUp() {
if (!traced_report_)
traced_report_ = new RTCStatsReportTraceListener();
traced_report_->last_trace_ = "";
SetupEventTracer(&GetCategoryEnabledHandler,
&RTCStatsReportTraceListener::AddTraceEventHandler);
}
static const std::string& last_trace() {
RTC_DCHECK(traced_report_);
return traced_report_->last_trace_;
}
private:
static void AddTraceEventHandler(char phase,
const unsigned char* category_enabled,
const char* name,
unsigned long long id,
int num_args,
const char** arg_names,
const unsigned char* arg_types,
const unsigned long long* arg_values,
unsigned char flags) {
RTC_DCHECK(traced_report_);
EXPECT_STREQ("webrtc_stats",
reinterpret_cast<const char*>(category_enabled));
EXPECT_STREQ("webrtc_stats", name);
EXPECT_EQ(1, num_args);
EXPECT_STREQ("report", arg_names[0]);
EXPECT_EQ(TRACE_VALUE_TYPE_COPY_STRING, arg_types[0]);
traced_report_->last_trace_ = reinterpret_cast<const char*>(arg_values[0]);
}
static RTCStatsReportTraceListener* traced_report_;
std::string last_trace_;
};
RTCStatsReportTraceListener* RTCStatsReportTraceListener::traced_report_ =
nullptr;
class RTCStatsIntegrationTest : public testing::Test {
public:
RTCStatsIntegrationTest()
: network_thread_(new rtc::Thread(&virtual_socket_server_)),
worker_thread_(rtc::Thread::Create()) {
SetupEventTracer(&GetCategoryEnabledHandler, &AddTraceEventHandler);
RTCStatsReportTraceListener::SetUp();
RTC_CHECK(network_thread_->Start());
RTC_CHECK(worker_thread_->Start());
@ -662,6 +697,7 @@ TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) {
rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller();
RTCStatsReportVerifier(report.get()).VerifyReport();
EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace());
}
TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) {
@ -669,6 +705,7 @@ TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) {
rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee();
RTCStatsReportVerifier(report.get()).VerifyReport();
EXPECT_EQ(report->ToJson(), RTCStatsReportTraceListener::last_trace());
}
TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) {
@ -682,6 +719,8 @@ TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) {
// Any pending stats requests should have completed in the act of destroying
// the peer connection.
EXPECT_TRUE(stats_obtainer->report());
EXPECT_EQ(stats_obtainer->report()->ToJson(),
RTCStatsReportTraceListener::last_trace());
}
#endif // HAVE_SCTP

View File

@ -32,18 +32,6 @@ namespace webrtc {
namespace {
const int kStatTypeMemberNameAndIdMaxLen = 1024;
std::string GetStatTypeMemberNameAndId(const RTCStats& stats,
const RTCStatsMemberInterface* member) {
RTC_DCHECK(strlen(stats.type()) + strlen(member->name())
+ stats.id().size() + 3 < kStatTypeMemberNameAndIdMaxLen);
char buffer[kStatTypeMemberNameAndIdMaxLen];
rtc::sprintfn(&buffer[0], sizeof(buffer), "%s.%s.%s", stats.type(),
member->name(), stats.id().c_str());
return buffer;
}
std::string RTCCertificateIDFromFingerprint(const std::string& fingerprint) {
return "RTCCertificate_" + fingerprint;
}
@ -778,16 +766,8 @@ void RTCStatsCollector::AddPartialResults_s(
// Trace WebRTC Stats when getStats is called on Javascript.
// This allows access to WebRTC stats from trace logs. To enable them,
// select the "webrtc_stats" category when recording traces.
for (const RTCStats& stats : *cached_report_) {
for (const RTCStatsMemberInterface* member : stats.Members()) {
if (member->is_defined()) {
TRACE_EVENT_INSTANT2("webrtc_stats", "webrtc_stats",
"value", member->ValueToString(),
"type.name.id", GetStatTypeMemberNameAndId(
stats, member));
}
}
}
TRACE_EVENT_INSTANT1("webrtc_stats", "webrtc_stats", "report",
cached_report_->ToJson());
DeliverCachedReport();
}
}