Alien-Judy

 view release on metacpan or  search on metacpan

src/judy-1.0.5/src/JudyCommon/JudyPrintJP.c  view on Meta::CPAN

// Copyright (C) 2000 - 2002 Hewlett-Packard Company
//
// This program is free software; you can redistribute it and/or modify it
// under the term of the GNU Lesser General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
// for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// _________________

// @(#) $Revision: 4.13 $ $Source: /judy/src/JudyCommon/JudyPrintJP.c $
//
// JudyPrintJP() debugging/tracing function for Judy1 or JudyL code.
// The caller should #include this file, with its static function (replicated
// in each compilation unit), in another *.c file, and compile with one of
// -DJUDY1 or -DJUDYL.
//
// The caller can set j__udyIndex and/or j__udyPopulation non-zero to have
// those values reported, and also to control trace-enabling (see below).
//
// Tracing is disabled by default unless one or both of two env parameters is
// set (regardless of value).  If either value is set but null or evaluates to
// zero, tracing is immediately enabled.  To disable tracing until a particular
// j__udy*Index value is seen, set STARTINDEX=<hex-index> in the env.  To
// disable it until a particular j__udy*Population value is seen, set
// STARTPOP=<decimal-population> in the env.  Once either condition is met,
// tracing "latches on".
//
// Example:
//
//      STARTPOP=0              // immediate tracing.
//      STARTINDEX=f35430a8     // not until one of these is met.
//      STARTPOP=1000000
//
// Note:  Trace-enabling does nothing unless the caller sets the appropriate
// global variable non-zero.

#if (! (defined(JUDY1) || defined(JUDYL)))
#error:  One of -DJUDY1 or -DJUDYL must be specified.
#endif

#include <stdlib.h>             // for getenv() and strtoul().


// GLOBALS FROM CALLER:
//
// Note:  This storage is declared once in each compilation unit that includes
// this file, but the linker should merge all cases into single locations, but
// ONLY if these are uninitialized, so ASSUME they are 0 to start.

Word_t j__udyIndex;             // current Index itself, optional from caller.
Word_t j__udyPopulation;        // Indexes in array, optional from caller.

// Other globals:

static Word_t startindex = 0;           // see usage below.
static Word_t startpop   = 0;
static bool_t enabled    = FALSE;       // by default, unless env params set.

// Shorthand for announcing JP addresses, Desc (in context), and JP types:
//
// Note:  Width is at least one blank wider than any JP type name, and the line
// is left unfinished.
//
// Note:  Use a format for address printing compatible with other tracing
// facilities; in particular, %x not %lx, to truncate the "noisy" high part on
// 64-bit systems.

#define JPTYPE(Type)  printf("0x%lx %s %-17s", (Word_t) Pjp, Desc, Type)

// Shorthands for announcing expanse populations from DcdPopO fields:

#define POP0 printf("Pop1 = 0 ")
#define POP1 printf("Pop1 = %ld ", (Word_t) ((JU_JPDCDPOP0(Pjp) &            0xff) + 1))
#define POP2 printf("Pop1 = %ld ", (Word_t) ((JU_JPDCDPOP0(Pjp) &          0xffff) + 1))
#define POP3 printf("Pop1 = %ld ", (Word_t) ((JU_JPDCDPOP0(Pjp) &        0xffffff) + 1))
#ifdef JU_64BIT
#define POP4 printf("Pop1 = %ld ", (Word_t) ((JU_JPDCDPOP0(Pjp) &       0xffffffff) + 1))
#define POP5 printf("Pop1 = %ld ", (Word_t) ((JU_JPDCDPOP0(Pjp) &     0xffffffffff) + 1))
#define POP6 printf("Pop1 = %ld ", (Word_t) ((JU_JPDCDPOP0(Pjp) &   0xffffffffffff) + 1))
#define POP7 printf("Pop1 = %ld ", (Word_t) ((JU_JPDCDPOP0(Pjp) & 0xffffffffffffff) + 1))
#endif

// Shorthands for announcing populations of Immeds:
//
// Note:  Line up the small populations that often occur together, but beyond
// that, dont worry about it because populations can get arbitrarily large.

#define POP_1   printf("Pop1 =  1 ")
#define POP_2   printf("Pop1 =  2 ")
#define POP_3   printf("Pop1 =  3 ")
#define POP_4   printf("Pop1 =  4 ")
#define POP_5   printf("Pop1 =  5 ")
#define POP_6   printf("Pop1 =  6 ")
#define POP_7   printf("Pop1 =  7 ")
#define POP_8   printf("Pop1 =  8 ")
#define POP_9   printf("Pop1 =  8 ")
#define POP_10  printf("Pop1 = 10 ")
#define POP_11  printf("Pop1 = 11 ")
#define POP_12  printf("Pop1 = 12 ")
#define POP_13  printf("Pop1 = 13 ")
#define POP_14  printf("Pop1 = 14 ")
#define POP_15  printf("Pop1 = 15 ")

// Shorthands for other announcements:

#define NUMJPSL printf("NumJPs = %d ", P_JBL(Pjp->jp_Addr)->jbl_NumJPs)
#define OOPS    printf("-- OOPS, invalid Type\n"); exit(1)

// This is harder to compute:

#define NUMJPSB                                                         \
        {                                                               \
            Pjbb_t Pjbb = P_JBB(Pjp->jp_Addr);                          \



( run in 1.720 second using v1.01-cache-2.11-cpan-e1769b4cff6 )