Skip to content

Commit

Permalink
Lint fix, ready for 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gaogaotiantian committed Aug 19, 2020
1 parent 44afa59 commit 4caa1a2
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 34 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name="viztracer",
version="0.2.1",
version="0.2.2",
author="Tian Gao",
author_email="[email protected]",
description="A debugging and profiling tool that can trace and visualize python code execution",
Expand Down
29 changes: 0 additions & 29 deletions src/viztracer/modules/snaptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ static struct ThreadInfo* snaptrace_createthreadinfo(void);
// the key is used to locate thread specific info
static pthread_key_t thread_key = 0;
// We need to ignore the first events until we get an entry
int first_event = 1;
int collecting = 0;
unsigned long total_entries = 0;
unsigned int check_flags = 0;
Expand Down Expand Up @@ -173,14 +172,6 @@ snaptrace_tracefunc(PyObject* obj, PyFrameObject* frame, int what, PyObject* arg
struct EventNode* node = NULL;
struct ThreadInfo* info = pthread_getspecific(thread_key);

//if (first_event) {
// if (what == PyTrace_RETURN || what == PyTrace_C_RETURN) {
// return 0;
// } else {
// first_event = 0;
// }
//}

if (info->paused) {
return 0;
}
Expand Down Expand Up @@ -367,7 +358,6 @@ snaptrace_start(PyObject* self, PyObject* args)
}
PyEval_SetProfile(snaptrace_tracefunc, NULL);

first_event = 1;
collecting = 1;

Py_RETURN_NONE;
Expand Down Expand Up @@ -438,24 +428,6 @@ snaptrace_load(PyObject* self, PyObject* args)
PyObject* prev_dict = NULL;
while (curr != buffer_tail && curr->next) {
struct EventNode* node = curr->next;
// If this is the immediate exit of the previous node, change the previous node
//if (node->ntype == FEE_NODE &&
// (node->data.fee.type == PyTrace_RETURN ||
// node->data.fee.type == PyTrace_C_RETURN ||
// node->data.fee.type == PyTrace_C_EXCEPTION )) {
// if (prev_dict && node->prev->ntype == FEE_NODE &&
// (node->prev->data.fee.type == PyTrace_CALL ||
// node->prev->data.fee.type == PyTrace_C_CALL) &&
// (node->data.fee.tid == node->prev->data.fee.tid)) {
// PyObject* dur = PyFloat_FromDouble(node->ts - node->prev->ts);
// PyDict_SetItemString(prev_dict, "ph", ph_X);
// PyDict_SetItemString(prev_dict, "dur", dur);
// prev_dict = NULL;
// curr = curr->next;
// continue;
// }
//}

PyObject* dict = PyDict_New();
PyObject* name = NULL;
PyObject* tid = PyLong_FromLong(node->data.fee.tid);
Expand Down Expand Up @@ -703,7 +675,6 @@ PyInit_snaptrace(void)
buffer_head->next = NULL;
buffer_head->prev = NULL;
buffer_tail = buffer_head;
first_event = 1;
collecting = 0;
if (pthread_key_create(&thread_key, snaptrace_threaddestructor)) {
perror("Failed to create Tss_Key");
Expand Down
3 changes: 2 additions & 1 deletion src/viztracer/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ def parse(self):

def overload_print(self):
self.system_print = builtins.print

def new_print(*args, **kwargs):
snaptrace.pause()
io = StringIO()
kwargs["file"] = io
self.system_print(*args, **kwargs)
self.add_instant("print", {"string":io.getvalue()})
self.add_instant("print", {"string": io.getvalue()})
snaptrace.resume()
builtins.print = new_print

Expand Down
5 changes: 3 additions & 2 deletions src/viztracer/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ def update(self, progress):
if self.progress == 100:
print("")


def size_fmt(num, suffix='B'):
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)
return "%.1f%s%s" % (num, 'Yi', suffix)
2 changes: 1 addition & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ def test_log_print(self):
print("hello")
tracer.stop()
entries = tracer.parse()
self.assertEqual(entries, 4)
self.assertEqual(entries, 4)

0 comments on commit 4caa1a2

Please sign in to comment.