-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
timeseriesUtils.ts
92 lines (74 loc) · 2.9 KB
/
timeseriesUtils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
import { cockroach } from "@cockroachlabs/crdb-protobuf-client";
import { AlignedData } from "uplot";
import { longToInt, TimestampToNumber } from "../util";
type statementStatisticsPerAggregatedTs = cockroach.server.serverpb.StatementDetailsResponse.ICollectedStatementGroupedByAggregatedTs;
export function generateExecuteAndPlanningTimeseries(
stats: statementStatisticsPerAggregatedTs[],
): AlignedData {
const ts: Array<number> = [];
const execution: Array<number> = [];
const planning: Array<number> = [];
stats.forEach(function(stat: statementStatisticsPerAggregatedTs) {
ts.push(TimestampToNumber(stat.aggregated_ts) * 1e3);
execution.push(stat.stats.run_lat.mean * 1e9);
planning.push(stat.stats.plan_lat.mean * 1e9);
});
return [ts, execution, planning];
}
export function generateRowsProcessedTimeseries(
stats: statementStatisticsPerAggregatedTs[],
): AlignedData {
const ts: Array<number> = [];
const read: Array<number> = [];
const written: Array<number> = [];
stats.forEach(function(stat: statementStatisticsPerAggregatedTs) {
ts.push(TimestampToNumber(stat.aggregated_ts) * 1e3);
read.push(stat.stats.rows_read.mean);
written.push(stat.stats.rows_written?.mean * 1e3);
});
return [ts, read, written];
}
export function generateExecRetriesTimeseries(
stats: statementStatisticsPerAggregatedTs[],
): AlignedData {
const ts: Array<number> = [];
const retries: Array<number> = [];
stats.forEach(function(stat: statementStatisticsPerAggregatedTs) {
ts.push(TimestampToNumber(stat.aggregated_ts) * 1e3);
const totalCountBarChart = longToInt(stat.stats.count);
const firstAttemptsBarChart = longToInt(stat.stats.first_attempt_count);
retries.push(totalCountBarChart - firstAttemptsBarChart);
});
return [ts, retries];
}
export function generateExecCountTimeseries(
stats: statementStatisticsPerAggregatedTs[],
): AlignedData {
const ts: Array<number> = [];
const count: Array<number> = [];
stats.forEach(function(stat: statementStatisticsPerAggregatedTs) {
ts.push(TimestampToNumber(stat.aggregated_ts) * 1e3);
count.push(longToInt(stat.stats.count));
});
return [ts, count];
}
export function generateContentionTimeseries(
stats: statementStatisticsPerAggregatedTs[],
): AlignedData {
const ts: Array<number> = [];
const count: Array<number> = [];
stats.forEach(function(stat: statementStatisticsPerAggregatedTs) {
ts.push(TimestampToNumber(stat.aggregated_ts) * 1e3);
count.push(stat.stats.exec_stats.contention_time.mean);
});
return [ts, count];
}