def total_size(self): return natualsize(self.max)
def current_size(self): return natualsize(self.index)
def csv2images(self, src=None, target_dir='.'): """ Args: src: csv file, default to perf record csv path target_dir: images store dir """ import pandas as pd import matplotlib.pyplot as plt import matplotlib.ticker as ticker import datetime import os from uiautomator2.utils import natualsize src = src or self.csv_output if not os.path.exists(target_dir): os.makedirs(target_dir) data = pd.read_csv(src) data['time'] = data['time'].apply( lambda x: datetime.datetime.strptime(x, "%Y-%m-%d %H:%M:%S.%f")) timestr = time.strftime("%Y-%m-%d %H:%M") # network rx_str = natualsize(data['rxBytes'].sum()) tx_str = natualsize(data['txBytes'].sum()) plt.subplot(2, 1, 1) plt.plot(data['time'], data['rxBytes'] / 1024, label='all') plt.plot(data['time'], data['rxTcpBytes'] / 1024, 'r--', label='tcp') plt.legend() plt.title('\n'.join( ["Network", timestr, 'Recv %s, Send %s' % (rx_str, tx_str)]), loc='left') plt.gca().xaxis.set_major_formatter(ticker.NullFormatter()) plt.ylabel('Recv(KB)') plt.ylim(ymin=0) plt.subplot(2, 1, 2) plt.plot(data['time'], data['txBytes'] / 1024, label='all') plt.plot(data['time'], data['txTcpBytes'] / 1024, 'r--', label='tcp') plt.legend() plt.xlabel('Time') plt.ylabel('Send(KB)') plt.ylim(ymin=0) plt.savefig(os.path.join(target_dir, "net.png")) plt.clf() plt.subplot(3, 1, 1) plt.title('\n'.join(['Summary', timestr, self.package_name]), loc='left') plt.plot(data['time'], data['pss'], '-') plt.ylabel('PSS(MB)') plt.gca().xaxis.set_major_formatter(ticker.NullFormatter()) plt.subplot(3, 1, 2) plt.plot(data['time'], data['cpu'], '-') plt.ylim(0, max(100, data['cpu'].max())) plt.ylabel('CPU') plt.gca().xaxis.set_major_formatter(ticker.NullFormatter()) plt.subplot(3, 1, 3) plt.plot(data['time'], data['fps'], '-') plt.ylabel('FPS') plt.ylim(0, 60) plt.xlabel('Time') plt.savefig(os.path.join(target_dir, "summary.png"))