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 1433226 commit 6f92b65
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/c++/perf_analyzer/docs/examples/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,24 @@ def load_profile_data():
return json.load(f)


def calculate_avg_latencies():
def collect_latencies(requests):
# Example json demonstrating format:
# see client/src/c++/perf_analyzer/docs/examples/decoupled_output_file.json
first_token_latencies = []
token_to_token_latencies = []

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

requests = requests["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
return first_token_latencies, token_to_token_latencies


def calculate_avg_latencies():
requests = load_profile_data()
first_token_latencies, token_to_token_latencies = collect_latencies(requests)

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

0 comments on commit 6f92b65

Please sign in to comment.