启用osd性能剖析脚本


Profile

针对OSD启用过程缓慢进行性能剖析,用到了一系列的脚本,例如批量创建OSD,批量启用OSD,Cprofile装饰器接口等

docprofile.py:提供cprofiler的装饰器接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import cProfile
import pstats
import os
def (filename):
def wrapper(func):
def profiled_func(*args, **kwargs):
print filename

DO_PROF = os.getenv("PROFILING")
if DO_PROF:
profile = cProfile.Profile()
profile.enable()
result = func(*args, **kwargs)
profile.disable()
# Sort stat by internal time.
sortby = "cum"
ps = pstats.Stats(profile).sort_stats(sortby)
ps.dump_stats(filename)
else:
result = func(*args, **kwargs)
return result
return profiled_func
return wrapper

pstat.py:用于处理生成的cprofiler文件,做一些排序,截取和打印等工作,默认按culativetime排序,打印前100条记录,有其他需求的可以适当修改参数

1
2
3
4
import pstats, sys
file = sys.argv[1]
p = pstats.Stats(file)
p.strip_dirs().sort_stats('cum').print_stats(100)