-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.py
More file actions
74 lines (57 loc) · 2.03 KB
/
Copy pathdebug.py
File metadata and controls
74 lines (57 loc) · 2.03 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
# -*- coding: utf-8 -*-
# vim: set tabstop=4 softtabstop=0 noexpandtab shiftwidth=4
# ***************************************************************
# * Soubor: debug.py *
# * Datum: 2018-04-16 *
# * Autor: Jan Doležal, xdolez52@stud.fit.vutbr.cz *
# * Projekt: == Failure Rate λ(t) to Failure Density f(t) == *
# * EVO - 00 - Evoluční hledání funkcí se specifickými *
# * vlastnostmi (konzultace: J. Strnadel, L332) *
# ***************************************************************
import sys
# Pro debugování:
import inspect
import traceback
import time
DEBUG_EN = True
#
# FUNKCE A TŘÍDY:
def printDbgEn(*args, **kwargs):
kwargs.setdefault("file", sys.stderr)
kwargs.setdefault("stack_num", 1)
stack_num = kwargs.pop("stack_num")
callerframerecord = inspect.stack()[stack_num]
frame = callerframerecord[0]
info = inspect.getframeinfo(frame)
head = "(%s, %s, %s, time=%r, cpuTime=%r)" % (info.filename, info.function, info.lineno, time.time(), time.clock())
print(head, ":", sep="", file=kwargs["file"])
print("'''", file=kwargs["file"])
print(*args, **kwargs)
print("'''", file=kwargs["file"], flush=True)
#
def printDbg(*args, **kwargs):
if not DEBUG_EN:
return
if "stack_num" not in kwargs:
kwargs["stack_num"] = 2
printDbgEn(*args, **kwargs)
#
def curInspect():
callerframerecord = inspect.stack()[1]
frame = callerframerecord[0]
info = inspect.getframeinfo(frame)
head = "(%s, %s, %s, time=%r, cpuTime=%r)" % (info.filename, info.function, info.lineno, time.time(), time.clock())
return head
#
def callerInspect():
callerframerecord = inspect.stack()[2]
frame = callerframerecord[0]
info = inspect.getframeinfo(frame)
head = "(%s, %s, %s, time=%r, cpuTime=%r)" % (info.filename, info.function, info.lineno, time.time(), time.clock())
return head
#
def curTraceback():
formated_traceback = traceback.format_stack()[:-1]
return "".join(formated_traceback)
#
# konec souboru debug.py