Using logzone, a Swarm library

Ralf Stephan (ralf@ark.in-berlin.de)

5th June 2000

Description / where to get it

Swarm is a Java/Objective-C framework for agent based modelling (ABM). logzone is a set of classes to facilitate monitoring of Zones in Swarm. It is available from the swarm.org archive or from the author’s website

logzone is free software, distributed under the GNU GPL.

Installation

The package comes as a gzipped tar archive file.

  1. To unpack, issue the tar xvfz command on the package. A subdirectory named logzone-version should be filled.
  2. cd into the created directory.
  3. With make, the file liblogzone.a should be built.
  4. The library is used in your programs by putting liblogzone.a into your Makefile APPLIBS variable.
        
           APPLIBS=/path/liblogzone.a
          

Class hierarchy

Usage examples

There is no limit on the number of LoggingZones. I used logzone to debug itself, for example.

The examples assume the header file is included, and both logzone and logger are temporary ids.

 #import "/path/LoggingZone.h"
 ...
   id logzone, logger;

Default The default behaviour is to give you sorted cumulative info in a graphics window.

 logzone = [LoggingZone create: globalZone];
 observerSwarm = [AquariumObserverSwarm create: logzone];

File/stdout You can also send alloc info (non-cumulative) to a file/stdout.

 logzone = [LoggingZone createBegin: globalZone];
 [logzone setAsciiFilename: 0]; // to stdout
 logzone = [logzone createEnd];
 observerSwarm = [AquariumObserverSwarm create: logzone];

Delimiter It is also possible to set a refined logger, e.g. log cumulative info separated by commata to a file named testlog.

 logzone = [LoggingZone createBegin: globalZone];
 logger = [AsciiMemLogger createBegin: globalZone];
 [logger setCumulative];
 [logger setFilename: "testlog"];
 [logger setRecordDelim: "\n" dataDelim: ","];
 logger = [logger createEnd];
 [logzone setMemLogConsumer: logger];
 logzone = [logzone createEnd];

ScrathchZone/GlobalZone One can even log scratchZone/globalZone by replacing it with a LoggingZone.

 logzone = [LoggingZone createBegin: globalZone];
 [logzone setAsciiFilename: 0]; // to stdout
 // WARNING: using a more complicated logger may result in infinite loops.
 scratchZone = [logzone createEnd];

R output The RMemLogger can be used to log single (de)allocation events or per step.
                                                                          
                                                                          

 logzone = [LoggingZone createBegin: globalZone];
 logger = [RMemLogger createBegin: globalZone];
 [logger setCumulative];
 [logger setFilename: "rlog"];
 logger = [logger createEnd];
 [logzone setMemLogConsumer: logger];
 logzone = [logzone createEnd];
The resulting file rlog could then be read from within R with something like:

 frame <- read.table("rlog",header=TRUE)
Logging in other formats (contributions!) or more graphically sophisticated would be nice to have.

Analyzing with awk

Here is an example of an awk script to cumulate alloc info from the (default non-cumulative) ASCII output.

 BEGIN { arr[0]=0 }
 {
   if ( $3 in arr )
   {
     if ( $2 ~ /\+/ )
       arr[$3] = arr[$3]+1
     else
       arr[$3] = arr[$3]-1
   }
                                                                          
                                                                          
   else
   {
     if ( $2 ~ /\+/ )
       arr[$3] = 1
   }
 }
 END { for ( i in arr ) print i,arr[i] }

Contact

Please send patches to: ralf@ark.in-berlin.de.