show_profile.py 1.2 KB
Newer Older
M
MRXLT 已提交
1 2 3 4 5 6 7
#coding=utf-8
import sys
import collections

profile_file = sys.argv[1]
thread_num = sys.argv[2]
time_dict = collections.OrderedDict()
H
HexToString 已提交
8
query_count = 0
M
MRXLT 已提交
9 10 11 12 13


def prase(line):
    profile_list = line.split(" ")
    num = len(profile_list)
M
MRXLT 已提交
14
    for idx in range(int(num / 2)):
M
MRXLT 已提交
15 16 17 18 19 20 21
        profile_0_list = profile_list[idx * 2].split(":")
        profile_1_list = profile_list[idx * 2 + 1].split(":")
        if len(profile_0_list[0].split("_")) == 2:
            name = profile_0_list[0].split("_")[0]
        else:
            name = profile_0_list[0].split("_")[0] + "_" + profile_0_list[
                0].split("_")[1]
M
MRXLT 已提交
22
        cost = int(profile_1_list[1]) - int(profile_0_list[1])
M
MRXLT 已提交
23 24 25 26 27 28 29
        if name not in time_dict:
            time_dict[name] = cost
        else:
            time_dict[name] += cost


with open(profile_file) as f:
H
HexToString 已提交
30
    query_count = 0
M
MRXLT 已提交
31 32 33
    for line in f.readlines():
        line = line.strip().split("\t")
        if line[0] == "PROFILE":
M
MRXLT 已提交
34
            prase(line[2])
H
HexToString 已提交
35
            query_count += 1
M
MRXLT 已提交
36

G
gentelyang 已提交
37
print("thread_num: {}".format(thread_num))
H
HexToString 已提交
38
print("query_count: {}".format(query_count))
M
MRXLT 已提交
39
for name in time_dict:
G
gentelyang 已提交
40
    print("{} cost: {}s in each thread ".format(name, time_dict[name] / (
M
MRXLT 已提交
41
        1000000.0 * float(thread_num))))