-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
94 lines (84 loc) · 1.83 KB
/
example.js
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
/**
* Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
*
* This product includes software developed at Datadog (https://www.datadoghq.com/ Copyright 2022 Datadog, Inc.
*/
import {
Function,
Label,
Line,
Location,
Mapping,
Profile,
Sample,
ValueType,
StringTable
} from 'pprof-format'
const stringTable = new StringTable()
const periodType = new ValueType({
type: stringTable.dedup('cpu'),
unit: stringTable.dedup('nanoseconds')
})
const fun = new Function({
id: 1,
name: stringTable.dedup('name'),
systemName: stringTable.dedup('system name'),
filename: stringTable.dedup('filename'),
startLine: 123
})
const mapping = new Mapping({
id: 1
})
const location = new Location({
id: 1,
mappingId: mapping.id,
address: 123,
line: [
new Line({
functionId: fun.id,
line: 1234
})
]
})
const profile = new Profile({
sampleType: [
new ValueType({
type: stringTable.dedup('sample'),
unit: stringTable.dedup('count')
}),
periodType
],
sample: [
new Sample({
locationId: [location.id],
value: [123, 456],
label: [
new Label({
key: stringTable.dedup('label key'),
str: stringTable.dedup('label str')
}),
new Label({
key: stringTable.dedup('label key'),
num: 12345,
numUnit: stringTable.dedup('label num unit')
})
]
})
],
mapping: [mapping],
location: [location],
function: [fun],
stringTable,
timeNanos: BigInt(Date.now()) * 1_000_000n,
durationNanos: 1234,
periodType,
period: 1234 / 2,
comment: [
stringTable.dedup('some comment')
]
})
// Encode to Uint8Array
console.log(profile.encode())
// Decode from Uint8Array
const copied = Profile.decode(profile.encode())
console.log(copied)