Skip to content

Commit 9f6e11d

Browse files
committed
Press F5 to reload
1 parent 7035c4a commit 9f6e11d

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ dune build && eio-trace run -- ./_build/default/examples/net/main.exe
5959

6060
Scrolling with the mouse or touchpad will zoom in or out of the diagram.
6161

62+
If the program is still running when the window appears, you can press F5 to update to the latest events.
63+
6264
To record a trace:
6365

6466
```

gtk/gtk_ui.ml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ open Eio_trace
33
let ( ==> ) signal callback =
44
ignore (signal ~callback : GtkSignal.id)
55

6-
let create ~title layout =
6+
let create ~title tracefile =
77
let window = GWindow.window () in
88
window#set_title title;
99
window#event#connect#delete ==> (fun _ -> GMain.quit (); true);
@@ -13,7 +13,10 @@ let create ~title layout =
1313
let area = GMisc.drawing_area ~packing:(table#attach ~left:0 ~top:0 ~expand:`BOTH ~fill:`BOTH) () in
1414
let _hscroll = GRange.scrollbar `HORIZONTAL ~adjustment:hadjustment ~packing:(table#attach ~left:0 ~top:1 ~expand:`X ~fill:`BOTH) () in
1515
let _vscroll = GRange.scrollbar `VERTICAL ~adjustment:vadjustment ~packing:(table#attach ~left:1 ~top:0 ~expand:`Y ~fill:`BOTH) () in
16-
let v = View.of_layout layout ~width:1000. ~height:1000. in
16+
let v =
17+
let layout = Layout.load tracefile in
18+
View.of_layout layout ~width:1000. ~height:1000.
19+
in
1720
let set_scollbars () =
1821
let (xlo, xhi, xsize, xvalue), (ylo, yhi, ysize, yvalue) = View.scroll_bounds v in
1922
hadjustment#set_bounds ~lower:xlo ~upper:xhi ~page_size:xsize ();
@@ -45,6 +48,18 @@ let create ~title layout =
4548
true
4649
);
4750
area#misc#set_app_paintable true;
51+
52+
window#event#connect#key_press ==> (fun ev ->
53+
let keyval = GdkEvent.Key.keyval ev in
54+
if keyval = GdkKeysyms._F5 then (
55+
let layout = Layout.load tracefile in
56+
View.set_layout v layout;
57+
set_scollbars ();
58+
redraw ();
59+
true
60+
) else false
61+
);
62+
4863
area#event#add [`SMOOTH_SCROLL; `BUTTON1_MOTION; `BUTTON_PRESS];
4964
area#event#connect#scroll ==> (fun ev ->
5065
let x = GdkEvent.Scroll.x ev in

gtk/main.ml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ let format_of_string = function
77
| ".png" -> `Png
88
| x -> Fmt.failwith "Unknown format %S (should be .svg or .png)" x
99

10-
let load tracefile =
11-
let ch = open_in_bin tracefile in
12-
let len = in_channel_length ch in
13-
let data = really_input_string ch len in
14-
close_in ch;
15-
let trace = Trace.create data in
16-
Layout.of_trace trace
17-
1810
let show ?args tracefile =
1911
let title =
2012
match args with
@@ -25,7 +17,7 @@ let show ?args tracefile =
2517
| Some args ->
2618
String.concat " " args
2719
in
28-
Gtk_ui.create ~title (load tracefile)
20+
Gtk_ui.create ~title tracefile
2921

3022
let render ?output ~start_time ?duration ~format tracefile =
3123
let output =
@@ -34,7 +26,7 @@ let render ?output ~start_time ?duration ~format tracefile =
3426
| None -> Filename.remove_extension tracefile ^ format
3527
in
3628
let format = format_of_string format in
37-
let l = load (tracefile) in
29+
let l = Layout.load (tracefile) in
3830
let v =
3931
View.of_layout l
4032
~width:1280.

lib/layout.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,11 @@ let of_trace (trace : Trace.t) =
242242
let start_time t = t.start_time
243243

244244
let ring t id = Trace.Rings.find id t.rings
245+
246+
let load tracefile =
247+
let ch = open_in_bin tracefile in
248+
let len = in_channel_length ch in
249+
let data = really_input_string ch len in
250+
close_in ch;
251+
let trace = Trace.create data in
252+
of_trace trace

lib/view.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
type t = {
2-
layout : Layout.t;
2+
mutable layout : Layout.t;
33
mutable width : float; (* Canvas width in pixels *)
44
mutable height : float;
55
mutable start_time : float; (* Time after layout start (ns) *)
@@ -78,3 +78,6 @@ let of_layout layout ~width ~height =
7878
let t = { layout; width; height; start_time = 0.; scroll_y = -. v_margin; pixels_per_ns = 0.0; zoom = -3.0 } in
7979
zoom t 0.0;
8080
t
81+
82+
let set_layout t layout =
83+
t.layout <- layout

0 commit comments

Comments
 (0)