statrecord.h 6.57 KB
/*
 * Copyright (C) 1996-1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * 
 * This file is part of the SimOS distribution. 
 * See LICENSE file for terms of the license. 
 *
 */

/**************************************************************
 * statrecord.h 
 * Management of the MemStat counters and the detailed (byPC,byData)
 * data structures. 
 * 
 * ************************************************************/


#ifndef STAT_RECORD_H
#define STAT_RECORD_H
#include <stdio.h>
#include "simtypes.h"

typedef struct StatRecordBucket   StatRecordBucket;
typedef struct StatRecordSwitch   StatRecordSwitch;
typedef struct StatRecordDetail   StatRecordDetail;
typedef struct StatRecordSnapshot StatRecordSnapshot;
typedef struct StatRecordFieldDescStruct *StatRecordFieldDesc;

extern void StatRecordEarlyInit(void);
extern void StatRecordLateInit(void);

/* ******************************************************************
 * StatRecordBucket. Allocation and Field definition
 * ******************************************************************/


#define STATRECORD_INSTRUCTION (1<<0)
#define STATRECORD_DATA        (1<<1)

extern StatRecordBucket *StatRecordNewBucket(void);
extern void StatRecordFreeBucket(StatRecordBucket *bucket);
extern StatRecordFieldDesc StatRecordDefineField(char *field, int instr_data);


/* *******************************************************************
 * Incrementors: use either the current switches or the snapshoted switches
 * ******************************************************************/
extern void StatRecordEntry(int cpuNum, VA PC, VA vAddr, 
                            StatRecordFieldDesc field, int inc);
extern void StatRecordIncrement(StatRecordSnapshot *cur, VA PC, VA vAddr, 
                                StatRecordFieldDesc field, int inc);

/* ****************************************************************
 * Control switches
 * Once a switch has been instantiated, associated MemStatBuckets can
 * can be freely set and changed independently for the different cpus.
 * ****************************************************************/

extern StatRecordSwitch *StatRecordNewSwitch(char *name);
extern void StatRecordSetSwitch(StatRecordSwitch *s, int cpuNum,
                                StatRecordBucket *newBucket);

/* *****************************************************************
 * Detailed breakdowns.
 * A detailed breakdown is specified by its name, byPC or byData, 
 * the selected fields and the selected areas of detail.
 * Fields and areas of detail cannot be added once the simulation
 * has started. The recording of the stats can be selectively
 * turned on/off for each CPU. This must be done explicitely
 * for each CPU if this is wanted.
 * *****************************************************************/

extern StatRecordDetail *StatRecordNewDetail(char *fileName,
                                             int isByPC,  
                                             int counterSize,
                                             int lowRes,
                                             int highRes);

extern void StatRecordDetailAddField(StatRecordDetail *detail,
                                     int pos, char *fieldName);

extern void StatRecordDetailHighResRange(StatRecordDetail *detail,
                                         VA addr, uint len);

extern void StatRecordDetailSetActive(StatRecordDetail *detail, 
                                      int cpuNum,bool active);

extern void StatRecordDetailDump(StatRecordDetail *detail, int fd, int reset);

extern int   StatRecordDetailNumCounters(StatRecordDetail *detail);
extern void* StatRecordDetailBucketAddr(StatRecordDetail *detail, VA addr);
extern int64 StatRecordDetailCounterByIndex(StatRecordDetail *detail, 
                                                void *bucketPtr, uint index);

extern int64 StatRecordDetailCounterByField(StatRecordDetail *detail, 
                                                void *bucketPtr, char *fieldName);

extern int StatRecordDetailTableOK(StatRecordDetail *detail);


/* *****************************************************************
 * Snapshots
 * Certain stats cannot be classified exactly at the time of the event
 * that we are associated it with, but rather only at a later point,
 * for example when the line is evicted from the cache. 
 * In order to remember the state at the time of the event,
 * a snapshot of the switches is taken that can be used to direct
 * the recording.  
 * *****************************************************************/

extern StatRecordSnapshot *StatRecordAllocSnapshot(int cpuNum);
extern void StatRecordFreeSnapshot(StatRecordSnapshot *);

/* *******************************************************************
 * StatRecordTransferBucket.
 * This does 3 things: (1) increment the final bucket by the values of the
 * temporary bucket (2) Redirect the snapshots that refered to the temporary
 * bucket (for the given switch) to the main bucket (3) clear the temproray
 * bucket
 * ********************************************************************/

extern void StatRecordTransferBucket(StatRecordSwitch *sw,
                                     StatRecordBucket *tmpBucket,
                                     StatRecordBucket *finalBucket);


/* ****************************************************************
 * StatRecordDisableCPU
 * ****************************************************************/

extern void StatRecordDisableCPU(int cpuNum);

/* ****************************************************************
 * Utility functions. Operations on StatRecordBucket
 * ****************************************************************/

extern void StatRecordDumpBucket(char *tag, StatRecordBucket *bp, char *lead);
extern void StatRecordDumpFields(void);
extern void StatRecordInc(StatRecordBucket *a,StatRecordBucket *b);
extern void StatRecordComputeMin(StatRecordBucket *min, StatRecordBucket *a);
extern void StatRecordComputeMax(StatRecordBucket *max, StatRecordBucket *a);
extern void StatRecordZero(StatRecordBucket *b);
extern void StatRecordCopy(StatRecordBucket *src, StatRecordBucket *dst);
extern int64 StatRecordFieldValue(StatRecordBucket *b, char *field);
extern int64 StatRecordFieldValueByIndex(StatRecordBucket *b, unsigned index);
extern int  StatRecordNumFields(void);
extern char* StatRecordGetFieldName(unsigned index);
extern int  StatRecordDetailNumFields(StatRecordDetail *detail);
extern char* StatRecordDetailGetFieldName(StatRecordDetail *detail, unsigned index);

/* this is just temoporary. Needed for modesstats hacks */
extern int StatRecordBucketSize(void);

#endif  /* STAT_RECORD_H */