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

Side by Side Diff: webrtc/tools/event_log_visualizer/plot_python.cc

Issue 2179223003: Convenience functions to set axis properties in visualization tool. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Change literal type to avoid VC++ compile warning Created 4 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 | « webrtc/tools/event_log_visualizer/plot_python.h ('k') | webrtc/tools/tools.gyp » ('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 (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 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 "webrtc/tools/event_log_visualizer/plot_python.h" 11 #include "webrtc/tools/event_log_visualizer/plot_python.h"
12 12
13 #include <stdio.h> 13 #include <stdio.h>
14
14 #include <memory> 15 #include <memory>
15 16
16 namespace webrtc { 17 namespace webrtc {
17 namespace plotting { 18 namespace plotting {
18 19
19 PythonPlot::PythonPlot() {} 20 PythonPlot::PythonPlot() {}
20 21
21 PythonPlot::~PythonPlot() {} 22 PythonPlot::~PythonPlot() {}
22 23
23 void PythonPlot::draw() { 24 void PythonPlot::Draw() {
24 // Write python commands to stdout. Intended program usage is 25 // Write python commands to stdout. Intended program usage is
25 // ./event_log_visualizer event_log160330.dump | python 26 // ./event_log_visualizer event_log160330.dump | python
26 27
27 if (!series.empty()) { 28 if (!series_list_.empty()) {
28 printf("color_count = %zu\n", series.size()); 29 printf("color_count = %zu\n", series_list_.size());
29 printf( 30 printf(
30 "hls_colors = [(i*1.0/color_count, 0.25+i*0.5/color_count, 0.8) for i " 31 "hls_colors = [(i*1.0/color_count, 0.25+i*0.5/color_count, 0.8) for i "
31 "in range(color_count)]\n"); 32 "in range(color_count)]\n");
32 printf("rgb_colors = [colorsys.hls_to_rgb(*hls) for hls in hls_colors]\n"); 33 printf("rgb_colors = [colorsys.hls_to_rgb(*hls) for hls in hls_colors]\n");
33 34
34 for (size_t i = 0; i < series.size(); i++) { 35 for (size_t i = 0; i < series_list_.size(); i++) {
35 // List x coordinates 36 // List x coordinates
36 printf("x%zu = [", i); 37 printf("x%zu = [", i);
37 if (series[i].points.size() > 0) 38 if (series_list_[i].points.size() > 0)
38 printf("%G", series[i].points[0].x); 39 printf("%G", series_list_[i].points[0].x);
39 for (size_t j = 1; j < series[i].points.size(); j++) 40 for (size_t j = 1; j < series_list_[i].points.size(); j++)
40 printf(", %G", series[i].points[j].x); 41 printf(", %G", series_list_[i].points[j].x);
41 printf("]\n"); 42 printf("]\n");
42 43
43 // List y coordinates 44 // List y coordinates
44 printf("y%zu = [", i); 45 printf("y%zu = [", i);
45 if (series[i].points.size() > 0) 46 if (series_list_[i].points.size() > 0)
46 printf("%G", series[i].points[0].y); 47 printf("%G", series_list_[i].points[0].y);
47 for (size_t j = 1; j < series[i].points.size(); j++) 48 for (size_t j = 1; j < series_list_[i].points.size(); j++)
48 printf(", %G", series[i].points[j].y); 49 printf(", %G", series_list_[i].points[j].y);
49 printf("]\n"); 50 printf("]\n");
50 51
51 if (series[i].style == BAR_GRAPH) { 52 if (series_list_[i].style == BAR_GRAPH) {
52 // There is a plt.bar function that draws bar plots, 53 // There is a plt.bar function that draws bar plots,
53 // but it is *way* too slow to be useful. 54 // but it is *way* too slow to be useful.
54 printf( 55 printf(
55 "plt.vlines(x%zu, map(lambda t: min(t,0), y%zu), map(lambda t: " 56 "plt.vlines(x%zu, map(lambda t: min(t,0), y%zu), map(lambda t: "
56 "max(t,0), y%zu), color=rgb_colors[%zu], " 57 "max(t,0), y%zu), color=rgb_colors[%zu], "
57 "label=\'%s\')\n", 58 "label=\'%s\')\n",
58 i, i, i, i, series[i].label.c_str()); 59 i, i, i, i, series_list_[i].label.c_str());
59 } else if (series[i].style == LINE_GRAPH) { 60 } else if (series_list_[i].style == LINE_GRAPH) {
60 printf("plt.plot(x%zu, y%zu, color=rgb_colors[%zu], label=\'%s\')\n", i, 61 printf("plt.plot(x%zu, y%zu, color=rgb_colors[%zu], label=\'%s\')\n", i,
61 i, i, series[i].label.c_str()); 62 i, i, series_list_[i].label.c_str());
62 } else if (series[i].style == LINE_DOT_GRAPH) { 63 } else if (series_list_[i].style == LINE_DOT_GRAPH) {
63 printf( 64 printf(
64 "plt.plot(x%zu, y%zu, color=rgb_colors[%zu], label=\'%s\', " 65 "plt.plot(x%zu, y%zu, color=rgb_colors[%zu], label=\'%s\', "
65 "marker='.')\n", 66 "marker='.')\n",
66 i, i, i, series[i].label.c_str()); 67 i, i, i, series_list_[i].label.c_str());
67 } else { 68 } else {
68 printf("raise Exception(\"Unknown graph type\")\n"); 69 printf("raise Exception(\"Unknown graph type\")\n");
69 } 70 }
70 } 71 }
71 } 72 }
72 73
73 printf("plt.xlim(%f, %f)\n", xaxis_min, xaxis_max); 74 printf("plt.xlim(%f, %f)\n", xaxis_min_, xaxis_max_);
74 printf("plt.ylim(%f, %f)\n", yaxis_min, yaxis_max); 75 printf("plt.ylim(%f, %f)\n", yaxis_min_, yaxis_max_);
75 printf("plt.xlabel(\'%s\')\n", xaxis_label.c_str()); 76 printf("plt.xlabel(\'%s\')\n", xaxis_label_.c_str());
76 printf("plt.ylabel(\'%s\')\n", yaxis_label.c_str()); 77 printf("plt.ylabel(\'%s\')\n", yaxis_label_.c_str());
77 printf("plt.title(\'%s\')\n", title.c_str()); 78 printf("plt.title(\'%s\')\n", title_.c_str());
78 if (!series.empty()) { 79 if (!series_list_.empty()) {
79 printf("plt.legend(loc=\'best\', fontsize=\'small\')\n"); 80 printf("plt.legend(loc=\'best\', fontsize=\'small\')\n");
80 } 81 }
81 } 82 }
82 83
83 PythonPlotCollection::PythonPlotCollection() {} 84 PythonPlotCollection::PythonPlotCollection() {}
84 85
85 PythonPlotCollection::~PythonPlotCollection() {} 86 PythonPlotCollection::~PythonPlotCollection() {}
86 87
87 void PythonPlotCollection::draw() { 88 void PythonPlotCollection::Draw() {
88 printf("import matplotlib.pyplot as plt\n"); 89 printf("import matplotlib.pyplot as plt\n");
89 printf("import colorsys\n"); 90 printf("import colorsys\n");
90 for (size_t i = 0; i < plots.size(); i++) { 91 for (size_t i = 0; i < plots_.size(); i++) {
91 printf("plt.figure(%zu)\n", i); 92 printf("plt.figure(%zu)\n", i);
92 plots[i]->draw(); 93 plots_[i]->Draw();
93 } 94 }
94 printf("plt.show()\n"); 95 printf("plt.show()\n");
95 } 96 }
96 97
97 Plot* PythonPlotCollection::append_new_plot() { 98 Plot* PythonPlotCollection::AppendNewPlot() {
98 Plot* plot = new PythonPlot(); 99 Plot* plot = new PythonPlot();
99 plots.push_back(std::unique_ptr<Plot>(plot)); 100 plots_.push_back(std::unique_ptr<Plot>(plot));
100 return plot; 101 return plot;
101 } 102 }
102 103
103 } // namespace plotting 104 } // namespace plotting
104 } // namespace webrtc 105 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/tools/event_log_visualizer/plot_python.h ('k') | webrtc/tools/tools.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698