Skip to content

Commit f38d813

Browse files
happyandslowLe Xu
and
Le Xu
authored
[fix] Handle error output in analysis script (#975)
Handle error output in analysis script Signed-off-by: Le Xu <[email protected]> Co-authored-by: Le Xu <[email protected]>
1 parent ab7d73b commit f38d813

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

Diff for: benchmarks/client/analyze.py

+26-9
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,31 @@ def main(args):
2525
for line in f:
2626
data.append(json.loads(line))
2727
# Extract metrics
28-
timestamps = [item.get("start_time", f"Entry {i}") for i, item in enumerate(data)]
29-
prompt_tokens = [item["prompt_tokens"] for item in data]
30-
output_tokens = [item["output_tokens"] for item in data]
31-
total_tokens = [item["total_tokens"] for item in data]
32-
latencies = [item["latency"] for item in data]
33-
throughputs = [item["throughput"] for item in data]
34-
tokens_per_second = [item["total_tokens"] / item["latency"] for item in data]
35-
ttft = [item["ttft"] if "ttft" in item else 0.0 for item in data] # Time to First Token
36-
tpot = [item["tpot"] if "tpot" in item else 0.0 for item in data] # Time per Output Token
28+
prompt_tokens = []
29+
output_tokens = []
30+
total_tokens = []
31+
latencies = []
32+
throughputs = []
33+
tokens_per_second = []
34+
ttft = []
35+
tpot = []
36+
total_errors = 0
37+
timestamps = []
38+
for i, item in enumerate(data):
39+
if item["status"] == "error":
40+
total_errors += 1
41+
else:
42+
if "prompt_tokens" not in item:
43+
print(item)
44+
timestamps.append(item.get("start_time", f"Entry {i}"))
45+
prompt_tokens.append(item["prompt_tokens"]) # Prompt tokens
46+
output_tokens.append(item["output_tokens"])
47+
total_tokens.append(item["total_tokens"])
48+
latencies.append(item["latency"])
49+
throughputs.append(item["throughput"])
50+
tokens_per_second.append(item["total_tokens"] / item["latency"])
51+
ttft.append(item["ttft"] if "ttft" in item else 0.0) # Time to First Token
52+
tpot.append(item["tpot"] if "tpot" in item else 0.0)# Time per Output Token
3753
goodput = None
3854
if args.goodput_target is not None:
3955
metric, threshold = parse_goodput_target(args.goodput_target)
@@ -90,6 +106,7 @@ def calculate_statistics(values):
90106
print(f"{metric} Statistics: Average = {avg:.4f}, Median = {median:.4f}, 99th Percentile = {p99:.4f}")
91107
if goodput != None:
92108
print(f"Goodput (reqs/s) {goodput:.4f}")
109+
print(f"Failure Rate (%) {(total_errors / len(data)) * 100 if len(data) > 0 else 0}")
93110

94111
# Create a DataFrame for plotting
95112
df = pd.DataFrame({

0 commit comments

Comments
 (0)