Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mix python script for new log format #53

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions scripts/latency.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
# !/usr/bin/env python
import argparse
import json
import sys
import statistics
from collections.abc import Iterable
from typing import Dict, Optional
import statistics
import argparse

import mixlog

from json_stream.base import TransientStreamingJSONObject

JsonStream = Iterable[TransientStreamingJSONObject]


class Message:
def __init__(self, message_id: str, step_a: Optional[int]):
Expand Down Expand Up @@ -73,8 +68,13 @@ def parse_record_stream(record_stream: Iterable[str]) -> MessageStorage:
storage: MessageStorage = {}

for record in record_stream:
json_record = json.loads(record)
payload_id = json_record["payload_id"]
try:
json_record = json.loads(record)
except json.decoder.JSONDecodeError:
continue

if (payload_id := json_record.get("payload_id")) is None:
continue
step_id = json_record["step_id"]

if (stored_message := storage.get(payload_id)) is None:
Expand All @@ -91,12 +91,12 @@ def build_argument_parser() -> argparse.ArgumentParser:
"--step-duration",
type=int,
default=100,
help="Duration (in ms) of each step in the simulation."
help="Duration (in ms) of each step in the simulation.",
)
parser.add_argument(
"input_file",
nargs="?",
help="The file to parse. If not provided, input will be read from stdin."
help="The file to parse. If not provided, input will be read from stdin.",
)
return parser

Expand Down