Tags:
create new tag
, view all tags
writeDebug is pretty usefulbut has it's limitations It'd be nice to be able to switch on & off debugging in various locations in twiki - especially when you just want to figure out "Why the heck is that broken?!"

As a result I'd propose a system similar to that of squid or ghostscript whereby each section of the code be allocated a name, and you can turn on various level of debugging. Specifically with squid you can say sections 7,10, 12, debug level 7. For twiki it strikes me an associative array would be useful... As a result, I'd suggest something along the lines of:

In TWiki,cfg:

    # EXPERIMENTAL ADDITIONS
    # Variables that affect debugging
    # ===============================
    #                        Section             Debug Level
    #                        ==============      ===========
    %debuggingSection    =  ('twiki.plugins'  => 1,
                             'plugin.smilies' => 5,
                             'plugin.draw'    => 5,
    ... etc ...
                             'twiki.store'    => 0,
                             'twiki.render'   => 0);
     
    

In TWiki.pm:

    #MPS
    # Variables that affect debugging
    # ===============================
    #
    # %debuggingSection
    sub areDebugging
    {
        my $section = shift;
        my $level   = shift;
        # writeDebug("debugging newdebug! : $section, $level, $debuggingSection{$section}");
        if ($debuggingSection{$section} && $level <= $debuggingSection{$section}) { return 1; }
        return 0;
    }
    #
     
    sub NEWwriteDebug {
        my $section = shift;
        my $level   = shift;
        my $text    = shift;
        if (areDebugging($section, $level)) {
           open( FILE, ">>$debugFilename");
           print FILE "NwD:$section:$level: $text\n";
           close( FILE);
        }# else {
         #  writeDebug("debugging newdebug! : $section, $level FAILED");
         # }
    }
    #/MPS                                                                                                                                                                 
    

Example modification to the Drawing plugin:

    ...
        &TWiki::NEWwriteDebug("plugin.draw", 10, "pubDir = $pDir");
        my $nameVal = TWiki::extractNameValuePair( $attributes );
        if( ! $nameVal ) {
            $nameVal = "untitled";
        }
        $nameVal =~ s/[^A-Za-z0-9_\.\-]//go; # delete special characters
        &TWiki::NEWwriteDebug("plugin.draw", 10, "nameVal = $nameVal");
        my $mapFile = "$pDir/$web/$topic/$nameVal.map";
        &TWiki::NEWwriteDebug("plugin.draw", 5, "mapFile = $mapFile");                                                                                                    
    ...
    

-- MichaelSparks - 10 Mar 2001

I like this idea and was wondering myself how to improve that. One thing to watch out is perfomance. An extra function call to write debug info (even if debug is turned off) is no problem for most cases like topic save, but might impose a performance impact for tight loops like rendering or search. So it needs to be used with perfomance in mind.

-- PeterThoeny - 10 Mar 2001

Changing some perl CGI scripts, often PerlPtkdb, a graphical perl debugger, helps me a lot for just getting out, what's wrong in a script.

-- StefanScherer - 11 Mar 2001

Regarding the performance... have a global "debugging on/off" switch, which is used to precede any debug function - ie the above example becomes:

    ...
        &TWiki::NEWwriteDebug("plugin.draw", 10, "pubDir = $pDir") if ($TWiki::debugging);
        my $nameVal = TWiki::extractNameValuePair( $attributes );
        if( ! $nameVal ) {
            $nameVal = "untitled";
        }
        $nameVal =~ s/[^A-Za-z0-9_\.\-]//go; # delete special characters
        &TWiki::NEWwriteDebug("plugin.draw", 10, "nameVal = $nameVal") if ($TWiki::debugging);
        my $mapFile = "$pDir/$web/$topic/$nameVal.map";
        &TWiki::NEWwriteDebug("plugin.draw", 5, "mapFile = $mapFile") if ($TWiki::debugging);
    ...
    
Having just run an informal test of code similar to the above.....
       my @lines = <DATA>;
       @arrgh = qw(ABC DEF GHI JKL);
       for($i=0; $i <1000; $i++) {
          foreach $line (@lines) {
             foreach $a (@arrgh) {
                $b = $a x 20;
                $line =~ s/$a/$b/;
    #            TWiki::NEWwriteDebug("plugin.draw", 10, "A = $a"); # Indiscriminate debugging 
    #            TWiki::NEWwriteDebug("plugin.draw", 10, "A = $a") if ($TWiki::debuggingON); # toggled debugging
             }
          }
       }
    

With no debugging, with indiscriminate debugging & with toggled debugging, it looks like toggled debugging is marginally slower than no debugging (almost immeasurably slower incidentally) and that indiscriminate debugging is about 2.25 - 3 times slower. I suspect that Perl's heavily optimised towards this kind of test smile

Regarding Stefan's comments - this doesn't replace that kind of debugging - these things are complementary smile

-- MichaelSparks -- 11 Mar 2001

Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2008-08-24 - TWikiJanitor
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.