From b246a292cd3dad8f6d4fb8521bcd115c794c15c9 Mon Sep 17 00:00:00 2001 From: terelius Date: Tue, 23 Aug 2016 18:15:25 -0700 Subject: [PATCH] Define a protobuf format for representing plots. Add code to convert the C-representation generated by the RtcEventLog analysis tool, to the new protobuf format. BUG=webrtc:6249 NOTRY=True Review-Url: https://codereview.webrtc.org/2268063002 Cr-Commit-Position: refs/heads/master@{#13873} --- webrtc/tools/BUILD.gn | 11 +++ webrtc/tools/event_log_visualizer/graph.proto | 32 ++++++++ .../event_log_visualizer/plot_protobuf.cc | 81 +++++++++++++++++++ .../event_log_visualizer/plot_protobuf.h | 39 +++++++++ webrtc/tools/tools.gyp | 22 ++++- 5 files changed, 182 insertions(+), 3 deletions(-) create mode 100644 webrtc/tools/event_log_visualizer/graph.proto create mode 100644 webrtc/tools/event_log_visualizer/plot_protobuf.cc create mode 100644 webrtc/tools/event_log_visualizer/plot_protobuf.h diff --git a/webrtc/tools/BUILD.gn b/webrtc/tools/BUILD.gn index 91564b9890..d551483008 100644 --- a/webrtc/tools/BUILD.gn +++ b/webrtc/tools/BUILD.gn @@ -7,6 +7,7 @@ # be found in the AUTHORS file in the root of the source tree. import("//testing/test.gni") +import("//third_party/protobuf/proto_library.gni") import("../build/webrtc.gni") source_set("tools") { @@ -175,12 +176,21 @@ source_set("agc_test_utils") { } if (rtc_enable_protobuf) { + proto_library("graph_proto") { + sources = [ + "event_log_visualizer/graph.proto", + ] + proto_out_dir = "webrtc/tools/event_log_visualizer" + } + source_set("event_log_visualizer_utils") { sources = [ "event_log_visualizer/analyzer.cc", "event_log_visualizer/analyzer.h", "event_log_visualizer/plot_base.cc", "event_log_visualizer/plot_base.h", + "event_log_visualizer/plot_protobuf.cc", + "event_log_visualizer/plot_protobuf.h", "event_log_visualizer/plot_python.cc", "event_log_visualizer/plot_python.h", ] @@ -201,6 +211,7 @@ if (rtc_enable_protobuf) { "//build/config/sanitizers:deps", ] public_deps = [ + ":graph_proto", "../:rtc_event_log_parser", ] } diff --git a/webrtc/tools/event_log_visualizer/graph.proto b/webrtc/tools/event_log_visualizer/graph.proto new file mode 100644 index 0000000000..3b02848913 --- /dev/null +++ b/webrtc/tools/event_log_visualizer/graph.proto @@ -0,0 +1,32 @@ +syntax = "proto2"; +option optimize_for = LITE_RUNTIME; +package webrtc.protobuf_plot; + +enum PlotStyle { + UNDEFINED = 0; + LINE_GRAPH = 1; + LINE_DOT_GRAPH = 2; + BAR_GRAPH = 3; +}; + +message DataSet { + repeated float xvalues = 1; + repeated float yvalues = 2; + optional string label = 3; + optional PlotStyle style = 4; +} + +message Plot { + repeated DataSet data_sets = 1; + optional float xaxis_min = 2; + optional float xaxis_max = 3; + optional string xaxis_label = 4; + optional float yaxis_min = 5; + optional float yaxis_max = 6; + optional string yaxis_label = 7; + optional string title = 8; +} + +message PlotCollection { + repeated Plot plots = 1; +} \ No newline at end of file diff --git a/webrtc/tools/event_log_visualizer/plot_protobuf.cc b/webrtc/tools/event_log_visualizer/plot_protobuf.cc new file mode 100644 index 0000000000..7f032c11b8 --- /dev/null +++ b/webrtc/tools/event_log_visualizer/plot_protobuf.cc @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "webrtc/tools/event_log_visualizer/plot_protobuf.h" + +#include + +namespace webrtc { +namespace plotting { + +ProtobufPlot::ProtobufPlot() {} + +ProtobufPlot::~ProtobufPlot() {} + +void ProtobufPlot::Draw() {} + +void ProtobufPlot::ExportProtobuf(protobuf_plot::Plot* plot) { + for (size_t i = 0; i < series_list_.size(); i++) { + protobuf_plot::DataSet* data_set = plot->add_data_sets(); + for (const auto& point : series_list_[i].points) { + data_set->add_xvalues(point.x); + } + for (const auto& point : series_list_[i].points) { + data_set->add_yvalues(point.y); + } + + if (series_list_[i].style == BAR_GRAPH) { + data_set->set_style(protobuf_plot::BAR_GRAPH); + } else if (series_list_[i].style == LINE_GRAPH) { + data_set->set_style(protobuf_plot::LINE_GRAPH); + } else if (series_list_[i].style == LINE_DOT_GRAPH) { + data_set->set_style(protobuf_plot::LINE_DOT_GRAPH); + } else { + data_set->set_style(protobuf_plot::UNDEFINED); + } + + data_set->set_label(series_list_[i].label); + } + + plot->set_xaxis_min(xaxis_min_); + plot->set_xaxis_max(xaxis_max_); + plot->set_yaxis_min(yaxis_min_); + plot->set_yaxis_max(yaxis_max_); + plot->set_xaxis_label(xaxis_label_); + plot->set_yaxis_label(yaxis_label_); + plot->set_title(title_); +} + +ProtobufPlotCollection::ProtobufPlotCollection() {} + +ProtobufPlotCollection::~ProtobufPlotCollection() {} + +void ProtobufPlotCollection::Draw() {} + +void ProtobufPlotCollection::ExportProtobuf( + protobuf_plot::PlotCollection* collection) { + for (const auto& plot : plots_) { + // TODO(terelius): Ensure that there is no way to insert plots other than + // ProtobufPlots in a ProtobufPlotCollection. Needed to safely static_cast + // here. + protobuf_plot::Plot* protobuf_representation = collection->add_plots(); + static_cast(plot.get()) + ->ExportProtobuf(protobuf_representation); + } +} + +Plot* ProtobufPlotCollection::AppendNewPlot() { + Plot* plot = new ProtobufPlot(); + plots_.push_back(std::unique_ptr(plot)); + return plot; +} + +} // namespace plotting +} // namespace webrtc diff --git a/webrtc/tools/event_log_visualizer/plot_protobuf.h b/webrtc/tools/event_log_visualizer/plot_protobuf.h new file mode 100644 index 0000000000..1ea525b20a --- /dev/null +++ b/webrtc/tools/event_log_visualizer/plot_protobuf.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#ifndef WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_PROTOBUF_H_ +#define WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_PROTOBUF_H_ + +#include "webrtc/tools/event_log_visualizer/graph.pb.h" +#include "webrtc/tools/event_log_visualizer/plot_base.h" + +namespace webrtc { +namespace plotting { + +class ProtobufPlot final : public Plot { + public: + ProtobufPlot(); + ~ProtobufPlot() override; + void Draw() override; + void ExportProtobuf(protobuf_plot::Plot* plot); +}; + +class ProtobufPlotCollection final : public PlotCollection { + public: + ProtobufPlotCollection(); + ~ProtobufPlotCollection() override; + void Draw() override; + Plot* AppendNewPlot() override; + void ExportProtobuf(protobuf_plot::PlotCollection* collection); +}; + +} // namespace plotting +} // namespace webrtc + +#endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_PLOT_PROTOBUF_H_ diff --git a/webrtc/tools/tools.gyp b/webrtc/tools/tools.gyp index cd83b52732..6ffc93ba68 100644 --- a/webrtc/tools/tools.gyp +++ b/webrtc/tools/tools.gyp @@ -101,6 +101,18 @@ 'conditions': [ ['enable_protobuf==1', { 'targets': [ + { + 'target_name': 'graph_proto', + 'type': 'static_library', + 'sources': [ + 'event_log_visualizer/graph.proto', + ], + 'variables': { + 'proto_in_dir': 'event_log_visualizer', + 'proto_out_dir': 'webrtc/tools/event_log_visualizer', + }, + 'includes': ['../build/protoc.gypi'], + }, { # RTC event log visualization library 'target_name': 'event_log_visualizer_utils', @@ -111,18 +123,22 @@ '<(webrtc_root)/modules/modules.gyp:congestion_controller', '<(webrtc_root)/modules/modules.gyp:rtp_rtcp', '<(webrtc_root)/system_wrappers/system_wrappers.gyp:metrics_default', + ':graph_proto', ], 'sources': [ 'event_log_visualizer/analyzer.cc', 'event_log_visualizer/analyzer.h', 'event_log_visualizer/plot_base.cc', 'event_log_visualizer/plot_base.h', + 'event_log_visualizer/plot_protobuf.cc', + 'event_log_visualizer/plot_protobuf.h', 'event_log_visualizer/plot_python.cc', 'event_log_visualizer/plot_python.h', ], - 'export_dependent_settings': [ - '<(webrtc_root)/webrtc.gyp:rtc_event_log_parser', - ], + 'export_dependent_settings': [ + '<(webrtc_root)/webrtc.gyp:rtc_event_log_parser', + ':graph_proto', + ], }, ], }],