in reply to Re: Analyze a C Call-Stack sequence trace and get call sequence from given Function name onwards.
in thread Analyze a C Call-Stack sequence trace and get call sequence from given Function name onwards.
It works out great. I will add one more interface to do the matching against a collection of functions..package CallStackAnalyzer; use strict; use warnings; use diagnostics; sub new { my $self = { name => 'CallStackAnalyzer', tracefilecontent => undef, stack => [], stacktraces => {}, direction => '', }; bless $self; return $self; } sub TraceFile{ my $self = shift; $self->{tracefilecontent} = shift; _AnalyzeTraceFile($self); } sub _AnalyzeTraceFile{ my $self = shift; my @trace = @{$self->{tracefilecontent}}; foreach my $line (@trace){ if($line=~m/^(ENTRY):\s+\S+\s+\S+\s+(\S+)\(\)/){ push(@{$self->{stack}}, $2) && ($self->{direction} = 'up'); } elsif ($line=~m/^(EXIT):\s+\S+\s+\S+\s+(\S+)\(\)/){ my @stack = $self->{stack}; ($self->{stacktraces}{join('->',@{$self->{stack}})} = \@stack ) && ($self->{direction} = 'down') if( not $self->{direction} eq 'down'); pop(@{$self->{stack}}); } } return ; } 1; package TraceCallStack; use strict; use warnings; use diagnostics; use CallStackAnalyzer; sub Main{ my $trace = open(FH, "CallStack.txt"); my @tracecontent = <FH>; close FH; my $CSA = CallStackAnalyzer->new(); $CSA->TraceFile(\@tracecontent); return; } Main(); 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Analyze a C Call-Stack sequence trace and get call sequence from given Function name onwards.
by Athanasius (Archbishop) on Aug 26, 2014 at 15:38 UTC | |
by tobias_hofer (Friar) on Aug 27, 2014 at 06:47 UTC |