-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathutils.ts
97 lines (87 loc) · 2.98 KB
/
utils.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
93
94
95
96
97
import type {TMemoryStats} from '../../types/api/nodes';
import {isNumeric} from '../../utils/utils';
import i18n from './i18n';
export function calculateAllocatedMemory(stats: TMemoryStats) {
const allocatedMemory = getMaybeNumber(stats.AllocatedMemory) || 0;
const allocatorCaches = getMaybeNumber(stats.AllocatorCachesMemory) || 0;
return String(allocatedMemory + allocatorCaches);
}
export function getMaybeNumber(value: string | number | undefined): number | undefined {
return isNumeric(value) ? parseFloat(String(value)) : undefined;
}
interface MemorySegment {
label: string;
key: string;
value: number;
capacity?: number;
isInfo?: boolean;
}
export function getMemorySegments(stats: TMemoryStats, memoryUsage: number): MemorySegment[] {
const segments = [
{
label: i18n('text_shared-cache'),
key: 'SharedCacheConsumption',
value: getMaybeNumber(stats.SharedCacheConsumption),
capacity: getMaybeNumber(stats.SharedCacheLimit),
isInfo: false,
},
{
label: i18n('text_query-execution'),
key: 'QueryExecutionConsumption',
value: getMaybeNumber(stats.QueryExecutionConsumption),
capacity: getMaybeNumber(stats.QueryExecutionLimit),
isInfo: false,
},
{
label: i18n('text_memtable'),
key: 'MemTableConsumption',
value: getMaybeNumber(stats.MemTableConsumption),
capacity: getMaybeNumber(stats.MemTableLimit),
isInfo: false,
},
{
label: i18n('text_allocator-caches'),
key: 'AllocatorCachesMemory',
value: getMaybeNumber(stats.AllocatorCachesMemory),
isInfo: false,
},
];
const nonInfoSegments = segments.filter(
(segment) => segment.value !== undefined,
) as MemorySegment[];
const sumNonInfoSegments = nonInfoSegments.reduce((acc, segment) => acc + segment.value, 0);
const otherMemory = Math.max(0, memoryUsage - sumNonInfoSegments);
segments.push({
label: i18n('text_other'),
key: 'Other',
value: otherMemory,
isInfo: false,
});
segments.push(
{
label: i18n('text_external-consumption'),
key: 'ExternalConsumption',
value: getMaybeNumber(stats.ExternalConsumption),
isInfo: true,
},
{
label: i18n('text_usage'),
key: 'Usage',
value: memoryUsage,
isInfo: true,
},
{
label: i18n('text_soft-limit'),
key: 'SoftLimit',
value: getMaybeNumber(stats.SoftLimit),
isInfo: true,
},
{
label: i18n('text_hard-limit'),
key: 'HardLimit',
value: getMaybeNumber(stats.HardLimit),
isInfo: true,
},
);
return segments.filter((segment) => segment.value !== undefined) as MemorySegment[];
}