Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nv-hwoo committed Oct 4, 2023
1 parent 7df7412 commit 1433226
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/c++/perf_analyzer/docs/examples/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,27 @@
TEMP_INPUT_FILE = "temp_input_data.json"


def load_profile_data():
with open("profile_export.json") as f:
return json.load(f)


def calculate_avg_latencies():
# Example json demonstrating format:
# see client/src/c++/perf_analyzer/docs/examples/decoupled_output_file.json
first_token_latencies = []
token_to_token_latencies = []
with open("profile_export.json") as f:
requests = json.load(f)["experiments"][0]["requests"]
for request in requests:
prev_response = request["response_timestamps"][0]
first_token_latencies.append(prev_response - request["timestamp"])
for response in request["response_timestamps"][1:]:
token_to_token_latencies.append(response - prev_response)
prev_response = response

# Compute mean and conversion from nanosec to sec

requests = load_profile_data()["experiments"][0]["requests"]

for request in requests:
prev_response = request["response_timestamps"][0]
first_token_latencies.append(prev_response - request["timestamp"])
for response in request["response_timestamps"][1:]:
token_to_token_latencies.append(response - prev_response)
prev_response = response

# Compute mean and convert from nanosec to sec
avg_first_token_latency = mean(first_token_latencies) / 1_000_000_000
avg_token_to_token_latency = mean(token_to_token_latencies) / 1_000_000_000
return avg_first_token_latency, avg_token_to_token_latency
Expand Down

0 comments on commit 1433226

Please sign in to comment.