Skip to content

Commit

Permalink
Added multiple axes for plots
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmilano committed Mar 13, 2017
1 parent 51e31ad commit a350ade
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/androidviewclient.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ src/com/dtmilano/android/common.py
src/com/dtmilano/android/concertina.py
src/com/dtmilano/android/controlpanel.py
src/com/dtmilano/android/culebron.py
src/com/dtmilano/android/plot.py
src/com/dtmilano/android/viewclient.py
src/com/dtmilano/android/window.py
src/com/dtmilano/android/adb/__init__.py
Expand Down
2 changes: 1 addition & 1 deletion src/androidviewclient.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
setuptools
requests
requests
2 changes: 1 addition & 1 deletion src/androidviewclient.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
com
share
com
39 changes: 32 additions & 7 deletions src/com/dtmilano/android/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,24 @@
import types

import matplotlib.pyplot as plt
import mpl_toolkits.axisartist as AA
import numpy as np
from mpl_toolkits.axes_grid1 import host_subplot

from com.dtmilano.android.adb.dumpsys import Dumpsys

__version__ = '13.1.0'


NumberTypes = (types.IntType, types.LongType, types.FloatType)


class Plot:

def __init__(self):
self.n = 0
self.na = []
self.va = []
self.ava = {}
''' Associative values array '''

def append(self, value):
self.n += 1
Expand All @@ -47,7 +49,7 @@ def append(self, value):
dumpsys = value
if not self.ava:
self.__initAva()
self.ava[Dumpsys.TOTAL].append(dumpsys.get(Dumpsys.TOTAL)/(1024*1024))
self.ava[Dumpsys.TOTAL].append(dumpsys.get(Dumpsys.TOTAL))
self.ava[Dumpsys.ACTIVITIES].append(dumpsys.get(Dumpsys.ACTIVITIES))
self.ava[Dumpsys.VIEWS].append(dumpsys.get(Dumpsys.VIEWS))
self.ava[Dumpsys.VIEW_ROOT_IMPL].append(dumpsys.get(Dumpsys.VIEW_ROOT_IMPL))
Expand All @@ -59,16 +61,39 @@ def __initAva(self):
self.ava[Dumpsys.VIEW_ROOT_IMPL] = []

def plot(self):
plt.xlabel('N')
plt.ylabel('V')
if self.ava:
host = host_subplot(111, axes_class=AA.Axes)
plt.subplots_adjust(right=0.75)
axis = 1
for k in self.ava.keys():
plt.plot(self.na, self.ava[k], label=k)
if k == Dumpsys.TOTAL:
host.plot(self.na, self.ava[k], label=k)
host.set_xlabel('N')
host.set_ylabel(k)
host.set_xlim(np.amin(self.na), np.amax(self.na))
host.set_ylim(np.amin(self.ava[k]), np.amax(self.ava[k]))
else:
par = host.twinx()
offset = axis * 60
axis += 1
new_fixed_axis = par.get_grid_helper().new_fixed_axis
par.axis["right"] = new_fixed_axis(loc="right",
axes=par,
offset=(offset, 0))
par.axis["right"].toggle(all=True)
par.plot(self.na, self.ava[k], label=k)
par.set_ylabel(k)
par.set_xlim(np.amin(self.na), np.amax(self.na))
par.set_ylim(np.amin(self.ava[k]), np.amax(self.ava[k]))
host.legend()
elif self.va:
plt.xlabel('N')
plt.ylabel('V')
plt.plot(self.na, self.va, label="A")
else:
raise RuntimeError("No values to plot")
plt.title('About as simple as it gets, folks')
plt.grid(True)
plt.savefig("plot.png")
plt.draw()
# plt.savefig("plot.png")
plt.show()
19 changes: 17 additions & 2 deletions tests/com/dtmilano/android/plottests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from com.dtmilano.android.plot import Plot

SERIALNO = '.*'
SAMPLE_PROCESS_NAME = 'com.android.systemui'


class PlotTests(unittest.TestCase):
Expand All @@ -20,11 +21,25 @@ def setUp(self):
self.plot = Plot()

def test_plot_dumpsys_meminfo(self):
for n in range(100):
self.plot.append(Dumpsys(self.device, Dumpsys.MEMINFO, 'com.android.systemui'))
for n in range(10):
self.plot.append(Dumpsys(self.device, Dumpsys.MEMINFO, SAMPLE_PROCESS_NAME))
time.sleep(1)
self.plot.plot()

def test_plot_dumpsys_meminfo_culebratester(self):
for n in range(10):
self.device.startActivity("com.dtmilano.android.sampleapplication/.MainActivity")
time.sleep(2)
self.plot.append(Dumpsys(self.device, Dumpsys.MEMINFO, "com.dtmilano.android.sampleapplication"))
self.device.press('BACK')
time.sleep(0.5)
self.device.press('BACK')
time.sleep(0.5)
self.device.press('HOME')
time.sleep(0.5)
self.plot.plot()



if __name__ == '__main__':
unittest.main()

0 comments on commit a350ade

Please sign in to comment.