Permalink
Browse files

Add a call graph analyzer

  • Loading branch information...
1 parent 3f34bbc commit e5c3ac0b38e228ae1bf2bb186af7adf39db3e300 @sorear committed Nov 30, 2010
Showing with 46 additions and 0 deletions.
  1. +4 −0 lib/Kernel.cs
  2. +42 −0 perf/call-log-analyze.pl
View
@@ -339,11 +339,15 @@ public class Frame: IP6 {
public Frame() { mo = Kernel.CallFrameMO; }
+ public static readonly bool TraceCalls =
+ Environment.GetEnvironmentVariable("NIECZA_TRACE_CALLS") != null;
public Frame MakeChild(Frame outer, SubInfo info) {
if (reusable_child == null) {
reusable_child = new Frame();
reusable_child.reuser = this;
}
+ if (TraceCalls)
+ Console.WriteLine("{0}\t{1}", this.info.name, info.name);
reusable_child.ip = 0;
reusable_child.resultSlot = null;
reusable_child.lexn = null;
@@ -0,0 +1,42 @@
+use warnings;
+use strict;
+use 5.010;
+use utf8;
+
+my %callers;
+my %tcall;
+
+my $i = 0;
+
+while (<STDIN>) {
+ chomp;
+ unless ($i--) {
+ $i = 10000;
+ syswrite STDERR, ".";
+ }
+ my ($caller, $callee) = split /\t/;
+ $callers{$callee}{$caller}++;
+ $tcall{$callee}++;
+}
+
+syswrite STDERR, "\n";
+
+my $all = 0;
+for (values %tcall) { $all += $_; }
+
+say "Total calls: $all";
+say "";
+
+for my $func (sort { $tcall{$b} <=> $tcall{$a} } keys %tcall) {
+ say "Function: $func";
+ my $t = $tcall{$func};
+ my $c = $callers{$func};
+ printf "Calls: %s (%.6f%%)\n", $tcall{$func}, 100 * $t / $all;
+ print "Called from:\n";
+
+ for my $caller (sort { $c->{$b} <=> $c->{$a} } keys %$c) {
+ printf " %30s %7d %.6f%%\n", $caller, $c->{$caller},
+ 100 * $c->{$caller} / $t;
+ }
+ print "\n";
+}

0 comments on commit e5c3ac0

Please sign in to comment.