-
Notifications
You must be signed in to change notification settings - Fork 13
Use trace instead of tracing #57
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 32 additions & 17 deletions
49
lib/olly_trace/olly_format_backend/olly_format_fuchsia.ml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,56 @@ | ||
open Olly_format_backend | ||
open Tracing | ||
|
||
let name = "fuchsia" | ||
let description = "Perfetto" | ||
|
||
type trace = { doms : Trace.Thread.t array; file : Trace.t } | ||
module Trace = Trace_fuchsia.Writer | ||
|
||
type trace = { | ||
doms : Trace.Thread_ref.t array; | ||
buf : Trace_fuchsia.Buf_chain.t; | ||
subscriber : Trace_fuchsia.Subscriber.t; | ||
exporter : Trace_fuchsia.Exporter.t; | ||
} | ||
|
||
let flush trace = | ||
Trace_fuchsia.Buf_chain.ready_all_non_empty trace.buf; | ||
Trace_fuchsia.Buf_chain.pop_ready trace.buf ~f:trace.exporter.write_bufs; | ||
trace.exporter.flush () | ||
|
||
let create ~filename = | ||
let file = Trace.create_for_file ~base_time:None ~filename in | ||
let buf_pool = Trace_fuchsia.Buf_pool.create () in | ||
let buf = Trace_fuchsia.Buf_chain.create ~sharded:false ~buf_pool () in | ||
let oc = Out_channel.open_bin filename in | ||
let exporter = Trace_fuchsia.Exporter.of_out_channel ~close_channel:true oc in | ||
let subscriber = Trace_fuchsia.Subscriber.create ~buf_pool ~pid:0 ~exporter () in | ||
(* Adds the headers to output *) | ||
Trace_fuchsia.Subscriber.Callbacks.on_init subscriber ~time_ns:0L; | ||
let doms = | ||
let max_doms = 128 in | ||
Array.init max_doms (fun i -> | ||
(* Use a different pid for each domain *) | ||
Trace.allocate_thread file ~pid:i ~name:(Printf.sprintf "Ring_id %d" i)) | ||
Trace.Thread_ref.ref (i + 1)) | ||
in | ||
{ doms; file } | ||
{ doms; buf; subscriber; exporter } | ||
|
||
let close trace = Trace.close trace.file | ||
let ts_to_span ts = ts |> Int64.to_int |> Core.Time_ns.Span.of_int_ns | ||
let close trace = | ||
flush trace; | ||
Trace_fuchsia.Subscriber.close trace.subscriber | ||
|
||
let emit trace evt = | ||
let open Event in | ||
let thread = trace.doms.(evt.ring_id) | ||
and category = "PERF" | ||
and time = ts_to_span evt.ts | ||
let t_ref = trace.doms.(evt.ring_id) | ||
and time_ns = evt.ts | ||
and name = evt.name in | ||
match evt.kind with | ||
| SpanBegin | SpanEnd -> | ||
let write = | ||
if evt.kind = SpanBegin then Trace.write_duration_begin | ||
else Trace.write_duration_end | ||
if evt.kind = SpanBegin then Trace.Event.Duration_begin.encode | ||
else Trace.Event.Duration_end.encode | ||
in | ||
write trace.file ~args:[] ~thread ~category ~name ~time | ||
write trace.buf ~args:[] ~t_ref ~name ~time_ns () | ||
| Counter value -> | ||
Trace.write_counter trace.file ~thread ~category ~name ~time | ||
~args:[ ("v", Int value) ] | ||
Trace.Event.Counter.encode trace.buf ~t_ref ~name ~time_ns ~args:[ ("v", A_int value) ] () | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, with subscriber |
||
| Instant -> | ||
Trace.write_duration_instant trace.file ~args:[] ~thread ~category ~name | ||
~time | ||
Trace.Event.Instant.encode trace.buf ~name ~args:[] ~t_ref ~time_ns () | ||
| _ -> () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could direct use the
Trace_fuchsia.Subscriber' callbacks here, too, without going through
Trace.Event`.