Skip to content

Commit 16bd4a1

Browse files
committed
[delta_q] add extractor scripts for simulation logs (not yet complete)
1 parent bab19a9 commit 16bd4a1

File tree

3 files changed

+148
-8
lines changed

3 files changed

+148
-8
lines changed

delta_q/comparison_hs.txt

Lines changed: 6 additions & 8 deletions
Large diffs are not rendered by default.

delta_q/diffusion.jq

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env jq -crnf
2+
3+
def fmt: . * 1000 | round | . / 1000;
4+
5+
def hist($max; $bins; src): reduce src as $in (
6+
{ bins: $bins, max: $max, hist: [range(0; $bins) | 0] };
7+
.hist[fmin($in / $max * $bins | floor; $bins - 1)] += 1
8+
);
9+
10+
# takes a hist and transforms it into a CDF string
11+
def cdf: last(.hist[]) as $sum |
12+
. as { bins: $b, max: $m, hist: $h } |
13+
($h | $m / length) as $bin_size |
14+
$h | keys | reduce .[] as $idx (
15+
[0, []];
16+
($h[$idx] / $sum|fmt) as $y |
17+
if $y == .[0] then .
18+
else (.[1] += ["(\($idx * $bin_size|fmt),\($y))"]) | .[0] = $y
19+
end
20+
) | .[1] | "CDF[\(join(","))]";
21+
22+
# `gen`: extract [type, id, time] of data generation, or empty
23+
# `recv`: extract [type, id, time] of data reception, or empty
24+
def read_log(in; gen; recv): reduce in as $in (
25+
{}; # { [type]: { [id]: [start, latency[]] }}
26+
def g: ($in | gen) as [$type, $id, $time] |
27+
setpath([$type, $id]; [$time, []]);
28+
def r: ($in | recv) as [$type, $id, $time] |
29+
.[$type][$id] |= . as [$t, $l] | [$t, $l + [$time - $t]];
30+
g // r // .
31+
) | map_values(
32+
(map(.[1]|length)|max) as $max |
33+
map_values(
34+
.[1] | select(length == $max) | hist(10; 100; .[])
35+
)
36+
);
37+
38+
def cumulative: .hist |= [foreach .[] as $in (0; . + $in; .)];
39+
40+
# turns an object with hist values into a single hist
41+
def hist_combine(combine): reduce .[] as $in (
42+
null;
43+
if . == null then $in
44+
else .hist |= . as $h | keys | [.[] | [$h[.], $in.hist[.] // 0] | combine]
45+
end
46+
);
47+
48+
def hist_min: hist_combine(fmin(.[0]; .[1]));
49+
def hist_max: hist_combine(fmax(.[0]; .[1]));
50+
def hist_avg: (1 / length) as $scale | hist_combine(.[0] + $scale * .[1]);
51+
52+
def min_max: map(cumulative) | {
53+
min: (hist_min | cdf),
54+
max: (hist_max | cdf),
55+
avg: (hist_avg | cdf)
56+
};
57+
58+
def print: . as $all | [
59+
paths(type == "string") |
60+
. as $path |
61+
"\(join("_")) := \($all | getpath($path))"
62+
] | join("\n");
63+
64+
read_log(limit(1000000; inputs);
65+
select(.event.tag=="generated")|[.event.kind, .event.id, .time_s];
66+
select(.event.tag=="received")|[.event.kind, .event.id, .time_s])
67+
| map_values(min_max)
68+
| print

delta_q/one_hop.jq

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env jq -cnf
2+
3+
def read_rs($emit; key_in; key_out): foreach (range(1; 1000000) | input) as $in (
4+
[{}];
5+
(.[0] as $state |
6+
($in.message.type | capture("(?<obj>.*)(?<dir>Sent|Received)$")) as { obj: $obj, dir: $dir } |
7+
($in.message.id | tostring) as $id |
8+
if $dir == $emit then
9+
$state |
10+
($in.message | key_out) as $key |
11+
(getpath([$obj, $key.[], $id]) // empty) as $time |
12+
delpaths([[$obj, $key.[], $id]]) |
13+
[., [$obj, ($in.time - $time) / 1000000]]
14+
else
15+
$state |
16+
($in.message | key_in) as $key |
17+
setpath([$obj, $key.[], $id]; $in.time) |
18+
[.]
19+
end
20+
) // [.[0]];
21+
.[1] // empty
22+
);
23+
24+
def read_hs($store; key_in; $emit; key_out): foreach inputs as $in (
25+
[{}];
26+
(.[0] as $state |
27+
$in.event as { tag: $dir, kind: $obj } |
28+
select($dir == $store or $dir == $emit) |
29+
($in.event.id // $in.event.ids[0]) as $id |
30+
if $dir == $emit then
31+
$state |
32+
($in.event | key_out) as $key |
33+
(getpath([$obj, $key.[], $id]) // empty) as $time |
34+
delpaths([[$obj, $key.[], $id]]) |
35+
[., [$obj, ($in.time_s - $time) * 1000]]
36+
else
37+
$state |
38+
($in.event | key_in) as $key |
39+
setpath([$obj, $key.[], $id]; $in.time_s) |
40+
[.]
41+
end
42+
) // [.[0]];
43+
.[1] // empty
44+
);
45+
46+
def histogram(src): reduce src as $in (
47+
{};
48+
.[$in[0]][$in[1] | tostring] += 1
49+
);
50+
51+
def histogram_binned($max; $bins; src): reduce src as $in (
52+
{};
53+
.[$in[0]][fmin($in[1] / $max * $bins | floor; $bins - 1)] += 1
54+
);
55+
56+
########
57+
# Rust #
58+
########
59+
60+
# delay between receiving a message and sending it on
61+
#histogram(read_rs("Sent"; [.recipient]; [.sender]))
62+
63+
# message propagation time
64+
#histogram(read_rs("Received"; [.sender, .recipient]; [.sender, .recipient]))
65+
66+
###########
67+
# Haskell #
68+
###########
69+
70+
# delay between receiving a message and sending it on
71+
#histogram_binned(1000; 20; read_hs("received"; [.node]; "Sent"; [.sender]))
72+
73+
# message propagation time
74+
histogram_binned(1000; 20; read_hs("Sent"; [.receipient]; "received"; [.node]))

0 commit comments

Comments
 (0)