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
93
94
95
96
97
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
// Copyright Epic Games, Inc. All Rights Reserved.
"use strict";
import { ZenPage } from "./page.js"
import { Fetcher } from "../util/fetcher.js"
import { Friendly } from "../util/friendly.js"
import { PropTable, Toolbar } from "../util/widgets.js"
////////////////////////////////////////////////////////////////////////////////
class TemporalStat
{
constructor(data, as_bytes)
{
this._data = data;
this._as_bytes = as_bytes;
}
toString()
{
const columns = [
/* count */ {},
/* rate */ {},
/* t */ {}, {},
];
const data = this._data;
for (var key in data)
{
var out = columns[0];
if (key.startsWith("rate_")) out = columns[1];
else if (key.startsWith("t_p")) out = columns[3];
else if (key.startsWith("t_")) out = columns[2];
out[key] = data[key];
}
var friendly = this._as_bytes ? Friendly.kib : Friendly.sep;
var content = "";
for (var i = 0; i < columns.length; ++i)
{
content += "<pre>";
const column = columns[i];
for (var key in column)
{
var value = column[key];
if (i)
{
value = Friendly.sep(value, 2);
key = key.padStart(9);
content += key + ": " + value;
}
else
content += friendly(value);
content += "\n";
}
content += "</pre>";
}
return content;
}
}
////////////////////////////////////////////////////////////////////////////////
export class Page extends ZenPage
{
async main()
{
const provider = this.get_param("provider", "z$");
var stats = new Fetcher()
.resource("stats", provider)
.param("cidstorestats", "true")
.param("cachestorestats", "true")
.json();
this.set_title("stat - " + provider);
const section = this.add_section(provider);
var toolbar = section.add_widget(Toolbar);
var tb_right = toolbar.right();
tb_right.add("filter:");
tb_right.add("-none-").on_click((x) => this.update_filter(""));
for (var preset of ["read.", "write.", ".request", ".bytes"])
tb_right.add(preset).on_click((x) => this.update_filter(x), preset);
this._filter_input = tb_right.add("", "label").tag("input");
this._filter_input.on("change", (x) => this.update_filter(x.inner().value), this._filter_input);
this._table = section.add_widget(PropTable);
this._stats = stats = await stats;
this._condense(stats);
var first = undefined;
for (var name in stats)
{
first = first || name;
toolbar.left().add(name).on_click((x) => this.view_category(x), name);
}
var filter = this.get_param("filter");
first = this.get_param("view", first);
this.view_category(first);
if (filter)
this.update_filter(filter);
}
view_category(name)
{
const friendly = (this.get_param("raw") == undefined);
this._table.clear();
this._table.add_object(this._stats[name], friendly, 3);
this.set_param("view", name);
this.update_filter("");
}
update_filter(needle)
{
this._filter_input.attr("value", needle);
this.set_param("filter", needle);
if (!needle)
return this._table.filter();
var needles = needle.split(" ");
this._table.filter(...needles);
}
_condense(stats)
{
const impl = function(node)
{
for (var name in node)
{
const candidate = node[name];
if (!(candidate instanceof Object))
continue;
if (candidate["rate_mean"] != undefined)
{
const as_bytes = (name.indexOf("bytes") >= 0);
node[name] = new TemporalStat(candidate, as_bytes);
continue;
}
impl(candidate);
}
}
for (var name in stats)
impl(stats[name]);
}
}
|