root/src/vmstat.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. fetch_insn_counting
  2. dump_insn_frequency

   1 /*
   2  * vmstat.c - statistics gathering code for vm.c
   3  *
   4  *   Copyright (c) 2005 Shiro Kawai, All rights reserved.
   5  * 
   6  *   Redistribution and use in source and binary forms, with or without
   7  *   modification, are permitted provided that the following conditions
   8  *   are met:
   9  * 
  10  *   1. Redistributions of source code must retain the above copyright
  11  *      notice, this list of conditions and the following disclaimer.
  12  *
  13  *   2. Redistributions in binary form must reproduce the above copyright
  14  *      notice, this list of conditions and the following disclaimer in the
  15  *      documentation and/or other materials provided with the distribution.
  16  *
  17  *   3. Neither the name of the authors nor the names of its contributors
  18  *      may be used to endorse or promote products derived from this
  19  *      software without specific prior written permission.
  20  *
  21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  27  *   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28  *   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29  *   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31  *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32  *
  33  *  $Id: vmstat.c,v 1.1 2005/08/13 06:51:52 shirok Exp $
  34  */
  35 
  36 /* This file is included from vm.c */
  37 
  38 #ifdef COUNT_INSN_FREQUENCY
  39 /* for statistics */
  40 static u_long insn1_freq[SCM_VM_NUM_INSNS];
  41 static u_long insn2_freq[SCM_VM_NUM_INSNS][SCM_VM_NUM_INSNS];
  42 
  43 #define LREF_FREQ_COUNT_MAX 10
  44 static u_long lref_freq[LREF_FREQ_COUNT_MAX][LREF_FREQ_COUNT_MAX];
  45 static u_long lset_freq[LREF_FREQ_COUNT_MAX][LREF_FREQ_COUNT_MAX];
  46 
  47 static ScmWord fetch_insn_counting(ScmVM *vm, ScmWord code)
  48 {
  49     if (vm->base && vm->pc != vm->base->code) {
  50         insn2_freq[SCM_VM_INSN_CODE(code)][SCM_VM_INSN_CODE(*vm->pc)]++;
  51     }
  52     code = *vm->pc++;
  53     insn1_freq[SCM_VM_INSN_CODE(code)]++; 
  54     switch (SCM_VM_INSN_CODE(code)) {
  55     case SCM_VM_LREF0: lref_freq[0][0]++; break;
  56     case SCM_VM_LREF1: lref_freq[0][1]++; break;
  57     case SCM_VM_LREF2: lref_freq[0][2]++; break;
  58     case SCM_VM_LREF3: lref_freq[0][3]++; break;
  59     case SCM_VM_LREF4: lref_freq[0][4]++; break;
  60     case SCM_VM_LREF10: lref_freq[1][0]++; break;
  61     case SCM_VM_LREF11: lref_freq[1][1]++; break;
  62     case SCM_VM_LREF12: lref_freq[1][2]++; break;
  63     case SCM_VM_LREF13: lref_freq[1][3]++; break;
  64     case SCM_VM_LREF14: lref_freq[1][4]++; break;
  65     case SCM_VM_LREF:
  66     {
  67         int dep = SCM_VM_INSN_ARG0(code);
  68         int off = SCM_VM_INSN_ARG1(code);
  69         if (dep >= LREF_FREQ_COUNT_MAX) dep=LREF_FREQ_COUNT_MAX-1;
  70         if (off >= LREF_FREQ_COUNT_MAX) off=LREF_FREQ_COUNT_MAX-1;
  71         lref_freq[dep][off]++;
  72         break;
  73     }
  74     case SCM_VM_LSET0: lset_freq[0][0]++;
  75     case SCM_VM_LSET1: lset_freq[0][1]++;
  76     case SCM_VM_LSET2: lset_freq[0][2]++;
  77     case SCM_VM_LSET3: lset_freq[0][3]++;
  78     case SCM_VM_LSET4: lset_freq[0][4]++;
  79     case SCM_VM_LSET:
  80     {
  81         int dep = SCM_VM_INSN_ARG0(code);
  82         int off = SCM_VM_INSN_ARG1(code);
  83         if (dep >= LREF_FREQ_COUNT_MAX) dep=LREF_FREQ_COUNT_MAX-1;
  84         if (off >= LREF_FREQ_COUNT_MAX) off=LREF_FREQ_COUNT_MAX-1;
  85         lset_freq[dep][off]++;
  86         break;
  87     }
  88     }
  89     return code;
  90 }
  91 
  92 static void dump_insn_frequency(void *data)
  93 {
  94     int i, j;
  95     Scm_Printf(SCM_CUROUT, "(:instruction-frequencies (");
  96     for (i=0; i<SCM_VM_NUM_INSNS; i++) {
  97         Scm_Printf(SCM_CUROUT, "(%s %d", Scm_VMInsnName(i), insn1_freq[i]);
  98         for (j=0; j<SCM_VM_NUM_INSNS; j++) {
  99             Scm_Printf(SCM_CUROUT, " %d", insn2_freq[i][j]);
 100         }
 101         Scm_Printf(SCM_CUROUT, ")\n");
 102     }
 103     Scm_Printf(SCM_CUROUT, ")\n :lref-frequencies (");
 104     for (i=0; i<LREF_FREQ_COUNT_MAX; i++) {
 105         Scm_Printf(SCM_CUROUT, "(");
 106         for (j=0; j<LREF_FREQ_COUNT_MAX; j++) {
 107             Scm_Printf(SCM_CUROUT, "%d ", lref_freq[i][j]);
 108         }
 109         Scm_Printf(SCM_CUROUT, ")\n");
 110     }
 111     Scm_Printf(SCM_CUROUT, ")\n :lset-frequencies (");
 112     for (i=0; i<LREF_FREQ_COUNT_MAX; i++) {
 113         Scm_Printf(SCM_CUROUT, "(");
 114         for (j=0; j<LREF_FREQ_COUNT_MAX; j++) {
 115             Scm_Printf(SCM_CUROUT, "%d ", lset_freq[i][j]);
 116         }
 117         Scm_Printf(SCM_CUROUT, ")\n");
 118     }
 119     Scm_Printf(SCM_CUROUT, ")\n");
 120     Scm_Printf(SCM_CUROUT, ")\n");
 121 }
 122 
 123 #endif /*COUNT_INSN_FREQUENCY*/
 124 

/* [<][>][^][v][top][bottom][index][help] */