viztracer 1.1.0__cp314-cp314-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of viztracer might be problematic. Click here for more details.
- viztracer/__init__.py +19 -0
- viztracer/__main__.py +8 -0
- viztracer/attach.py +67 -0
- viztracer/attach_process/LICENSE +203 -0
- viztracer/attach_process/__init__.py +0 -0
- viztracer/attach_process/add_code_to_python_process.py +582 -0
- viztracer/attach_process/attach_x86.dll +0 -0
- viztracer/attach_process/inject_dll_amd64.exe +0 -0
- viztracer/attach_process/linux_and_mac/lldb_prepare.py +54 -0
- viztracer/attach_process/run_code_on_dllmain_amd64.dll +0 -0
- viztracer/attach_process/run_code_on_dllmain_x86.dll +0 -0
- viztracer/cellmagic.py +70 -0
- viztracer/code_monkey.py +353 -0
- viztracer/decorator.py +164 -0
- viztracer/event_base.py +81 -0
- viztracer/functree.py +135 -0
- viztracer/html/flamegraph.html +34 -0
- viztracer/html/trace_viewer_embedder.html +203 -0
- viztracer/html/trace_viewer_full.html +10207 -0
- viztracer/main.py +699 -0
- viztracer/modules/eventnode.c +172 -0
- viztracer/modules/eventnode.h +73 -0
- viztracer/modules/pythoncapi_compat.h +1726 -0
- viztracer/modules/quicktime.c +177 -0
- viztracer/modules/quicktime.h +104 -0
- viztracer/modules/snaptrace.c +2205 -0
- viztracer/modules/snaptrace.h +134 -0
- viztracer/modules/snaptrace_member.c +483 -0
- viztracer/modules/util.c +45 -0
- viztracer/modules/util.h +22 -0
- viztracer/modules/vcompressor/vc_dump.c +1131 -0
- viztracer/modules/vcompressor/vc_dump.h +49 -0
- viztracer/modules/vcompressor/vcompressor.c +396 -0
- viztracer/modules/vcompressor/vcompressor.h +15 -0
- viztracer/patch.py +307 -0
- viztracer/report_builder.py +311 -0
- viztracer/snaptrace.cp314-win_amd64.pyd +0 -0
- viztracer/snaptrace.pyi +77 -0
- viztracer/util.py +196 -0
- viztracer/vcompressor.cp314-win_amd64.pyd +0 -0
- viztracer/vcompressor.pyi +10 -0
- viztracer/viewer.py +528 -0
- viztracer/vizcounter.py +20 -0
- viztracer/vizevent.py +31 -0
- viztracer/vizlogging.py +20 -0
- viztracer/vizobject.py +28 -0
- viztracer/vizplugin.py +143 -0
- viztracer/viztracer.py +472 -0
- viztracer/web_dist/LICENSE +189 -0
- viztracer/web_dist/index.html +127 -0
- viztracer/web_dist/service_worker.js +279 -0
- viztracer/web_dist/trace_processor +300 -0
- viztracer/web_dist/v52.0-6b9586def/assets/MaterialSymbolsOutlined.woff2 +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/Roboto-100.woff2 +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/Roboto-300.woff2 +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/Roboto-400.woff2 +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/Roboto-500.woff2 +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/RobotoCondensed-Light.woff2 +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/RobotoCondensed-Regular.woff2 +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/RobotoMono-Regular.woff2 +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/brand.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/catapult_trace_viewer.html +3946 -0
- viztracer/web_dist/v52.0-6b9586def/assets/catapult_trace_viewer.js +7539 -0
- viztracer/web_dist/v52.0-6b9586def/assets/favicon.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/logo-128.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/logo-3d.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_atrace.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_battery_counters.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_board_voltage.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_cpu_coarse.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_cpu_fine.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_cpu_freq.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_cpu_voltage.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_frame_timeline.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_ftrace.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_gpu_mem_total.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_java_heap_dump.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_lmk.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_logcat.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_long_trace.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_mem_hifreq.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_meminfo.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_native_heap_profiler.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_one_shot.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_profiling.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_ps_stats.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_ring_buf.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_syscalls.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/rec_vmstat.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/scheduling_latency.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/assets/vscode-icon.png +0 -0
- viztracer/web_dist/v52.0-6b9586def/engine_bundle.js +3 -0
- viztracer/web_dist/v52.0-6b9586def/frontend_bundle.js +5495 -0
- viztracer/web_dist/v52.0-6b9586def/index.html +127 -0
- viztracer/web_dist/v52.0-6b9586def/manifest.json +52 -0
- viztracer/web_dist/v52.0-6b9586def/perfetto.css +5737 -0
- viztracer/web_dist/v52.0-6b9586def/stdlib_docs.json +1 -0
- viztracer/web_dist/v52.0-6b9586def/trace_config_utils.wasm +0 -0
- viztracer/web_dist/v52.0-6b9586def/trace_processor.wasm +0 -0
- viztracer/web_dist/v52.0-6b9586def/trace_processor_memory64.wasm +0 -0
- viztracer/web_dist/v52.0-6b9586def/traceconv.wasm +0 -0
- viztracer/web_dist/v52.0-6b9586def/traceconv_bundle.js +2 -0
- viztracer-1.1.0.dist-info/METADATA +316 -0
- viztracer-1.1.0.dist-info/RECORD +109 -0
- viztracer-1.1.0.dist-info/WHEEL +5 -0
- viztracer-1.1.0.dist-info/entry_points.txt +3 -0
- viztracer-1.1.0.dist-info/licenses/LICENSE +222 -0
- viztracer-1.1.0.dist-info/licenses/NOTICE.txt +27 -0
- viztracer-1.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#ifndef __VC_DUMP_H__
|
|
2
|
+
#define __VC_DUMP_H__
|
|
3
|
+
|
|
4
|
+
#include <Python.h>
|
|
5
|
+
|
|
6
|
+
#define VC_HEADER_RESERVED 0x00
|
|
7
|
+
#define VC_HEADER_FEE 0x01
|
|
8
|
+
#define VC_HEADER_PROCESS_NAME 0x02
|
|
9
|
+
#define VC_HEADER_THREAD_NAME 0x03
|
|
10
|
+
#define VC_HEADER_COUNTER_EVENTS 0x04
|
|
11
|
+
#define VC_HEADER_OTHER_EVENTS 0x05
|
|
12
|
+
#define VC_HEADER_FILE_INFO 0x11
|
|
13
|
+
#define VC_HEADER_COUNTER_ARG_UNKNOWN 0x21
|
|
14
|
+
#define VC_HEADER_COUNTER_ARG_SAME 0x22
|
|
15
|
+
#define VC_HEADER_COUNTER_ARG_LONG 0x23
|
|
16
|
+
#define VC_HEADER_COUNTER_ARG_FLOAT 0x24
|
|
17
|
+
#define VC_HEADER_COUNTER_ARG_LONG_STRING 0x25
|
|
18
|
+
|
|
19
|
+
#define TS_6_BIT 0x00
|
|
20
|
+
#define TS_14_BIT 0x01
|
|
21
|
+
#define TS_30_BIT 0x02
|
|
22
|
+
#define TS_62_BIT 0x03
|
|
23
|
+
|
|
24
|
+
PyObject* decompress_bytes(PyObject* bytes_data);
|
|
25
|
+
PyObject* compress_bytes(PyObject* bytes_data);
|
|
26
|
+
PyObject* json_loads_from_bytes(PyObject* bytes_data);
|
|
27
|
+
PyObject* json_dumps_to_bytes(PyObject* json_data);
|
|
28
|
+
PyObject* json_loads_and_decompress_from_file(FILE* fptr);
|
|
29
|
+
int json_dumps_and_compress_to_file(PyObject* json_data, FILE* fptr);
|
|
30
|
+
|
|
31
|
+
int dump_metadata(FILE* fptr);
|
|
32
|
+
|
|
33
|
+
int dump_parsed_trace_events(PyObject* trace_events, FILE* fptr);
|
|
34
|
+
|
|
35
|
+
int dump_file_info(PyObject* file_info, FILE* fptr);
|
|
36
|
+
|
|
37
|
+
int diff_and_write_counter_args(PyObject* counter_args, FILE* fptr);
|
|
38
|
+
|
|
39
|
+
int write_fee_events(PyObject* fee_key, PyObject* fee_value, FILE* fptr);
|
|
40
|
+
|
|
41
|
+
PyObject* load_events_from_file(FILE* fptr);
|
|
42
|
+
|
|
43
|
+
PyObject* load_file_info(FILE* fptr);
|
|
44
|
+
|
|
45
|
+
PyObject* load_counter_event(FILE* fptr);
|
|
46
|
+
|
|
47
|
+
PyObject * load_fee_events(FILE* fptr);
|
|
48
|
+
|
|
49
|
+
#endif
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
// Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
|
|
2
|
+
// For details: https://github.com/gaogaotiantian/viztracer/blob/master/NOTICE.txt
|
|
3
|
+
|
|
4
|
+
#include <Python.h>
|
|
5
|
+
#include "vcompressor.h"
|
|
6
|
+
#include "vc_dump.h"
|
|
7
|
+
|
|
8
|
+
PyObject* json_module = NULL;
|
|
9
|
+
PyObject* zlib_module = NULL;
|
|
10
|
+
|
|
11
|
+
static PyObject*
|
|
12
|
+
vcompressor_new(PyTypeObject* type, PyObject* args, PyObject* kwargs)
|
|
13
|
+
{
|
|
14
|
+
PyObject* self = PyType_GenericNew(type, args, kwargs);
|
|
15
|
+
return (PyObject*)self;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static void
|
|
19
|
+
vcompressor_dealloc(VcompressorObject* self)
|
|
20
|
+
{
|
|
21
|
+
Py_TYPE(self)->tp_free((PyObject*) self);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static PyObject*
|
|
25
|
+
parse_trace_events(PyObject* trace_events)
|
|
26
|
+
{
|
|
27
|
+
PyObject* parsed_events = NULL;
|
|
28
|
+
PyObject* fee_events = NULL;
|
|
29
|
+
PyObject* counter_events = NULL;
|
|
30
|
+
PyObject* other_events = NULL;
|
|
31
|
+
PyObject* process_names = NULL;
|
|
32
|
+
PyObject* thread_names = NULL;
|
|
33
|
+
PyObject* key = NULL;
|
|
34
|
+
|
|
35
|
+
if (!PyList_CheckExact(trace_events)) {
|
|
36
|
+
return NULL;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Initialize the event holder
|
|
40
|
+
parsed_events = PyDict_New();
|
|
41
|
+
fee_events = PyDict_New();
|
|
42
|
+
counter_events = PyDict_New();
|
|
43
|
+
process_names = PyDict_New();
|
|
44
|
+
thread_names = PyDict_New();
|
|
45
|
+
other_events = PyList_New(0);
|
|
46
|
+
PyDict_SetItemString(parsed_events, "fee_events", fee_events);
|
|
47
|
+
PyDict_SetItemString(parsed_events, "process_names", process_names);
|
|
48
|
+
PyDict_SetItemString(parsed_events, "thread_names", thread_names);
|
|
49
|
+
PyDict_SetItemString(parsed_events, "counter_events", counter_events);
|
|
50
|
+
PyDict_SetItemString(parsed_events, "other_events", other_events);
|
|
51
|
+
Py_DECREF(fee_events);
|
|
52
|
+
Py_DECREF(process_names);
|
|
53
|
+
Py_DECREF(thread_names);
|
|
54
|
+
Py_DECREF(counter_events);
|
|
55
|
+
Py_DECREF(other_events);
|
|
56
|
+
|
|
57
|
+
for (Py_ssize_t i = 0; i < PyList_GET_SIZE(trace_events); i++) {
|
|
58
|
+
PyObject* event = PyList_GetItem(trace_events, i);
|
|
59
|
+
PyObject* ph = NULL;
|
|
60
|
+
PyObject* name = NULL;
|
|
61
|
+
PyObject* args_name = NULL;
|
|
62
|
+
PyObject* pid = NULL;
|
|
63
|
+
PyObject* tid = NULL;
|
|
64
|
+
PyObject* ts = NULL;
|
|
65
|
+
PyObject* dur = NULL;
|
|
66
|
+
PyObject* fee_args = NULL;
|
|
67
|
+
PyObject* counter_args = NULL;
|
|
68
|
+
PyObject* ts_dur_tuple = NULL;
|
|
69
|
+
PyObject* event_ts_list = NULL;
|
|
70
|
+
PyObject* counter_event_dict = NULL;
|
|
71
|
+
if (PyErr_Occurred() || !PyDict_CheckExact(event)) {
|
|
72
|
+
PyErr_SetString(PyExc_ValueError, "event format failure");
|
|
73
|
+
goto clean_exit;
|
|
74
|
+
}
|
|
75
|
+
ph = PyDict_GetItemString(event, "ph");
|
|
76
|
+
if (!ph || !PyUnicode_CheckExact(ph)) {
|
|
77
|
+
PyErr_SetString(PyExc_ValueError, "event format failure");
|
|
78
|
+
goto clean_exit;
|
|
79
|
+
}
|
|
80
|
+
switch (PyUnicode_AsUTF8(ph)[0]) {
|
|
81
|
+
case 'X':
|
|
82
|
+
name = PyDict_GetItemString(event, "name");
|
|
83
|
+
ts = PyDict_GetItemString(event, "ts");
|
|
84
|
+
dur = PyDict_GetItemString(event, "dur");
|
|
85
|
+
pid = PyDict_GetItemString(event, "pid");
|
|
86
|
+
tid = PyDict_GetItemString(event, "tid");
|
|
87
|
+
if (!ts || !dur || !pid || !tid) {
|
|
88
|
+
PyErr_SetString(PyExc_ValueError, "event format failure");
|
|
89
|
+
goto clean_exit;
|
|
90
|
+
}
|
|
91
|
+
// Prepare the tuple key
|
|
92
|
+
key = PyTuple_New(4);
|
|
93
|
+
|
|
94
|
+
// PyTuple_SetItem steals reference
|
|
95
|
+
Py_INCREF(pid);
|
|
96
|
+
Py_INCREF(tid);
|
|
97
|
+
Py_INCREF(name);
|
|
98
|
+
PyTuple_SET_ITEM(key, 0, pid);
|
|
99
|
+
PyTuple_SET_ITEM(key, 1, tid);
|
|
100
|
+
PyTuple_SET_ITEM(key, 2, name);
|
|
101
|
+
|
|
102
|
+
// This indicates that if there's args in fee
|
|
103
|
+
fee_args = PyDict_GetItemString(event, "args");
|
|
104
|
+
if (fee_args) {
|
|
105
|
+
PyTuple_SET_ITEM(key, 3, Py_True);
|
|
106
|
+
Py_INCREF(Py_True);
|
|
107
|
+
} else {
|
|
108
|
+
PyTuple_SET_ITEM(key, 3, Py_False);
|
|
109
|
+
Py_INCREF(Py_False);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!PyDict_Contains(fee_events, key)) {
|
|
113
|
+
event_ts_list = PyList_New(0);
|
|
114
|
+
PyDict_SetItem(fee_events, key, event_ts_list);
|
|
115
|
+
Py_DECREF(event_ts_list);
|
|
116
|
+
} else {
|
|
117
|
+
event_ts_list = PyDict_GetItem(fee_events, key);
|
|
118
|
+
}
|
|
119
|
+
Py_DECREF(key);
|
|
120
|
+
|
|
121
|
+
if (fee_args) {
|
|
122
|
+
ts_dur_tuple = PyTuple_New(3);
|
|
123
|
+
} else {
|
|
124
|
+
ts_dur_tuple = PyTuple_New(2);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
Py_INCREF(ts);
|
|
128
|
+
Py_INCREF(dur);
|
|
129
|
+
PyTuple_SET_ITEM(ts_dur_tuple, 0, ts);
|
|
130
|
+
PyTuple_SET_ITEM(ts_dur_tuple, 1, dur);
|
|
131
|
+
|
|
132
|
+
if (fee_args) {
|
|
133
|
+
PyTuple_SET_ITEM(ts_dur_tuple, 2, fee_args);
|
|
134
|
+
Py_INCREF(fee_args);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
PyList_Append(event_ts_list, ts_dur_tuple);
|
|
138
|
+
Py_DECREF(ts_dur_tuple);
|
|
139
|
+
break;
|
|
140
|
+
case 'M':
|
|
141
|
+
name = PyDict_GetItemString(event, "name");
|
|
142
|
+
pid = PyDict_GetItemString(event, "pid");
|
|
143
|
+
tid = PyDict_GetItemString(event, "tid");
|
|
144
|
+
if (!name || !pid || !tid) {
|
|
145
|
+
PyErr_SetString(PyExc_ValueError, "event format failure");
|
|
146
|
+
goto clean_exit;
|
|
147
|
+
}
|
|
148
|
+
args_name = PyDict_GetItemString(
|
|
149
|
+
PyDict_GetItemString(event, "args"),
|
|
150
|
+
"name"
|
|
151
|
+
);
|
|
152
|
+
PyObject* id_key = PyTuple_New(2);
|
|
153
|
+
|
|
154
|
+
// PyTuple_SetItem steals reference
|
|
155
|
+
Py_INCREF(pid);
|
|
156
|
+
Py_INCREF(tid);
|
|
157
|
+
PyTuple_SET_ITEM(id_key, 0, pid);
|
|
158
|
+
PyTuple_SET_ITEM(id_key, 1, tid);
|
|
159
|
+
|
|
160
|
+
if (PyUnicode_CompareWithASCIIString(name, "process_name") == 0) {
|
|
161
|
+
PyDict_SetItem(process_names, id_key, args_name);
|
|
162
|
+
} else if (PyUnicode_CompareWithASCIIString(name, "thread_name") == 0) {
|
|
163
|
+
PyDict_SetItem(thread_names, id_key, args_name);
|
|
164
|
+
} else {
|
|
165
|
+
PyErr_SetString(PyExc_ValueError, "event format failure");
|
|
166
|
+
Py_DECREF(id_key);
|
|
167
|
+
goto clean_exit;
|
|
168
|
+
}
|
|
169
|
+
Py_DECREF(id_key);
|
|
170
|
+
break;
|
|
171
|
+
// Counter Event
|
|
172
|
+
// {"pid": 852, "tid": 852, "ts": 358802972.1, "ph": "C", "name": "counter name", "args": {"a": 20, "b": 10}}
|
|
173
|
+
case 'C':
|
|
174
|
+
name = PyDict_GetItemString(event, "name");
|
|
175
|
+
pid = PyDict_GetItemString(event, "pid");
|
|
176
|
+
tid = PyDict_GetItemString(event, "tid");
|
|
177
|
+
ts = PyDict_GetItemString(event, "ts");
|
|
178
|
+
if (!ts || !name || !pid || !tid) {
|
|
179
|
+
PyErr_SetString(PyExc_ValueError, "event format failure");
|
|
180
|
+
goto clean_exit;
|
|
181
|
+
}
|
|
182
|
+
counter_args = PyDict_GetItemString(event, "args");
|
|
183
|
+
PyObject* counter_id_key = PyTuple_New(3);
|
|
184
|
+
// counter_id_key steals the reference, so we need to call Py_INCREF here
|
|
185
|
+
Py_INCREF(name);
|
|
186
|
+
Py_INCREF(pid);
|
|
187
|
+
Py_INCREF(tid);
|
|
188
|
+
PyTuple_SET_ITEM(counter_id_key, 0, pid);
|
|
189
|
+
PyTuple_SET_ITEM(counter_id_key, 1, tid);
|
|
190
|
+
PyTuple_SET_ITEM(counter_id_key, 2, name);
|
|
191
|
+
if (!PyDict_Contains(counter_events, counter_id_key)){
|
|
192
|
+
counter_event_dict = PyDict_New();
|
|
193
|
+
PyDict_SetItem(counter_events, counter_id_key, counter_event_dict);
|
|
194
|
+
Py_DECREF(counter_event_dict);
|
|
195
|
+
} else {
|
|
196
|
+
counter_event_dict = PyDict_GetItem(counter_events, counter_id_key);
|
|
197
|
+
}
|
|
198
|
+
Py_DECREF(counter_id_key);
|
|
199
|
+
if (PyDict_Contains(counter_event_dict, ts)) {
|
|
200
|
+
PyErr_SetString(PyExc_ValueError, "event format failure, reason: same counter event timestamp");
|
|
201
|
+
goto clean_exit;
|
|
202
|
+
}
|
|
203
|
+
PyDict_SetItem(counter_event_dict, ts, counter_args);
|
|
204
|
+
break;
|
|
205
|
+
// Other Events, such as instant events, VizObject and user defined events
|
|
206
|
+
default:
|
|
207
|
+
PyList_Append(other_events, event);
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
clean_exit:
|
|
213
|
+
|
|
214
|
+
if (PyErr_Occurred()) {
|
|
215
|
+
if (parsed_events) {
|
|
216
|
+
Py_DECREF(parsed_events);
|
|
217
|
+
}
|
|
218
|
+
return NULL;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return parsed_events;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
static PyObject* vcompressor_compress(VcompressorObject* self, PyObject* args)
|
|
225
|
+
{
|
|
226
|
+
PyObject* raw_data = NULL;
|
|
227
|
+
PyObject* trace_events = NULL;
|
|
228
|
+
PyObject* parsed_events = NULL;
|
|
229
|
+
PyObject* file_info = NULL;
|
|
230
|
+
const char* filename = NULL;
|
|
231
|
+
FILE* fptr = NULL;
|
|
232
|
+
|
|
233
|
+
if (!PyArg_ParseTuple(args, "Os", &raw_data, &filename)) {
|
|
234
|
+
PyErr_SetString(PyExc_ValueError, "Can't parse the argument correctly");
|
|
235
|
+
goto clean_exit;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (!PyDict_CheckExact(raw_data)) {
|
|
239
|
+
PyErr_SetString(PyExc_ValueError, "You need to pass in a dict");
|
|
240
|
+
goto clean_exit;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
trace_events = PyDict_GetItemString(raw_data, "traceEvents");
|
|
244
|
+
|
|
245
|
+
if (!trace_events || !PyList_CheckExact(trace_events)) {
|
|
246
|
+
PyErr_SetString(PyExc_ValueError, "Unable to find traceEvents");
|
|
247
|
+
goto clean_exit;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
fptr = fopen(filename, "wb");
|
|
251
|
+
if (!fptr) {
|
|
252
|
+
PyErr_Format(PyExc_ValueError, "Can't open file %s to write", filename);
|
|
253
|
+
goto clean_exit;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
dump_metadata(fptr);
|
|
257
|
+
|
|
258
|
+
parsed_events = parse_trace_events(trace_events);
|
|
259
|
+
|
|
260
|
+
if (!parsed_events) {
|
|
261
|
+
PyErr_SetString(PyExc_ValueError, "Unable to find traceEvents");
|
|
262
|
+
goto clean_exit;
|
|
263
|
+
}
|
|
264
|
+
Py_INCREF(parsed_events);
|
|
265
|
+
|
|
266
|
+
if (dump_parsed_trace_events(parsed_events, fptr) != 0) {
|
|
267
|
+
goto clean_exit;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// file_info here is a borrowed reference
|
|
271
|
+
file_info = PyDict_GetItemString(raw_data, "file_info");
|
|
272
|
+
if (file_info != NULL) {
|
|
273
|
+
if (dump_file_info(file_info, fptr) != 0) {
|
|
274
|
+
goto clean_exit;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
clean_exit:
|
|
279
|
+
|
|
280
|
+
if (parsed_events) {
|
|
281
|
+
Py_DECREF(parsed_events);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (fptr) {
|
|
285
|
+
fclose(fptr);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (PyErr_Occurred()) {
|
|
289
|
+
return NULL;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return parsed_events;
|
|
293
|
+
|
|
294
|
+
// Py_RETURN_NONE;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
static PyObject*
|
|
298
|
+
vcompressor_decompress(VcompressorObject* self, PyObject* args) {
|
|
299
|
+
PyObject* parsed_events = NULL;
|
|
300
|
+
const char* filename = NULL;
|
|
301
|
+
FILE* fptr = NULL;
|
|
302
|
+
|
|
303
|
+
if (!PyArg_ParseTuple(args, "s", &filename)) {
|
|
304
|
+
return NULL;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
fptr = fopen(filename, "rb");
|
|
308
|
+
if (!fptr) {
|
|
309
|
+
PyErr_Format(PyExc_ValueError, "Can't open file %s to write", filename);
|
|
310
|
+
goto clean_exit;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
parsed_events = load_events_from_file(fptr);
|
|
314
|
+
|
|
315
|
+
clean_exit:
|
|
316
|
+
|
|
317
|
+
if (fptr) {
|
|
318
|
+
fclose(fptr);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (PyErr_Occurred()) {
|
|
322
|
+
if (parsed_events) {
|
|
323
|
+
Py_DECREF(parsed_events);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return NULL;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return parsed_events;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
// ================================================================
|
|
334
|
+
// Python interface
|
|
335
|
+
// ================================================================
|
|
336
|
+
|
|
337
|
+
static PyMethodDef Vcompressor_methods[] = {
|
|
338
|
+
{"compress", (PyCFunction)vcompressor_compress, METH_VARARGS, "compress function"},
|
|
339
|
+
{"decompress", (PyCFunction)vcompressor_decompress, METH_VARARGS, "decompress function"},
|
|
340
|
+
{NULL, NULL, 0, NULL}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
static struct PyModuleDef compressormodule = {
|
|
344
|
+
PyModuleDef_HEAD_INIT,
|
|
345
|
+
"viztracer.vcompressor",
|
|
346
|
+
NULL,
|
|
347
|
+
-1,
|
|
348
|
+
Vcompressor_methods
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
static PyTypeObject VcompressorType = {
|
|
352
|
+
PyVarObject_HEAD_INIT(NULL, 0)
|
|
353
|
+
.tp_name = "viztracer.Vcompressor",
|
|
354
|
+
.tp_doc = "Vcompressor",
|
|
355
|
+
.tp_basicsize = sizeof(VcompressorObject),
|
|
356
|
+
.tp_itemsize = 0,
|
|
357
|
+
.tp_dict = NULL,
|
|
358
|
+
.tp_flags = Py_TPFLAGS_DEFAULT,
|
|
359
|
+
.tp_new = vcompressor_new,
|
|
360
|
+
.tp_dealloc = (destructor) vcompressor_dealloc,
|
|
361
|
+
.tp_methods = Vcompressor_methods
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
PyMODINIT_FUNC
|
|
365
|
+
PyInit_vcompressor(void)
|
|
366
|
+
{
|
|
367
|
+
// Tracer Module
|
|
368
|
+
PyObject* m = NULL;
|
|
369
|
+
|
|
370
|
+
if (PyType_Ready(&VcompressorType) < 0) {
|
|
371
|
+
return NULL;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
m = PyModule_Create(&compressormodule);
|
|
375
|
+
|
|
376
|
+
if (!m) {
|
|
377
|
+
return NULL;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
#ifdef Py_GIL_DISABLED
|
|
381
|
+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
|
|
382
|
+
#endif
|
|
383
|
+
|
|
384
|
+
Py_INCREF(&VcompressorType);
|
|
385
|
+
|
|
386
|
+
if (PyModule_AddObject(m, "VCompressor", (PyObject*) &VcompressorType) < 0) {
|
|
387
|
+
Py_DECREF(&VcompressorType);
|
|
388
|
+
Py_DECREF(m);
|
|
389
|
+
return NULL;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
zlib_module = PyImport_ImportModule("zlib");
|
|
393
|
+
json_module = PyImport_ImportModule("json");
|
|
394
|
+
|
|
395
|
+
return m;
|
|
396
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#ifndef __VCOMPRESSOR_H__
|
|
2
|
+
#define __VCOMPRESSOR_H__
|
|
3
|
+
|
|
4
|
+
#include <Python.h>
|
|
5
|
+
|
|
6
|
+
#define VCOMPRESSOR_VERSION 1
|
|
7
|
+
|
|
8
|
+
typedef struct {
|
|
9
|
+
PyObject_HEAD
|
|
10
|
+
} VcompressorObject;
|
|
11
|
+
|
|
12
|
+
extern PyObject* json_module;
|
|
13
|
+
extern PyObject* zlib_module;
|
|
14
|
+
|
|
15
|
+
#endif
|