diff --git a/python/examples/bert/benchmark.sh b/python/examples/bert/benchmark.sh index 9a2fa2d8f3440cf8f7dd1bf69707b8e0414c703e..10e6fb8f867b909ef217bbf50dfbfd929c4b2770 100644 --- a/python/examples/bert/benchmark.sh +++ b/python/examples/bert/benchmark.sh @@ -2,6 +2,6 @@ rm profile_log for thread_num in 1 4 8 12 16 20 24 do $PYTHONROOT/bin/python benchmark.py serving_client_conf/serving_client_conf.prototxt data.txt $thread_num $batch_size > profile 2>&1 - $PYTHONROOT/bin/python ../imdb/show_profile.py profile $thread_num >> profile_log + $PYTHONROOT/bin/python ../util/show_profile.py profile $thread_num >> profile_log tail -n 1 profile >> profile_log done diff --git a/python/examples/bert/benchmark_batch.sh b/python/examples/bert/benchmark_batch.sh index 31965cf53c8afd9591ecf570994c3c60653e9962..2f9fa4d1002837cb4313332331ea66460f6c411d 100644 --- a/python/examples/bert/benchmark_batch.sh +++ b/python/examples/bert/benchmark_batch.sh @@ -3,6 +3,6 @@ thread_num=1 for batch_size in 1 4 8 16 32 64 128 256 do $PYTHONROOT/bin/python benchmark_batch.py serving_client_conf/serving_client_conf.prototxt data.txt $thread_num $batch_size > profile 2>&1 - $PYTHONROOT/bin/python ../imdb/show_profile.py profile $thread_num >> profile_log + $PYTHONROOT/bin/python ../util/show_profile.py profile $thread_num >> profile_log tail -n 1 profile >> profile_log done diff --git a/python/examples/imdb/show_profile.py b/python/examples/util/show_profile.py similarity index 100% rename from python/examples/imdb/show_profile.py rename to python/examples/util/show_profile.py diff --git a/python/examples/util/timeline_trace.py b/python/examples/util/timeline_trace.py new file mode 100644 index 0000000000000000000000000000000000000000..e8bffedfbde3d0ff00d398172303da6d91d04b61 --- /dev/null +++ b/python/examples/util/timeline_trace.py @@ -0,0 +1,46 @@ +#coding=utf-8 +import json +import sys + +profile_file = sys.argv[1] + + +def prase(line, counter): + event_list = line.split(" ") + trace_list = [] + for event in event_list: + name, ts = event.split(":") + name_list = name.split("_") + ph = "B" if (name_list[-1] == "0") else "E" + if len(name_list) == 2: + name = name_list[0] + else: + name = name_list[0] + "_" + name_list[1] + event_dict = {} + event_dict["name"] = name + event_dict["tid"] = 0 + event_dict["pid"] = 0 + event_dict["ts"] = ts + event_dict["ph"] = ph + + trace_list.append(event_dict) + return trace_list + + +if __name__ == "__main__": + profile_file = sys.argv[1] + trace_file = sys.argv[2] + all_list = [] + counter = 0 + with open(profile_file) as f: + for line in f.readlines(): + line = line.strip().split("\t") + if line[0] == "PROFILE": + trace_list = prase(line[1], counter) + counter += 1 + for trace in trace_list: + all_list.append(trace) + + trace = json.dumps(all_list, indent=2, separators=(',', ':')) + with open(trace_file, "w") as f: + f.write(trace)