-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
34 lines (21 loc) · 842 Bytes
/
common.py
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
from timeit import default_timer
import os
import psutil
def get_execute_time():
start_time = default_timer()
# function
terminate_time = default_timer()
print("%f초" % (terminate_time - start_time))
def check_usage_of_cpu_and_memory():
pid = os.getpid()
py = psutil.Process(pid)
cpu_usage = os.popen("ps aux | grep " + str(pid) + " | grep -v grep | awk '{print $3}'").read()
cpu_usage = cpu_usage.replace("\n","")
memory_usage = round(py.memory_info()[0] /2.**30, 2)
print("cpu usage\t\t:", cpu_usage, "%")
print("memory usage\t\t:", memory_usage, "%")
def memory_usage(message: str = 'debug'):
# current process RAM usage
p = psutil.Process()
rss = p.memory_info().rss / 2 ** 20 # Bytes to MB
print(f"[{message}] memory usage: {rss: 10.5f} MB")