-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtegrastats.py
48 lines (38 loc) · 1.43 KB
/
tegrastats.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import subprocess
class Tegrastats:
def __init__(self, interval, log_file, verbose):
self.interval = interval
self.log_file = log_file
self.verbose = verbose
def prepare_command(self):
tegrastats_cmd = f"tegrastats --interval {self.interval}"
if self.verbose:
tegrastats_cmd = tegrastats_cmd + " --verbose"
cmd = f"{{ echo $(date -u) & {tegrastats_cmd}; }} > {self.log_file}"
return cmd
def run(self):
cmd = self.prepare_command()
process = None
try:
process = subprocess.Popen(cmd, shell=True)
print("Running tegrastats...\nEnter 'exit' to stop tegrastats and parse data\n")
except subprocess.CalledProcessError:
print(f"Error running tegrastats!\nCommand used {cmd}")
return False
while (True):
user_input = input()
if (user_input == "exit"):
try:
process.kill()
print("Successfully stopped tegrastats!")
break
except subprocess.CalledProcessError:
print(f"Unable to kill tegrastats (pid={process.pid}) successfully...")
return False
return True
if __name__ == '__main__':
interval = 1000
log_file = 'output_log.txt'
verbose = False
tegrastats = Tegrastats(interval, log_file, verbose)
tegrastats.run()