-
Notifications
You must be signed in to change notification settings - Fork 974
Expand file tree
/
Copy pathprofiler_results_scuba.py
More file actions
110 lines (90 loc) · 3.85 KB
/
profiler_results_scuba.py
File metadata and controls
110 lines (90 loc) · 3.85 KB
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
import getpass
import hashlib
import uuid
from typing import Dict, List, Optional
from executorch.exir.schema import FrameList
from executorch.exir.serialize import deserialize_from_flatbuffer
from executorch.profiler.parse_profiler_results import (
frame_list_normal_vector_short,
frame_list_short_repr,
get_frame_list,
ProfileEvent,
)
from libfb.py.fburl import FBUrlError, get_fburl, resolve_fburl
from libfb.py.scuba_url import ScubaDrillstate, ScubaURL
from rfe.scubadata.scubadata_py3 import Sample, ScubaData
def generate_scuba_fburl(scuba_url):
scuba_url = str(scuba_url)
key = hashlib.md5(scuba_url.encode()).hexdigest()[:20]
try:
fb_url = "https://fburl.com/{}".format(key)
resolve_fburl(fb_url)
return fb_url
except FBUrlError:
return get_fburl(scuba_url, string_key=key)
def upload_to_scuba(profile_data: Dict[str, List[ProfileEvent]], model_path: str):
scuba_table = "executorch_profile"
scuba_data = ScubaData(scuba_table)
run_id = str(uuid.uuid4())
program = None
model_bytes = None
if model_path is not None:
with open(model_path, "rb") as model_file:
model_bytes = model_file.read()
program = deserialize_from_flatbuffer(model_bytes)
def frame_list_normal_vector(frame_list: FrameList) -> Optional[List[str]]:
if frame_list is None:
return None
return [
f'File "{frame.filename}", line {frame.lineno}, in {frame.name}\n{frame.context}\n'
for frame in frame_list.items
]
execution_plan_idx = 0
samples = []
for _, profile_data_list in profile_data.items():
for d in profile_data_list:
sample = Sample()
sample.setTimeColumnNow()
sample.addNormalValue("run_id", run_id)
sample.addNormalValue("unixname", getpass.getuser())
sample.addNormalValue("profile_event_name", d.name)
sample.addIntValue("execution_plan_idx", execution_plan_idx)
sample.addIntValue("chain_idx", d.chain_idx)
sample.addIntValue("instruction_idx", d.instruction_idx)
sample.addFloatValue("duration", d.duration[0])
if model_bytes is not None:
sample.addNormalValue("model_file_path", model_path)
sample.addIntValue("model_file_size_bytes", len(model_bytes))
frame_list = get_frame_list(
program, execution_plan_idx, d.chain_idx, d.instruction_idx
)
stacktrace = frame_list_normal_vector(frame_list)
stacktrace_short = frame_list_normal_vector_short(frame_list)
sample.addNormVectorValue("model_stacktrace", stacktrace)
sample.addNormVectorValue("model_stacktrace_short", stacktrace_short)
sample.addNormalValue("model_frame", frame_list_short_repr(frame_list))
samples.append(sample)
start_time = samples[0].time() - 1
end_time = samples[-1].time() + 1
try:
print(f"Uploading to scuba with run_id: {run_id}")
scuba_data.add_samples(samples)
drillstate = (
ScubaDrillstate()
.setStartTime(str(start_time))
.setEndTime(str(end_time))
.setGroupBy(["profile_event_name"])
.setAggregationField("sum")
.setMetric("sum")
.setLimit("20")
.setOrderColumn("duration")
.setOrderDesc(True)
.addEqConstraint("run_id", run_id)
.addMatchRegexConstraint("profile_event_name", "^native_call.*")
)
scuba_url = generate_scuba_fburl(ScubaURL(scuba_table, drillstate, view="Pie"))
print(f"Successfully uploaded to scuba: {scuba_url}")
print("It may take up to 5 minutes to see it in scuba")
except Exception as e:
print(f"Error logging result to Scuba table: {e}")
raise