Skip to content

Commit 9495c51

Browse files
committed
sim-rs: return timestamps in f64 seconds
1 parent 8f6f103 commit 9495c51

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

sim-rs/sim-core/src/clock/timestamp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Serialize for Timestamp {
4343
where
4444
S: serde::Serializer,
4545
{
46-
serializer.serialize_u128(self.0.as_nanos())
46+
serializer.serialize_f32(self.0.as_secs_f32())
4747
}
4848
}
4949

sim-rs/sim-core/src/events.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub enum Event {
7272
CpuSubtaskStarted {
7373
task: CpuTaskId<Node>,
7474
subtask_id: u64,
75-
#[serde(serialize_with = "duration_as_nanos")]
75+
#[serde(serialize_with = "duration_as_secs")]
7676
duration: Duration,
7777
},
7878
TransactionGenerated {
@@ -473,6 +473,6 @@ impl EventTracker {
473473
}
474474
}
475475

476-
fn duration_as_nanos<S: Serializer>(duration: &Duration, serializer: S) -> Result<S::Ok, S::Error> {
477-
serializer.serialize_u128(duration.as_nanos())
476+
fn duration_as_secs<S: Serializer>(duration: &Duration, serializer: S) -> Result<S::Ok, S::Error> {
477+
serializer.serialize_f32(duration.as_secs_f32())
478478
}

ui/src/app/api/messages/batch/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function getTimestampAtPosition(
4343

4444
rl.on("line", (line) => {
4545
const message: IServerMessage = JSON.parse(line);
46-
const timestamp = message.time / 1_000_000;
46+
const timestamp = message.time;
4747
rl.close();
4848
resolve(timestamp);
4949
});
@@ -161,7 +161,7 @@ export async function GET(req: Request, res: Response) {
161161

162162
const serializedData = {
163163
...aggregatedData,
164-
progress: JSON.parse(batch[batch.length - 1]).time / 1_000_000,
164+
progress: JSON.parse(batch[batch.length - 1]).time,
165165
nodes: Array.from(aggregatedData.nodes.entries()),
166166
lastNodesUpdated: [...nodesUpdated],
167167
};

ui/src/app/api/messages/batch/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export function getTimestampAtPosition(
282282

283283
rl.on("line", (line) => {
284284
const message: IServerMessage = JSON.parse(line);
285-
const timestamp = message.time / 1_000_000;
285+
const timestamp = message.time;
286286
rl.close();
287287
resolve(timestamp);
288288
});

ui/src/app/queries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const getSetSimulationMaxTime = async (): Promise<number> => {
7575
reject("Could not find the last transaction.");
7676
} else {
7777
const message: IServerMessage = JSON.parse(lastLine.trim());
78-
resolve(message.time / 1_000_000);
78+
resolve(message.time);
7979
}
8080
});
8181
};

ui/src/components/Sim/modules/Slider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export const Progress: FC = () => {
88

99
const percent = (aggregatedData.progress / maxTime) * 100;
1010

11-
const minutes = Math.floor(aggregatedData.progress / 60_000);
12-
const seconds = (aggregatedData.progress / 1000 % 60).toFixed(3);
11+
const minutes = Math.floor(aggregatedData.progress / 60);
12+
const seconds = (aggregatedData.progress % 60).toFixed(3);
1313
const time = minutes ? `${minutes}m${seconds}s` : `${seconds}s`;
1414

1515
return (

0 commit comments

Comments
 (0)