Skip to content

Commit 610e557

Browse files
committed
utilization test added
1 parent ee0c5c3 commit 610e557

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

.idea/workspace.xml

Lines changed: 2 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dkeras/dkeras.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import os
99
import time
10+
import keras
1011

1112
import ray
1213

testing/utilization_test.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/env/python
2+
# -*- encoding: utf-8 -*-
3+
"""
4+
5+
"""
6+
from __future__ import print_function, division
7+
8+
import multiprocessing as mp
9+
import time
10+
11+
import matplotlib.pyplot as plt
12+
import numpy as np
13+
import psutil
14+
from tensorflow.keras.applications import ResNet50
15+
16+
17+
def run_predict():
18+
model = ResNet50()
19+
test_data = np.random.uniform(-1, 1, (100, 224, 224, 3))
20+
time.sleep(1)
21+
model.predict(test_data)
22+
23+
24+
def monitor(target):
25+
worker_process = mp.Process(target=target)
26+
worker_process.start()
27+
#p = psutil.Process(worker_process.pid)
28+
29+
# log cpu usage of `worker_process` every 10 ms
30+
cpu_percents = []
31+
while worker_process.is_alive():
32+
cpu_percents.append(psutil.cpu_percent(percpu=False))
33+
time.sleep(1e-3)
34+
35+
worker_process.join()
36+
return cpu_percents
37+
38+
39+
def main():
40+
cpu_percents = monitor(target=run_predict)
41+
print(cpu_percents)
42+
43+
# Data for plotting
44+
t = np.asarray(range(len(cpu_percents)))
45+
cpu_percents = np.asarray(cpu_percents)
46+
47+
fig, ax = plt.subplots()
48+
ax.plot(t, cpu_percents)
49+
50+
ax.set(xlabel='time (ms)', ylabel='CPU utilization',
51+
title='CPU utilization for ResNet50 Inference')
52+
ax.grid()
53+
54+
fig.savefig("test.png")
55+
plt.show()
56+
57+
58+
if __name__ == "__main__":
59+
main()

0 commit comments

Comments
 (0)