Commit ab20d2d3 authored by malenov's avatar malenov
Browse files

resolve minor discrepancy in WMOPS numbers when WMOPS_DETAIL is used

parent bd6cae01
Loading
Loading
Loading
Loading
+80 −88
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ int cntr_push_pop = 0; /* global counter for checking balanced push_wmops()/pop_
 * Complexity counting tool
 *--------------------------------------------------------------------*/


#define MAX_FUNCTION_NAME_LENGTH     200 /* Maximum length of the function name */
#define MAX_PARAMS_LENGTH            200 /* Maximum length of the function parameter string */
#define MAX_NUM_RECORDS              300 /* Initial maximum number of records -> might be increased during runtime, if needed */
@@ -78,7 +79,6 @@ typedef struct
} wmops_record;

double ops_cnt;
double prom_cnt_wmc;
double inst_cnt[NUM_INST];

static wmops_record *wmops = NULL;
@@ -153,7 +153,7 @@ static BASIC_OP op_weight = {
};

BASIC_OP *multiCounter = NULL;
int currCounter = 0;
unsigned int currCounter = 0;
int funcId_where_last_call_to_else_occurred;
long funcid_total_wmops_at_last_call_to_else;
int call_occurred = 1;
@@ -162,7 +162,6 @@ char func_name_where_last_call_to_else_occurred[MAX_FUNCTION_NAME_LENGTH + 1];
void reset_wmops( void )
{
    int i, j;
    unsigned int *ptr;

    num_wmops_records = 0;
    max_num_wmops_records = MAX_NUM_RECORDS;
@@ -199,7 +198,7 @@ void reset_wmops( void )
    }

    /* initilize the list of WMOPS records */
    /* initilize the BASOP WMOPS counters */
    /* initilize BASOP operation counters */
    for ( i = 0; i < max_num_wmops_records; i++ )
    {
        strcpy( &wmops[i].label[0], "\0" );
@@ -226,13 +225,8 @@ void reset_wmops( void )
        wmops[i].wc_call_number = -1;
#endif

        /* clear all BASOP operation counters */
        ptr = (unsigned int *) &multiCounter[i];
        for ( j = 0; j < (int) ( sizeof( BASIC_OP ) / sizeof( unsigned int ) ); j++ )
        {
            *ptr++ = 0;
        }
        wmops[i].LastWOper = 0;
        /* Reset BASOP operation counter */
        Reset_BASOP_WMOPS_counter( i );
    }

    /* allocate the list of wmops callers to track the sequence of function calls */
@@ -254,7 +248,8 @@ void reset_wmops( void )
        wmops_caller_stack[i] = -1;
    }

    /* initialize auxiliary BASOP WMOPS variables */
    /* initialize auxiliary BASOP counter variables */
    currCounter = 0; /* Note: currCounter cannot be set to -1 because it's defined as unsigned int ! */
    call_occurred = 1;
    funcId_where_last_call_to_else_occurred = -100;

@@ -265,7 +260,7 @@ void push_wmops_fct( const char *label, ... )
{
    int new_flag;
    int i, j, index_record;
    unsigned int *ptr;
    long tot;
    va_list arg;
    char func_name[MAX_FUNCTION_NAME_LENGTH] = "";

@@ -302,44 +297,39 @@ void push_wmops_fct( const char *label, ... )
        }

        /* initilize the new WMOPS record */
        strcpy( &wmops[i].label[0], "\0" );
        wmops[i].call_number = 0;
        wmops[i].update_cnt = 0;
        strcpy( &wmops[index_record].label[0], "\0" );
        wmops[index_record].call_number = 0;
        wmops[index_record].update_cnt = 0;
        for ( j = 0; j < MAX_CALL_TREE_DEPTH; j++ )
        {
            wmops[i].call_tree[j] = -1;
        }
        wmops[i].start_selfcnt = 0.0;
        wmops[i].current_selfcnt = 0.0;
        wmops[i].max_selfcnt = 0.0;
        wmops[i].min_selfcnt = DOUBLE_MAX;
        wmops[i].tot_selfcnt = 0.0;
        wmops[i].start_cnt = 0.0;
        wmops[i].current_cnt = 0.0;
        wmops[i].max_cnt = 0.0;
        wmops[i].min_cnt = DOUBLE_MAX;
        wmops[i].tot_cnt = 0.0;
            wmops[index_record].call_tree[j] = -1;
        }
        wmops[index_record].start_selfcnt = 0.0;
        wmops[index_record].current_selfcnt = 0.0;
        wmops[index_record].max_selfcnt = 0.0;
        wmops[index_record].min_selfcnt = DOUBLE_MAX;
        wmops[index_record].tot_selfcnt = 0.0;
        wmops[index_record].start_cnt = 0.0;
        wmops[index_record].current_cnt = 0.0;
        wmops[index_record].max_cnt = 0.0;
        wmops[index_record].min_cnt = DOUBLE_MAX;
        wmops[index_record].tot_cnt = 0.0;
#ifdef WMOPS_WC_FRAME_ANALYSIS
        wmops[i].wc_cnt = 0.0;
        wmops[i].wc_selfcnt = 0.0;
        wmops[i].current_call_number = 0;
        wmops[i].wc_call_number = -1;
        wmops[index_record].wc_cnt = 0.0;
        wmops[index_record].wc_selfcnt = 0.0;
        wmops[index_record].current_call_number = 0;
        wmops[index_record].wc_call_number = -1;
#endif

        /* initialize BASOP WMOPS counters */
        ptr = (unsigned int *) &multiCounter[i];
        for ( j = 0; j < (int) ( sizeof( BASIC_OP ) / sizeof( unsigned int ) ); j++ )
        {
            *ptr++ = 0;
        }
        wmops[i].LastWOper = 0;
        /* Reset BASOP operation counter */
        Reset_BASOP_WMOPS_counter( index_record );

        strcpy( wmops[index_record].label, func_name );

        num_wmops_records++;
    }

    /* Push the current context info to the new record */
    /* Update the WMOPS context info of the old record before switching to the new one */
    if ( current_record >= 0 )
    {
        if ( wmops_caller_stack_index >= max_wmops_caller_stack_index )
@@ -350,7 +340,9 @@ void push_wmops_fct( const char *label, ... )
        }
        wmops_caller_stack[wmops_caller_stack_index++] = current_record;

        /* accumulate op counts */
        /* add the BASOP complexity to the counter and update the old WMOPS counter */
        tot = DeltaWeightedOperation( current_record );
        ops_cnt += tot;
        wmops[current_record].current_selfcnt += ops_cnt - wmops[current_record].start_selfcnt;

        /* update call tree */
@@ -368,7 +360,14 @@ void push_wmops_fct( const char *label, ... )
        }
    }

    /* update the current context info */
    /* Need to reset the BASOP operation counter of the 0th record in every push_wmops() */
    /* because currCounter can never be -1 */
    if ( current_record == -1 && index_record == 0 )
    {
        wmops[index_record].LastWOper = TotalWeightedOperation( index_record );
    }

    /* switch to the new record */
    current_record = index_record;
    wmops[index_record].start_selfcnt = ops_cnt;
    wmops[index_record].start_cnt = ops_cnt;
@@ -377,8 +376,9 @@ void push_wmops_fct( const char *label, ... )
    wmops[index_record].current_call_number++;
#endif

    /* set the ID of BASOP functions counters */
    Set_BASOP_WMOPS_counter( index_record );
    /* set the ID of the current BASOP operations counter */
    currCounter = index_record;
    call_occurred = 1;

    return;
}
@@ -395,7 +395,7 @@ void pop_wmops( void )
    }

    /* add the BASOP complexity to the counter */
    tot = DeltaWeightedOperation();
    tot = DeltaWeightedOperation( currCounter );
    ops_cnt += tot;

    /* update count of current record */
@@ -407,15 +407,23 @@ void pop_wmops( void )
    {
        current_record = wmops_caller_stack[--wmops_caller_stack_index];
        wmops[current_record].start_selfcnt = ops_cnt;

        /* set the ID of the previous BASOP counter */
        Set_BASOP_WMOPS_counter( current_record );
    }
    else
    {
        current_record = -1;
    }

    /* set the ID of the previous BASOP operations counter */
    if ( current_record == -1 )
    {
        currCounter = 0; /* Note: currCounter cannot be set to -1 because it's defined as unsigned int ! */
    }
    else
    {
        currCounter = current_record;
    }
    call_occurred = 1;

    return;
}

@@ -507,9 +515,9 @@ void update_wmops( void )
        wmops[i].current_call_number = 0;
#endif

        /* reset the BASOP counter */
        Set_BASOP_WMOPS_counter( i );
        Reset_BASOP_WMOPS_counter();
        /* reset the BASOP operations counter */
        call_occurred = 1;
        Reset_BASOP_WMOPS_counter( i );
    }

    current_cnt = ops_cnt - start_cnt;
@@ -2436,11 +2444,9 @@ int NE_64( long long int L64_var1, long long int L64_var2 )

void incrIf( const char *func_name )
{
    /* Technical note :
     * If the "IF" operator comes just after an "ELSE", its counter
     * must not be incremented.
     */
    if ( ( currCounter != funcId_where_last_call_to_else_occurred ) || ( strncmp( func_name, func_name_where_last_call_to_else_occurred, MAX_FUNCTION_NAME_LENGTH ) != 0 ) || ( TotalWeightedOperation() != funcid_total_wmops_at_last_call_to_else ) || ( call_occurred == 1 ) )
    /* Technical note: If the "IF" operator comes just after an "ELSE", its counter must not be incremented */
    /* The following auxiliary variables are used to check if the "IF" operator doesn't immediately follow an "ELSE" operator */
    if ( ( (int) currCounter != funcId_where_last_call_to_else_occurred ) || ( strncmp( func_name, func_name_where_last_call_to_else_occurred, MAX_FUNCTION_NAME_LENGTH ) != 0 ) || ( TotalWeightedOperation( currCounter) != funcid_total_wmops_at_last_call_to_else ) || ( call_occurred == 1 ) )
        multiCounter[currCounter].If++;

    call_occurred = 0;
@@ -2451,34 +2457,35 @@ void incrElse( const char *func_name )
{
    multiCounter[currCounter].If++;

    /* We keep track of the funcId of the last function which used ELSE {...} structure. */
    /* Save the BASOP counter Id in the last function in which ELSE() has been called */
    funcId_where_last_call_to_else_occurred = currCounter;

    /* We keep track of the number of WMOPS of this funcId when the ELSE macro was called. */
    funcid_total_wmops_at_last_call_to_else = TotalWeightedOperation();
    /* Save the BASOP comeplxity in the last call of the ELSE() statement */
    funcid_total_wmops_at_last_call_to_else = TotalWeightedOperation( currCounter );

    /* Save the function name in the last call of the ELSE() statement */
    strncpy( func_name_where_last_call_to_else_occurred, func_name, MAX_FUNCTION_NAME_LENGTH );
    func_name_where_last_call_to_else_occurred[MAX_FUNCTION_NAME_LENGTH] = '\0';

    /* call_occurred is set to 0, in order to count the next IF (if necessary) */
    /* Set call_occurred to 0 to prevent counting of complexity of the next "immediate" IF statement */
    call_occurred = 0;
}

long TotalWeightedOperation()
long TotalWeightedOperation( unsigned int CounterId )
{
    int i;
    unsigned int *ptr, *ptr2;
    long tot;

    tot = 0;
    ptr = (unsigned int *) &multiCounter[currCounter];
    ptr = (unsigned int *) &multiCounter[CounterId];
    ptr2 = (unsigned int *) &op_weight;

    for ( i = 0; i < (int) ( sizeof( multiCounter[currCounter] ) / sizeof( unsigned int ) ); i++ )
    for ( i = 0; i < (int) ( sizeof( multiCounter[CounterId] ) / sizeof( unsigned int ) ); i++ )
    {
        if ( *ptr == UINT_MAX )
        {
            printf( "\nError in BASOP complexity counters: multiCounter[%d][%d] = %d !!!\n", currCounter, i, *ptr );
            printf( "\nError in BASOP complexity counters: multiCounter[%d][%d] = %d !!!\n", CounterId, i, *ptr );
            exit( -1 );
        }

@@ -2488,47 +2495,32 @@ long TotalWeightedOperation()
    return ( tot );
}

long DeltaWeightedOperation( void )
long DeltaWeightedOperation( unsigned int CounterId )
{
    long NewWOper, delta;

    NewWOper = TotalWeightedOperation();
    NewWOper = TotalWeightedOperation( CounterId );

    delta = NewWOper - wmops[currCounter].LastWOper;
    wmops[currCounter].LastWOper = NewWOper;
    delta = NewWOper - wmops[CounterId].LastWOper;
    wmops[CounterId].LastWOper = NewWOper;

    return ( delta );
}

/* Set the counter group to use, default is zero */
void Set_BASOP_WMOPS_counter( int counterId )
{
    if ( ( counterId > num_wmops_records ) || ( counterId < 0 ) )
    {
        currCounter = 0;
        return;
    }

    currCounter = counterId;
    call_occurred = 1;

    return;
}

/* Resets the current BASOP WMOPS counter */
void Reset_BASOP_WMOPS_counter( void )
/* Resets BASOP operation counter */
void Reset_BASOP_WMOPS_counter( unsigned int counterId )
{
    int i;
    long *ptr;

    /* clear the current BASOP operation counter before new frame begins */
    ptr = (long *) &multiCounter[currCounter];
    for ( i = 0; i < (int) ( sizeof( multiCounter[currCounter] ) / sizeof( long ) ); i++ )
    /* reset the current BASOP operation counter */
    ptr = (long *) &multiCounter[counterId];
    for ( i = 0; i < (int) ( sizeof( multiCounter[counterId] ) / sizeof( long ) ); i++ )
    {
        *ptr++ = 0;
    }

    wmops[currCounter].LastWOper = 0;
    wmops[counterId].LastWOper = 0;

    return;
}
 No newline at end of file
+154 −493

File changed.

Preview size limit exceeded, changes collapsed.