-
Notifications
You must be signed in to change notification settings - Fork 96
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
Add support for magic-trace to sample and show other events such as cache misses and branch misses #234
Merged
Merged
Add support for magic-trace to sample and show other events such as cache misses and branch misses #234
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dd45f61
Updated perf decoding to process event types and periods and use even…
lamoreauxaj 3548c62
Updated `Collection_mode` to allow passing additional sampled events …
lamoreauxaj 84a6ade
Updated `perf_decode.ml` to handle decoding additional sampled events
lamoreauxaj 8cd1e2a
Updated `trace_writer.ml` to write new sampled events
lamoreauxaj db27094
Added decoding/trace writing tests for sampling extra events
lamoreauxaj 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 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,28 +1,93 @@ | ||
open! Core | ||
|
||
module Event = struct | ||
module Name = struct | ||
type t = | ||
| Branch_misses | ||
| Cache_misses | ||
[@@deriving compare, hash, sexp] | ||
|
||
let to_string = function | ||
| Branch_misses -> "branch-misses" | ||
| Cache_misses -> "cache-misses" | ||
;; | ||
end | ||
|
||
module When_to_sample = struct | ||
type t = | ||
| Frequency of int | ||
| Period of int | ||
[@@deriving of_sexp] | ||
end | ||
|
||
module Precision = struct | ||
type t = | ||
| Arbitrary_skid | ||
| Constant_skid | ||
| Request_zero_skid | ||
| Zero_skid | ||
| Maximum_possible | ||
[@@deriving of_sexp] | ||
end | ||
|
||
type t = | ||
{ when_to_sample : When_to_sample.t | ||
; name : Name.t | ||
; precision : Precision.t | ||
} | ||
[@@deriving of_sexp] | ||
|
||
let of_string = function | ||
| "branch-misses" -> | ||
{ when_to_sample = Period 50; name = Branch_misses; precision = Maximum_possible } | ||
| "cache-misses" -> | ||
{ when_to_sample = Period 1; name = Cache_misses; precision = Maximum_possible } | ||
| str -> t_of_sexp (Sexp.of_string str) | ||
;; | ||
|
||
let arg_type = Command.Arg_type.create of_string | ||
end | ||
|
||
type t = | ||
| Intel_processor_trace | ||
| Stacktrace_sampling | ||
| Intel_processor_trace of { extra_events : Event.t list } | ||
| Stacktrace_sampling of { extra_events : Event.t list } | ||
|
||
let extra_events = function | ||
| Intel_processor_trace { extra_events } | Stacktrace_sampling { extra_events } -> | ||
extra_events | ||
;; | ||
|
||
let select_collection_mode ~use_sampling = | ||
let select_collection_mode ~extra_events ~use_sampling = | ||
match use_sampling with | ||
| true -> Stacktrace_sampling | ||
| true -> Stacktrace_sampling { extra_events } | ||
| false -> | ||
(match Core_unix.access "/sys/bus/event_source/devices/intel_pt" [ `Exists ] with | ||
| Ok () -> Intel_processor_trace | ||
| Ok () -> Intel_processor_trace { extra_events } | ||
| Error _ -> | ||
Core.printf | ||
"Intel PT support not found. magic-trace will continue and use sampling instead."; | ||
Stacktrace_sampling) | ||
Core.eprintf | ||
"Intel PT support not found. magic-trace will continue and use sampling instead.\n"; | ||
Stacktrace_sampling { extra_events }) | ||
;; | ||
|
||
let param = | ||
Command.Param.( | ||
let%map_open.Command extra_events = | ||
flag | ||
"-events" | ||
(optional_with_default | ||
[] | ||
(Command.Arg_type.comma_separated ~unique_values:true Event.arg_type)) | ||
~doc: | ||
"EVENTS Select additional events which can be sampled as a comma separated list. \ | ||
Valid options are [cache-misses] or [branch-misses]. For more info: \ | ||
https://magic-trace.org/w/e" | ||
|> Util.experimental_flag ~default:[] | ||
and use_sampling = | ||
flag | ||
"-sampling" | ||
no_arg | ||
~doc: | ||
"Use stacktrace sampling instead of Intel PT. If Intel PT is not available, \ | ||
magic-trace will default to this." | ||
|> map ~f:(fun use_sampling -> select_collection_mode ~use_sampling)) | ||
in | ||
select_collection_mode ~extra_events ~use_sampling | ||
;; |
This file contains 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,7 +1,40 @@ | ||
open! Core | ||
|
||
module Event : sig | ||
module Name : sig | ||
type t = | ||
| Branch_misses | ||
| Cache_misses | ||
[@@deriving compare, hash, sexp] | ||
|
||
val to_string : t -> string | ||
end | ||
|
||
module When_to_sample : sig | ||
type t = | ||
| Frequency of int | ||
| Period of int | ||
end | ||
|
||
module Precision : sig | ||
type t = | ||
| Arbitrary_skid | ||
| Constant_skid | ||
| Request_zero_skid | ||
| Zero_skid | ||
| Maximum_possible | ||
end | ||
|
||
type t = | ||
{ when_to_sample : When_to_sample.t | ||
; name : Name.t | ||
; precision : Precision.t | ||
} | ||
end | ||
|
||
type t = | ||
| Intel_processor_trace | ||
| Stacktrace_sampling | ||
| Intel_processor_trace of { extra_events : Event.t list } | ||
| Stacktrace_sampling of { extra_events : Event.t list } | ||
|
||
val extra_events : t -> Event.t list | ||
val param : t Command.Param.t |
This file contains 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 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,6 +1,7 @@ | ||
open! Core | ||
|
||
val debug : bool | ||
val experimental : bool | ||
val perf_is_privileged : bool | ||
val perfetto_dir : string option | ||
val no_dlfilter : bool |
This file contains 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 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 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 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 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 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.
@Xyene a couple things to think about here. One, what do you think are good defaults for precision and when_to_sample? Two, do you think there should be an alternative to the sexp in order to control when_to_sample / precision?