sample-compare.html 5.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->
<!doctype html>
<html>
	<head>
23 24 25
		<meta charset='utf-8'>
		<title>Downsample Comparasions</title>
		<meta name='viewport' content='width=device-width, initial-scale=1'>
26 27
	</head>
	<body>
P
pissang 已提交
28 29 30 31 32 33 34 35
		<style>
			.chart {
				width: 800px;
				height: 400px;
			}
		</style>
		<h2 id='status'>Loading lib....</h2>
		<div id='container'></div>
36

37 38
        <script src='lib/esl.js'></script>
        <script src='lib/config.js'></script>
39 40 41 42 43
		<script>
            require([
                'echarts'
                // 'echarts/chart/sankey',
                // 'echarts/component/tooltip'
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
            ], function (echarts) {
					function round2(val) {
						return Math.round(val * 100) / 100;
					}

					function round3(val) {
						return Math.round(val * 1000) / 1000;
					}

					function prepData(packed) {
						console.time('prep');

						// epoch,idl,recv,send,read,writ,used,free

						var numFields = packed[0];
						packed = packed.slice(numFields + 1);

P
pissang 已提交
61
						var repeatTimes = 5;
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

						var data = new Float64Array((packed.length / numFields) * 4 * repeatTimes);

						var off = 0;
						var date = packed[0];
						for (let repeat = 0; repeat < repeatTimes; repeat++) {
							for (let i = 0, j = 0; i < packed.length; i += numFields, j++) {
								date += 1;
								data[off++] = date * 60 * 1000;
								data[off++] = round3(100 - packed[i + 1]);
								data[off++] = round2(
									(100 * packed[i + 5]) / (packed[i + 5] + packed[i + 6])
								);
								data[off++] = packed[i + 3];
							}
						}
						console.timeEnd('prep');

						return data;
					}

P
pissang 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
					function makeChart(data, title, sampling) {
						var container = document.getElementById('container');
						var dom = document.createElement('div');
						var titleDom = document.createElement('h3');
						dom.classList.add('chart');
						if (title !== 'warmup') {
							container.appendChild(titleDom);
							container.appendChild(dom);
						}
						var myChart = echarts.init(dom, null, {
							width: 800,
							height: 400
						});

						titleDom.innerHTML = title;
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

						let opts = {
							animation: false,
							dataset: {
								source: data,
								dimensions: ['date', 'cpu', 'ram', 'tcpout']
							},
							tooltip: {
								trigger: 'axis'
							},
							legend: {},
							grid: {
								containLabel: true,
								left: 0,
								top: 50,
								right: 0,
								bottom: 30
							},
							xAxis: {
								type: 'time'
							},
							yAxis: [{
								type: 'value',
								max: 100,
								axisLabel: {
									formatter: '{value} %'
								}
							}, {
								type: 'value',
								max: 100,
								axisLabel: {
									formatter: '{value} MB'
								}
							}],
							series: [{
								name: 'CPU',
								type: 'line',
								showSymbol: false,
P
pissang 已提交
136
								sampling: sampling,
137 138 139 140 141 142 143 144 145 146 147
								lineStyle: { width: 1 },
								emphasis: { lineStyle: { width: 1 } },
								encode: {
									x: 'date',
									y: 'cpu'
								}
							}, {
								name: 'RAM',
								type: 'line',
								yAxisIndex: 1,
								showSymbol: false,
P
pissang 已提交
148
								sampling: sampling,
149 150 151 152 153 154 155 156 157 158 159
								lineStyle: { width: 1 },
								emphasis: { lineStyle: { width: 1 } },
								encode: {
									x: 'date',
									y: 'ram'
								}
							}, {
								name: 'TCP Out',
								type: 'line',
								yAxisIndex: 1,
								showSymbol: false,
P
pissang 已提交
160
								sampling: sampling,
161 162 163 164 165 166 167 168 169
								lineStyle: { width: 1 },
								emphasis: { lineStyle: { width: 1 } },
								encode: {
									x: 'date',
									y: 'tcpout'
								}
							}]
						};
						const startTime = performance.now();
P
pissang 已提交
170 171 172
						myChart.setOption(opts, {
							notMerge: true
						});
173
						const endTime = performance.now();
P
pissang 已提交
174
						titleDom.innerHTML = `${title}(${data.length / 4 * 3}) ${(endTime - startTime).toFixed(0)} ms`;
175
					}
P
pissang 已提交
176 177
					let status = document.getElementById('status');
					status.textContent = 'Fetching data.json (2.07MB)....';
178 179 180 181

					fetch('data/large-data.json')
						.then(r => r.json())
						.then(packed => {
P
pissang 已提交
182
							status.textContent = 'Warming up';
183
							let data = prepData(packed);
P
pissang 已提交
184 185 186 187 188 189

							setTimeout(function () {
								for (let i = 0; i < 5; i++) {
									makeChart(data, 'warmup');
									makeChart(data, 'warmup', 'lttb');
									makeChart(data, 'warmup', 'average');
P
pissang 已提交
190
									makeChart(data, 'warmup', 'max');
P
pissang 已提交
191 192 193 194
								}
								status.textContent = 'Running';
								setTimeout(() => makeChart(data, 'No Sampling', null), 500);
								setTimeout(() => makeChart(data, 'LTTB Sampling', 'lttb'), 1000);
P
pissang 已提交
195
								setTimeout(() => makeChart(data, 'Max Sampling', 'max'), 1500);
P
pissang 已提交
196 197
								setTimeout(() => makeChart(data, 'Average Sampling', 'average'), 1500);
							});
198
						});
199 200 201 202
      });
		</script>
	</body>
</html>