I needed to cycle through a collection of external files, but I wanted to do it in a random order, and I also wanted to go through all of the files before I went through any file twice.

There are all sorts of ways to implement this, so that's not really a big deal. Somewhere I had an error that was giving me repeated files before I had finished a complete cycle, so I need to track that down, and I did, and it was fixed.

But was it really fixed? I wondered how I could test this. I could simply count every time I saw the file and compare all the counts at various times. That works.

I wanted to watch it though. I didn't want to speed read as a bunch of text lines scrolled past on the terminal. I wanted so compact output that would fit on the screen and updated as things happened, so I wrote a little Curses visualizer.

The particulars of the program aren't important. It output a string with two numbers which identified the resource. The first number was between 1 and 9 and the second was between 1 and 80. On the screen, I framed a matrix for these. At the right spot, I'd put something on the screen to show something just happened for the file with those two numbers.

I started with the count of the times I had seen that file. When I saw the file once, I'd put a "1" in the matrix, when I saw it twice, a "2", and so on. That kinda worked, but it was hard to read. Then I used other characters in place of number and alternated between characters with lots of empty space and those without a lot, such as ( . @ ^ # , $ | & + ). That was better, but still not good enough. I was running this things for a couple implementations and I wanted to see an anomaly instantly.

I changed to simple, colored blocks instead of characters. I just made a bunch of Curses pairs that had the same foreground and background and assigned each color to a number of times I saw the file. I went in the order of the rainbow: blue for 1 time, green for 2 times, and so on.

Too bad I can't show some images inline, so you'll have to be satisfied with some external images: first pass through the corpus (black is 0 times and blue is 1 time ), second pass (green is 2 times).

I could have also done this with sound by playing a specific pitch for each count and I wouldn't even have to watch it. I could almost tune out because the odd pitch would get my attention.

#!/usr/bin/perl use Curses; init(); make_frame(); while(1) { my( $M, $m ) = `command` =~ m/M: (\d+), m: (\d+)$/g; put( $M, $m, ++$count{$M}{$m} ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # sub init { $SIG{__DIE__} = $SIG{TERM} = sub { endwin; exit }; instiller; curs_set(0); start_color(); my @colors = ( COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_YELLOW, COLOR_RED ); foreach my $color ( 1 .. @colors ) { init_pair( $color, ( $colors[ $color ] ) x 2 ) } } sub make_frame { foreach my $y ( 1 .. 80 ) { my $Y = $y; if( $y % 10 == 0 ) { $y /= 10 }; $y %= 10; addch( 0, $Y+1, "$y" ); addch( 10, $Y+1, "$y" ); } foreach my $x ( 1 .. 9 ) { addch( $x, 1, "$x" ); addch( $x, 82, "$x" ); } refresh; } sub put { my( $major, $minor, $n ) = @_; attron( COLOR_PAIR($n) ); addch( $major, $minor+2, " " ); attroff( COLOR_PAIR($n) ); refresh; }
--
brian d foy <bdfoy@cpan.org>

In reply to Visualizing bugs by brian_d_foy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.