/*
 *  Copyright 2009 OpenSourceStewardshipFoundation.org
 *  Licensed under GNU General Public License version 2
 *
 * Author: seanhalle@yahoo.com
 * 
 */

#ifndef _PROBES_H
#define	_PROBES_H
#define _GNU_SOURCE

#include "VMS_primitive_data_types.h"

#include <sys/time.h>

/*Note on order of include files:  
 * This file relies on #defines that appear in other files..
 */


//typedef struct _IntervalProbe IntervalProbe; //in VMS.h

struct _IntervalProbe
 {
   char           *nameStr;
   int32           probeID;

   int32           schedChoiceWasRecorded;
   int32           coreNum;
   int32           procrID;
   float64         procrCreateSecs;

   #ifdef STATS__USE_TSC_PROBES
   TSCount    startStamp;
   TSCount    endStamp;
   #else
   struct timeval  startStamp;
   struct timeval  endStamp;
   #endif
   float64         startSecs;
   float64         endSecs;
   float64         interval;
   DblHist        *hist;//if NULL, then is single interval probe
 };



//======================== Probes =============================
//
// Use macros to allow turning probes off with a #define switch
#ifdef STATS__ENABLE_PROBES
int32
VMS_impl__record_time_point_into_new_probe( char *nameStr,SlaveVP *animPr);
#define VMS__record_time_point_into_new_probe( nameStr, animPr ) \
        VMS_impl__record_time_point_in_new_probe( nameStr, animPr )

int32
VMS_ext_impl__record_time_point_into_new_probe( char *nameStr );
#define VMS_ext__record_time_point_into_new_probe( nameStr ) \
        VMS_ext_impl__record_time_point_into_new_probe( nameStr )


int32
VMS_impl__create_single_interval_probe( char *nameStr, SlaveVP *animPr );
#define VMS__create_single_interval_probe( nameStr, animPr ) \
        VMS_impl__create_single_interval_probe( nameStr, animPr )


int32
VMS_impl__create_histogram_probe( int32   numBins, float64    startValue,
               float64 binWidth, char    *nameStr, SlaveVP *animPr );
#define VMS__create_histogram_probe(      numBins, startValue,              \
                                          binWidth, nameStr, animPr )       \
        VMS_impl__create_histogram_probe( numBins, startValue,              \
                                          binWidth, nameStr, animPr )
void
VMS_impl__free_probe( IntervalProbe *probe );
#define VMS__free_probe( probe ) \
        VMS_impl__free_probe( probe )

void
VMS_impl__index_probe_by_its_name( int32 probeID, SlaveVP *animPr );
#define VMS__index_probe_by_its_name( probeID, animPr ) \
        VMS_impl__index_probe_by_its_name( probeID, animPr )

IntervalProbe *
VMS_impl__get_probe_by_name( char *probeName, SlaveVP *animPr );
#define VMS__get_probe_by_name( probeID, animPr ) \
        VMS_impl__get_probe_by_name( probeName, animPr )

void
VMS_impl__record_sched_choice_into_probe( int32 probeID, SlaveVP *animPr );
#define VMS__record_sched_choice_into_probe( probeID, animPr ) \
        VMS_impl__record_sched_choice_into_probe( probeID, animPr )

void
VMS_impl__record_interval_start_in_probe( int32 probeID );
#define VMS__record_interval_start_in_probe( probeID ) \
        VMS_impl__record_interval_start_in_probe( probeID )

void
VMS_impl__record_interval_end_in_probe( int32 probeID );
#define VMS__record_interval_end_in_probe( probeID ) \
        VMS_impl__record_interval_end_in_probe( probeID )

void
VMS_impl__print_stats_of_probe( int32 probeID );
#define VMS__print_stats_of_probe( probeID ) \
        VMS_impl__print_stats_of_probe( probeID )

void
VMS_impl__print_stats_of_all_probes();
#define VMS__print_stats_of_all_probes() \
        VMS_impl__print_stats_of_all_probes()


#else
int32
VMS_impl__record_time_point_into_new_probe( char *nameStr,SlaveVP *animPr);
#define VMS__record_time_point_into_new_probe( nameStr, animPr ) \
       0 /* do nothing */

int32
VMS_ext_impl__record_time_point_into_new_probe( char *nameStr );
#define VMS_ext__record_time_point_into_new_probe( nameStr ) \
       0 /* do nothing */


int32
VMS_impl__create_single_interval_probe( char *nameStr, SlaveVP *animPr );
#define VMS__create_single_interval_probe( nameStr, animPr ) \
       0 /* do nothing */


int32
VMS_impl__create_histogram_probe( int32   numBins, float64    startValue,
               float64 binWidth, char    *nameStr, SlaveVP *animPr );
#define VMS__create_histogram_probe(      numBins, startValue,              \
                                          binWidth, nameStr, animPr )       \
       0 /* do nothing */

void
VMS_impl__index_probe_by_its_name( int32 probeID, SlaveVP *animPr );
#define VMS__index_probe_by_its_name( probeID, animPr ) \
        /* do nothing */

IntervalProbe *
VMS_impl__get_probe_by_name( char *probeName, SlaveVP *animPr );
#define VMS__get_probe_by_name( probeID, animPr ) \
       NULL /* do nothing */

void
VMS_impl__record_sched_choice_into_probe( int32 probeID, SlaveVP *animPr );
#define VMS__record_sched_choice_into_probe( probeID, animPr ) \
        /* do nothing */

void
VMS_impl__record_interval_start_in_probe( int32 probeID );
#define VMS__record_interval_start_in_probe( probeID ) \
        /* do nothing */

void
VMS_impl__record_interval_end_in_probe( int32 probeID );
#define VMS__record_interval_end_in_probe( probeID ) \
        /* do nothing */

inline void doNothing();
void
VMS_impl__print_stats_of_probe( int32 probeID );
#define VMS__print_stats_of_probe( probeID ) \
        doNothing/* do nothing */

void
VMS_impl__print_stats_of_all_probes();
#define VMS__print_stats_of_all_probes \
        doNothing/* do nothing */

#endif   /* defined STATS__ENABLE_PROBES */

#endif	/* _PROBES_H */

