Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rakudo/rakudo into build-…
Browse files Browse the repository at this point in the history
…revamp
  • Loading branch information
vrurg committed May 24, 2019
2 parents 09b9e06 + 966790a commit bba187b
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions lib/MoarVM/Profiler.pm6
Expand Up @@ -71,6 +71,14 @@ class MoarVM::Profiler::Allocation does OnHash[<

method thread() { self.callee.thread }
method name() { self.thread.type_by_id($.id).name }
method file() { self.callee.file }
method line() { self.callee.line }

method gist() {
my $gist = "Allocated $.count objects of $.name";
$gist ~= " (JITted $.jit)" if $.jit;
$gist ~ "\n at $.file line $.line"
}
}

# Information about a Callable that has been called at least once.
Expand Down Expand Up @@ -164,15 +172,15 @@ class MoarVM::Profiler::Type does OnHash[<
managed_size
repr
type
name
has_unmanaged_data
>] {
has Int $.id;
has Str $.name;
has %.threads; # set by MoarVM::Profiler.new

method new( ($id,%hash) ) { self.bless(:$id, :%hash) }
method TWEAK() {
%!hash.BIND-KEY('name',(try .^name) || "(" ~ nqp::objectid($_) ~ ")")
$!name := (try .^name) || "(" ~ nqp::objectid($_) ~ ")"
given %!hash<type>;
}

Expand Down Expand Up @@ -214,6 +222,13 @@ class MoarVM::Profiler::Thread does OnHash[<
method nr_jitted(--> Int:D) { self.callee.nr_jitted }
method nr_osred(--> Int:D) { self.callee.nr_osred }
method nr_gcs(--> Int:D) { +self.gcs }

method callees_by_file(\matcher) {
self.all_callees.grep({ matcher.ACCEPTS(.file) })
}
method allocations_by_file(\matcher) {
self.callees_by_file(matcher).map: *.allocations
}
}

# Main object returned by profile() and friends.
Expand Down Expand Up @@ -256,7 +271,14 @@ class MoarVM::Profiler {
method all_callees() { %!threads.values.map: |*.all_callees }
method all_allocations() { %!threads.values.map: |*.all_allocations }

method report(--> Str:D) {
method callees_by_file(\matcher) {
self.all_callees.grep({ matcher.ACCEPTS(.file) })
}
method allocations_by_file(\matcher) {
self.callees_by_file(matcher).map: *.allocations
}

method gist(--> Str:D) {
(
" # wallclock objects frames inlined jitted OSR GCs",
"----+-----------+---------+---------+---------+---------+-----+-----",
Expand All @@ -276,9 +298,7 @@ class MoarVM::Profiler {
).join("\n")
}

method sink(--> Nil) {
note self.report;
}
method sink(--> Nil) { note self }
}

# Raw subs, for cases where starting an extra scope would be troublesome
Expand All @@ -290,6 +310,12 @@ sub profile_end(--> MoarVM::Profiler:D) is export {
MoarVM::Profiler.new(nqp::mvmendprofile)
}

sub profile_rest(--> Nil) is export {
nqp::mvmstartprofile({:instrumented});
my $end-profile = True;
END MoarVM::Profiler.new(nqp::mvmendprofile) if $end-profile;
}

# HLL sub for profiling a piece of code and getting the info from that
sub profile(&code --> MoarVM::Profiler:D) is export {
nqp::mvmstartprofile({:instrumented});
Expand Down

0 comments on commit bba187b

Please sign in to comment.