simpleperf 火焰图

Python019

simpleperf 火焰图,第1张

1. 获取simpleperf的可执行文件

android\system\extras\simpleperf\scripts\bin\android

2 利用simpleperf抓取perf.data数据

adb shell simpleperf record -p 1791 -g --duration 30 -o /sdcard/perf.data

3  pull数据到指定的目录

simpleperf-master$ adb pull /sdcard/perf.data

4 . 在该目录下执行如下指令

python report_sample.py --symfs android/out/target/product/sdm710/symbols/vendor/lib/hw/ >out.perf

注:示例中的 " --symfs " 指定符号表

5. 从github中获取如下工具

git clone https://github.com/brendangregg/FlameGraph.git

6. 生成火焰图

在 simpleperf-master$ 运行  python report_sample.py >./FlameGraph-master/out.perf

进入 /FlameGraph-master 下运行

./stackcollapse-perf.pl out.perf >out.folded

./flamegraph.pl out.folded >p.svg

注:上面的2个工具存在于FlameGraph的git仓库中 ,最后生成的p.svg需要用Google Chrome打开

# Python热力图绘制方法

热力图的使用场景有 

1.描述数据在空间的密集程度,常见有城市热力图,区域热力图

2.描述多个变量之间相关性高低程度

# step 1 准备数据集,读取excel列表内容,usecols = index, 这里是表里的第一列不读取。

index =range(1, 11)

dataset = np.array(pd.read_csv(r'C:\Users\Administrator\Desktop\heatmap.csv', usecols=index))

# step 2  读取excel行索引转成列表,作为热力图的y轴标签

a = (pd.read_csv(r'C:\Users\Administrator\Desktop\heatmap.csv', usecols=[0]))

y_label =list(a.stack())

# step 3 读取excel列索引转成列表,作为热力图的x轴标签

b = (pd.read_csv(r'C:\Users\Administrator\Desktop\heatmap.csv'))

column_index=(b.columns.tolist())

x_label = column_index[1:]

# 这一步是为了计算热力图的数据的最大值,可以进行标准化处理,也可以直接显示数据,dataframe转成list,从list里面寻找最大值

dataset_max = (pd.read_csv(r'C:\Users\Administrator\Desktop\heatmap.csv', usecols=index))

list1 = np.array(dataset_max.stack())

max_number =max(list1)

# step 4 开始绘制热力图

plt.figure(figsize=(14, 8))# 定义输出图像大小,annot参数决定是否在热力图上显示数值,Vmax,Vmin表示最大最小值,cmap表示颜色

sns.heatmap(dataset, fmt='.0f', annot=True, vmin=0, vmax=max_number, cmap='Reds', yticklabels=y_label,

            xticklabels=x_label)

# 绘制标签

plt.xlabel('This is x label', labelpad=15)

plt.ylabel('This is y label', labelpad=20)

plt.show()