diff options
Diffstat (limited to 'scripts/lib/build_perf/html/measurement_chart.html')
-rw-r--r-- | scripts/lib/build_perf/html/measurement_chart.html | 214 |
1 files changed, 166 insertions, 48 deletions
diff --git a/scripts/lib/build_perf/html/measurement_chart.html b/scripts/lib/build_perf/html/measurement_chart.html index 65f1a227ad..86435273cf 100644 --- a/scripts/lib/build_perf/html/measurement_chart.html +++ b/scripts/lib/build_perf/html/measurement_chart.html | |||
@@ -1,50 +1,168 @@ | |||
1 | <script type="text/javascript"> | 1 | <script type="module"> |
2 | chartsDrawing += 1; | 2 | // Get raw data |
3 | google.charts.setOnLoadCallback(drawChart_{{ chart_elem_id }}); | 3 | const rawData = [ |
4 | function drawChart_{{ chart_elem_id }}() { | 4 | {% for sample in measurement.samples %} |
5 | var data = new google.visualization.DataTable(); | 5 | [{{ sample.commit_num }}, {{ sample.mean.gv_value() }}, {{ sample.start_time }}, '{{sample.commit}}'], |
6 | 6 | {% endfor %} | |
7 | // Chart options | 7 | ]; |
8 | var options = { | 8 | |
9 | theme : 'material', | 9 | const convertToMinute = (time) => { |
10 | legend: 'none', | 10 | return time[0]*60 + time[1] + time[2]/60 + time[3]/3600; |
11 | hAxis: { format: '', title: 'Commit number', | 11 | } |
12 | minValue: {{ chart_opts.haxis.min }}, | 12 | |
13 | maxValue: {{ chart_opts.haxis.max }} }, | 13 | // Update value format to either minutes or leave as size value |
14 | {% if measurement.type == 'time' %} | 14 | const updateValue = (value) => { |
15 | vAxis: { format: 'h:mm:ss' }, | 15 | // Assuming the array values are duration in the format [hours, minutes, seconds, milliseconds] |
16 | {% else %} | 16 | return Array.isArray(value) ? convertToMinute(value) : value |
17 | vAxis: { format: '' }, | 17 | } |
18 | {% endif %} | 18 | |
19 | pointSize: 5, | 19 | // Convert raw data to the format: [time, value] |
20 | chartArea: { left: 80, right: 15 }, | 20 | const data = rawData.map(([commit, value, time]) => { |
21 | }; | 21 | return [ |
22 | 22 | // The Date object takes values in milliseconds rather than seconds. So to use a Unix timestamp we have to multiply it by 1000. | |
23 | // Define data columns | 23 | new Date(time * 1000).getTime(), |
24 | data.addColumn('number', 'Commit'); | 24 | // Assuming the array values are duration in the format [hours, minutes, seconds, milliseconds] |
25 | data.addColumn('{{ measurement.value_type.gv_data_type }}', | 25 | updateValue(value) |
26 | '{{ measurement.value_type.quantity }}'); | 26 | ] |
27 | // Add data rows | 27 | }); |
28 | data.addRows([ | 28 | |
29 | {% for sample in measurement.samples %} | 29 | const commitCountList = rawData.map(([commit, value, time]) => { |
30 | [{{ sample.commit_num }}, {{ sample.mean.gv_value() }}], | 30 | return commit |
31 | {% endfor %} | 31 | }); |
32 | ]); | 32 | |
33 | 33 | const commitCountData = rawData.map(([commit, value, time]) => { | |
34 | // Finally, draw the chart | 34 | return updateValue(value) |
35 | chart_div = document.getElementById('{{ chart_elem_id }}'); | 35 | }); |
36 | var chart = new google.visualization.LineChart(chart_div); | 36 | |
37 | google.visualization.events.addListener(chart, 'ready', function () { | 37 | // Set chart options |
38 | //chart_div = document.getElementById('{{ chart_elem_id }}'); | 38 | const option_start_time = { |
39 | //chart_div.innerHTML = '<img src="' + chart.getImageURI() + '">'; | 39 | tooltip: { |
40 | png_div = document.getElementById('{{ chart_elem_id }}_png'); | 40 | trigger: 'axis', |
41 | png_div.outerHTML = '<a id="{{ chart_elem_id }}_png" href="' + chart.getImageURI() + '">PNG</a>'; | 41 | enterable: true, |
42 | console.log("CHART READY: {{ chart_elem_id }}"); | 42 | position: function (point, params, dom, rect, size) { |
43 | chartsDrawing -= 1; | 43 | return [point[0], '0%']; |
44 | if (chartsDrawing == 0) | 44 | }, |
45 | console.log("ALL CHARTS READY"); | 45 | formatter: function (param) { |
46 | const value = param[0].value[1] | ||
47 | const sample = rawData.filter(([commit, dataValue]) => updateValue(dataValue) === value) | ||
48 | const formattedDate = new Date(sample[0][2] * 1000).toString().replace(/GMT[+-]\d{4}/, '').replace(/\(.*\)/, '(CEST)'); | ||
49 | |||
50 | // Add commit hash to the tooltip as a link | ||
51 | const commitLink = `https://git.yoctoproject.org/poky/commit/?id=${sample[0][3]}` | ||
52 | if ('{{ measurement.value_type.quantity }}' == 'time') { | ||
53 | const hours = Math.floor(value/60) | ||
54 | const minutes = Math.floor(value % 60) | ||
55 | const seconds = Math.floor((value * 60) % 60) | ||
56 | return `<strong>Duration:</strong> ${hours}:${minutes}:${seconds}, <strong>Commit number:</strong> <a href="${commitLink}" target="_blank" rel="noreferrer noopener">${sample[0][0]}</a>, <br/> <strong>Start time:</strong> ${formattedDate}` | ||
57 | } | ||
58 | return `<strong>Size:</strong> ${value.toFixed(2)} MB, <strong>Commit number:</strong> <a href="${commitLink}" target="_blank" rel="noreferrer noopener">${sample[0][0]}</a>, <br/> <strong>Start time:</strong> ${formattedDate}` | ||
59 | ;} | ||
60 | }, | ||
61 | xAxis: { | ||
62 | type: 'time', | ||
63 | }, | ||
64 | yAxis: { | ||
65 | name: '{{ measurement.value_type.quantity }}' == 'time' ? 'Duration in minutes' : 'Disk size in MB', | ||
66 | type: 'value', | ||
67 | min: function(value) { | ||
68 | return Math.round(value.min - 0.5); | ||
69 | }, | ||
70 | max: function(value) { | ||
71 | return Math.round(value.max + 0.5); | ||
72 | } | ||
73 | }, | ||
74 | dataZoom: [ | ||
75 | { | ||
76 | type: 'slider', | ||
77 | xAxisIndex: 0, | ||
78 | filterMode: 'none' | ||
79 | }, | ||
80 | ], | ||
81 | series: [ | ||
82 | { | ||
83 | name: '{{ measurement.value_type.quantity }}', | ||
84 | type: 'line', | ||
85 | symbol: 'none', | ||
86 | data: data | ||
87 | } | ||
88 | ] | ||
89 | }; | ||
90 | |||
91 | const option_commit_count = { | ||
92 | tooltip: { | ||
93 | trigger: 'axis', | ||
94 | enterable: true, | ||
95 | position: function (point, params, dom, rect, size) { | ||
96 | return [point[0], '0%']; | ||
97 | }, | ||
98 | formatter: function (param) { | ||
99 | const value = param[0].value | ||
100 | const sample = rawData.filter(([commit, dataValue]) => updateValue(dataValue) === value) | ||
101 | const formattedDate = new Date(sample[0][2] * 1000).toString().replace(/GMT[+-]\d{4}/, '').replace(/\(.*\)/, '(CEST)'); | ||
102 | // Add commit hash to the tooltip as a link | ||
103 | const commitLink = `https://git.yoctoproject.org/poky/commit/?id=${sample[0][3]}` | ||
104 | if ('{{ measurement.value_type.quantity }}' == 'time') { | ||
105 | const hours = Math.floor(value/60) | ||
106 | const minutes = Math.floor(value % 60) | ||
107 | const seconds = Math.floor((value * 60) % 60) | ||
108 | return `<strong>Duration:</strong> ${hours}:${minutes}:${seconds}, <strong>Commit number:</strong> <a href="${commitLink}" target="_blank" rel="noreferrer noopener">${sample[0][0]}</a>, <br/> <strong>Start time:</strong> ${formattedDate}` | ||
109 | } | ||
110 | return `<strong>Size:</strong> ${value.toFixed(2)} MB, <strong>Commit number:</strong> <a href="${commitLink}" target="_blank" rel="noreferrer noopener">${sample[0][0]}</a>, <br/> <strong>Start time:</strong> ${formattedDate}` | ||
111 | ;} | ||
112 | }, | ||
113 | xAxis: { | ||
114 | name: 'Commit count', | ||
115 | type: 'category', | ||
116 | data: commitCountList | ||
117 | }, | ||
118 | yAxis: { | ||
119 | name: '{{ measurement.value_type.quantity }}' == 'time' ? 'Duration in minutes' : 'Disk size in MB', | ||
120 | type: 'value', | ||
121 | min: function(value) { | ||
122 | return Math.round(value.min - 0.5); | ||
123 | }, | ||
124 | max: function(value) { | ||
125 | return Math.round(value.max + 0.5); | ||
126 | } | ||
127 | }, | ||
128 | dataZoom: [ | ||
129 | { | ||
130 | type: 'slider', | ||
131 | xAxisIndex: 0, | ||
132 | filterMode: 'none' | ||
133 | }, | ||
134 | ], | ||
135 | series: [ | ||
136 | { | ||
137 | name: '{{ measurement.value_type.quantity }}', | ||
138 | type: 'line', | ||
139 | symbol: 'none', | ||
140 | data: commitCountData | ||
141 | } | ||
142 | ] | ||
143 | }; | ||
144 | |||
145 | // Draw chart | ||
146 | const draw_chart = (chart_id, option) => { | ||
147 | let chart_name | ||
148 | const chart_div = document.getElementById(chart_id); | ||
149 | // Set dark mode | ||
150 | if (window.matchMedia('(prefers-color-scheme: dark)').matches) { | ||
151 | chart_name= echarts.init(chart_div, 'dark', { | ||
152 | height: 320 | ||
153 | }); | ||
154 | } else { | ||
155 | chart_name= echarts.init(chart_div, null, { | ||
156 | height: 320 | ||
157 | }); | ||
158 | } | ||
159 | // Change chart size with browser resize | ||
160 | window.addEventListener('resize', function() { | ||
161 | chart_name.resize(); | ||
46 | }); | 162 | }); |
47 | chart.draw(data, options); | 163 | return chart_name.setOption(option); |
48 | } | 164 | } |
49 | </script> | ||
50 | 165 | ||
166 | draw_chart('{{ chart_elem_start_time_id }}', option_start_time) | ||
167 | draw_chart('{{ chart_elem_commit_count_id }}', option_commit_count) | ||
168 | </script> | ||