[Phoenix-pm] Source code for the graph thingie / Re: Meeting Announcement - Wed March 14, 2007 @ 7:00pm

Scott Walters scott at illogics.org
Wed Mar 14 17:31:11 PDT 2007


Ooops, didn't mean to send that quite yet... in particular, I hadn't attached
the code...

Here's the code.  And here are some comments on it...

sub opt ($) { scalar grep $_ eq $_[0], @ARGV }
sub arg ($) { my @a=args(@_); return () unless @a; return $a[0]; }
sub args ($) { grep { my $x = $_ eq $_[0] ... /^-/; $x !~ /E/ and $x and $x > 1; } @ARGV; }

I've taken to pasting that in where I need some lightweight argument processing.
It's less feature-rich than Getopt.  

    do { no warnings 'misc'; splice @symbol_stack, $indent, @symbol_stack-$indent, ($symbol); };

One splice, ignoring the errors, makes sure that our concept of the current
call stack (where the program currently is with regards to which methods
have called which other methods and how deeply that's gone) is updated
against the two bits of info we've just read:  the call stack depth (indicated
by how much whitespace there was at the start) and the current method the
code is in.

        $graph->{$symbol_stack[-2]}->{$symbol_stack[-1]}++;

The last two things on the call stack are the current method being
called from and called to.  We bump the counter for that connection
(which turns out to be an edge between two nodes on the graph).
The number is used to decide how dark to draw the edge (line).

my $find_weight = do {

This divides all of the nodes up into 16 groups of equal size,
each to be assigned a different darkness, 0 through f.

There's really not much to it!

-scott

On  0, Scott Walters <scott at illogics.org> wrote:
> Hi all,
> 
> Thanks to everyone who came out.  It's lovely to be able to sit aorund and
> gab with Perl people, or at least gab about Perl with people ;)
> 
> I'll try to include enough details for even those who didn't make it, but
> I gotta say, watching eight people try to assemble thirty pages into a poster
> on a table top and coming up with an elaborate graph of nodes and edges 
> everywhere in complex array was the best part.
> 
> Here's my little shell script that runs everything and gets it ready for
> print:
> 
> perl parsejohnstrace.pl -f /home/playground/scottwalters/logs/error_log > parsejohn.txt
> dot -Tps parsejohn.txt > parsejohn.ps
> poster parsejohn.ps -s 3 -o parsejohn.poster.ps
> 
> parsejohnstrace.pl is attached.  That's the only bit I did.  It
> looks for stuff in the log file in a certain format:
> 
>   Logging::logHandler
>     RequestStash::_get_instance
>       RequestStash::_apache_get_instance
>     RequestStash::get
>       RequestStash::_key_defined
>     Logging::_make_tokenized_args
>       RequestStash::_get_instance
>         RequestStash::_apache_get_instance
>       RequestStash::get
>         RequestStash::_key_defined
>       Logging::_tokenize_request_args
>         Logging::_clean_up_rogue_pid_args
>         Logging::_array_has_value
>         Logging::_array_has_value
>         Logging::_array_has_value
>         Logging::_array_has_value
>       Logging::_tokenize_host_args
>         Logging::app
>         Application::local_ip
>           Application::r
> 
> Another program (not included) wraps methods to print out their names with
> an indentation level of the depth of the call stack (in other words, if
> method A calls B and B calls C, A would be indented none, B once, and
> C two spaces).  This was an artifact and isn't recommended... if you can
> use dprof (Devel::DProf does dprof compatible output) and read that
> format, that's much saner that what we did.  We were doing this in
> Apache mod_perl and had some problems with profiling the ordinary way,
> and this Aspect-y stuff was already in use and was easily adapted to
> this purpose.
> 
> Hint:  don't try to wrap AUTOLOAD methods.  It just doesn't work ;)
> They quite often look at caller() and wrapping them screws that up.
> 
> The 'poster' program that takes one PostScript page and scales it up into 
> an arbitrary number of pages is poster.  That's available from here:
> 
> http://ctan.unsw.edu.au/support/poster/poster.txt
> http://ctan.unsw.edu.au/support/poster.zip
> 
> I think there's a Debian package for that.  My Knoppix machine had it already,
> I was surprised to see.  It's a very old program so it's nice to run into it
> randomly like that.
> 
> dot is of course from GraphViz.  It takes the graph description in its own
> little language and outputs an image or PostScript.  PostScript is a 
> vector format with many tools to work on it, so it was a natual choice.
> In particular, poster tiled it across pages so we could make a nice
> blown up version.
> 
> parsejohnstrace.pl is attached (so named because I was originally parsing
> data logged to a coworker's Apache error_log).  It will output GraphViz
> format or vcg format graphs.  vcg has an interactive graph viewing
> mode.
> 
> A few notes about the code...
> 
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: parsejohnstrace.pl
Type: application/x-perl
Size: 5188 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/phoenix-pm/attachments/20070315/b69b139f/attachment-0001.bin 


More information about the Phoenix-pm mailing list