/* This file was generated by scm2java from source file "stats.scm" */
/*  "stats.scm" WB-tree File Based Associative String Data Base System. */
/*  Copyright (C) 1991, 1992, 1993, 2000 Free Software Foundation, Inc. */
/*  */
/*  This program is free software: you can redistribute it and/or modify */
/*  it under the terms of the GNU Lesser General Public License as */
/*  published by the Free Software Foundation, either version 3 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, see */
/*  <http://www.gnu.org/licenses/>. */



package wb;

import static wb.Ents.*;
import static wb.Seg.*;
import static wb.Blink.*;
import static wb.Del.*;
import static wb.Handle.*;
import static wb.Wbdefs.*;
import static wb.Wbsys.*;
import static wb.Blk.*;
import static wb.Ent.*;
public class Stats {

/*  PERFORMANCE STATISTICS */


public static int nextCt = 0;

public static int nextFct = 0;

public static int prevCt = 0;

public static int prevFct = 0;

public static int getCt = 0;

public static int getFct = 0;

public static int putCt = 0;

public static int putFct = 0;

public static int remCt = 0;

public static int remFct = 0;

public static int geCt = 0;

public static int geFct = 0;

public static int tgeCt = 0;

public static int tgeFct = 0;

public static int tceCt = 0;

public static int tceFct = 0;


public static int chainsToNext = 0;

public static int deferredInserts = 0;

public static int splitIndexInserts = 0;

public static int indexScrewCase = 0;

public static int blockSplits = 0;

public static int blockDeletes = 0;

public static int deferredDeletes = 0;

public static int dirDtyCt = 0;


public static int readCt = 0;

public static int writeCt = 0;

public static int readFlCt = 0;

public static int writeFlCt = 0;

public static int flushCt = 0;


public static int clearStats()
{
  nextCt = 0;
  nextFct = 0;
  prevCt = 0;
  prevFct = 0;
  getCt = 0;
  getFct = 0;
  putCt = 0;
  putFct = 0;
  remCt = 0;
  remFct = 0;
  geCt = 0;
  geFct = 0;
  tgeCt = 0;
  tgeFct = 0;
  tceCt = 0;
  tceFct = 0;
  chainsToNext = 0;
  deferredInserts = 0;
  splitIndexInserts = 0;
  indexScrewCase = 0;
  blockSplits = 0;
  blockDeletes = 0;
  deferredDeletes = 0;
  dirDtyCt = 0;
  readCt = 0;
  writeCt = 0;
  readFlCt = 0;
  writeFlCt = 0;
  flushCt = 0;
  return success;
}


public static int cstats()
{
  stats();
  return clearStats();
}


public static int stats()
{
  System.err.print("\n");
  System.err.print("OPERATIONS SUMMARY:\n");
  System.err.print("            NEXT     PREV      GET      PUT      REM   GETENT   CACHE    CACHE\n");
  System.err.print("                                                                AVAIL?   VALID?\n");
  System.err.print("   succ "+(nextCt)+" "+(prevCt)+" "+(getCt)+" "+(putCt)
   +" "+(remCt)+" "+(geCt)+" "+(tgeCt)+" "+(tceCt)
   +"\n");
  System.err.print("   fail "+(nextFct)+" "+(prevFct)+" "+(getFct)+" "+(putFct)
   +" "+(remFct)+" "+(geFct)+" "+(tgeFct)+" "+(tceFct)
   +"\n\n");
  System.err.print("INTERNAL OPERATIONS SUMMARY:\n");
  System.err.print("   chains-to-next = "+(chainsToNext)+"\n");
  System.err.print("   "+(blockSplits)+" block splits, "+(deferredInserts)+" deferred parent updates, "+(deferredInserts)+" undone\n");
  System.err.print("   "+(splitIndexInserts)+" split index inserts; "+(indexScrewCase)+" index-insert screw cases \n");
  System.err.print("   "+(blockDeletes)+" block deletes; "+(deferredDeletes)+" deferred block deletes\n\n");
  System.err.print("I/O SUMMARY: "+(readCt)+" READS, "+(writeCt)+" WRITES, "+(flushCt)+" FLUSH (of dirty bufs) calls.\n");
  System.err.print("             "+(readFlCt)+" FREELIST READS, "+(writeFlCt)+" FREELIST WRITES.\n");
  System.err.print("             "+(dirDtyCt)+" DIRS LEFT DTY.\n");
  {
    int ops = Math.max((nextFct)+(prevFct)+(getFct)+(putFct)+(remFct)+(nextCt)+(prevCt)+(getCt)
     +(putCt)+(remCt), 1);
    System.err.print("   AVG BLKS REFERENCED PER OPERATION: "+((0x64*((geCt)+(tceCt)))/(ops))+"%"+"\n");
    System.err.print("   AVG DISK I/Os PER OPERATION: "+((0x64*((readCt)+(writeCt)+(readFlCt)+(writeFlCt)))/(ops))+"%"+"; ");
    System.err.print("   WRITE/READ RATIO: "+((0x64*((writeCt)+(writeFlCt)))/(Math.max(1, (readCt)+(readFlCt))))+"%"+"\n");
    if ((putCt)>0)
      System.err.print("   AVG DISK WRITES PER PUT: "+((0x64*(writeCt))/(putCt))+"%"+"\n");
  }
  System.err.print("\n");
  System.err.print("MODES IN EFFECT:\n");
  System.err.print(""+(numEntsCt)+" buffers [hashed over "+(numBuks)+" buckets]; blksize (max)="+(blkSize)+"; FLC-LEN="+(flcLen)
   +"\n");
  System.err.print("defer-insert-updates?= "+((deferInsertUpdates_P
	?"#t"
	:"#f"))+"; defer-block-deletes="+((del_DeferBlockDeletes_P
	?"#t"
	:"#f"))+"\n");
  System.err.print("cache-ent-enable?="+((cacheEntEnable_P
	?"#t"
	:"#f"))+"; clever-cache-enable?="+((cleverCacheEnable_P
	?"#t"
	:"#f"))+"\n");
  System.err.print("\n");
  return success;
}


public static void showBuffer(Ent ent)
{
  System.err.print("SEG = "+(seg_Id(ent_Seg(ent)))+" ID= "+(ent_Id(ent))+" ACC= "+(ent_Acc(ent))+" REF= "+(ent_Ref(ent))
   +" DTY= "+(ent_Dty_P(ent))+" AGE= "+(ent_Age(ent))+"\n");
  return;
}


public static boolean bufVerbose_P = (true);


public static int showBuffer1(Ent ent)
{
  if ((bufVerbose_P
      || (seg_Id(ent_Seg(ent)))> -1))
    {
      System.err.print(" "+(seg_Id(ent_Seg(ent)))+":"+(ent_Id(ent))+" "+(hash2int(seg_Id(ent_Seg(ent)), ent_Id(ent)))+" "+(ent_Acc(ent))
   +" "+(ent_Ref(ent))+" "+0+" "+(ent_Dty_P(ent))+" "+(ent_Age(ent))
   +"");
      if ((seg_Id(ent_Seg(ent)))> -1)
	{
	  System.err.print(" "+((blk_Level(ent_Blk(ent)))-(leaf))+" "+(blk_Typ(ent_Blk(ent)))+"\n");
	}
      else System.err.print("\n");
    }
  return success;
}


public static int showBuffers()
{
  System.err.print("\n");
  System.err.print(" SEG:ID        BUK      ACC    REF READERS DTY  AGE LEVEL TYPE\n");
  return doSegBuffers(null, getMethod("wb.Stats", "showBuffer1", new Class[]{Ent.class}));
}


public static int sb()
{
  return showBuffers();
}

}
