| 469 | } |
| 470 | |
| 471 | def process_one_metric( |
| 472 | # E.g., "ttft" |
| 473 | metric_attribute_name: str, |
| 474 | # E.g., "TTFT" |
| 475 | metric_name: str, |
| 476 | # E.g., "Time to First Token" |
| 477 | metric_header: str, |
| 478 | ): |
| 479 | # This function prints and adds statistics of the specified |
| 480 | # metric. |
| 481 | if metric_attribute_name not in selected_percentile_metrics: |
| 482 | return |
| 483 | print("{s:{c}^{n}}".format(s=metric_header, n=50, c="-")) |
| 484 | print( |
| 485 | "{:<40} {:<10.2f}".format( |
| 486 | f"Mean {metric_name} (ms):", |
| 487 | getattr(metrics, f"mean_{metric_attribute_name}_ms"), |
| 488 | ) |
| 489 | ) |
| 490 | print( |
| 491 | "{:<40} {:<10.2f}".format( |
| 492 | f"Median {metric_name} (ms):", |
| 493 | getattr(metrics, f"median_{metric_attribute_name}_ms"), |
| 494 | ) |
| 495 | ) |
| 496 | result[f"mean_{metric_attribute_name}_ms"] = getattr(metrics, f"mean_{metric_attribute_name}_ms") |
| 497 | result[f"median_{metric_attribute_name}_ms"] = getattr(metrics, f"median_{metric_attribute_name}_ms") |
| 498 | result[f"std_{metric_attribute_name}_ms"] = getattr(metrics, f"std_{metric_attribute_name}_ms") |
| 499 | for p, value in getattr(metrics, f"percentiles_{metric_attribute_name}_ms"): |
| 500 | p_word = str(int(p)) if int(p) == p else str(p) |
| 501 | print("{:<40} {:<10.2f}".format(f"P{p_word} {metric_name} (ms):", value)) |
| 502 | result[f"p{p_word}_{metric_attribute_name}_ms"] = value |
| 503 | |
| 504 | def process_one_length( |
| 505 | # E.g., "ttft" |