/** Copyright (c) 2009 Open Information Security Foundation. * \author Anoop Saldanha */ #include "eidps-common.h" #include "eidps.h" #include "counters.h" #include "threadvars.h" #include "tm-modules.h" #include "tm-threads.h" #include "util-unittest.h" #include "conf.h" #include "util-debug.h" /** \todo Get the default log directory from some global resource. */ #define SC_PERF_DEFAULT_LOG_FILENAME "stats.log" static SCPerfOPIfaceContext *sc_perf_op_ctx = NULL; /** * \brief Get the filename with path to the stats log file. * * This function returns a string containing the log filename. It uses * allocated memory simply to drop into the existing code a little better * where a strdup was used. So as before, it is up to the caller to free * the memory. * * \retval An allocated string containing the log filename on success or NULL on * failure. */ static char *SCPerfGetLogFilename(void) { char *log_dir = NULL; char *log_filename = NULL; if (ConfGet("default-log-dir", &log_dir) != 1) log_dir = DEFAULT_LOG_DIR; if ( (log_filename = malloc(PATH_MAX)) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } if (snprintf(log_filename, PATH_MAX, "%s/%s", log_dir, SC_PERF_DEFAULT_LOG_FILENAME) < 0) { SCLogError(SC_SPRINTF_ERROR, "Sprintf Error"); return NULL; } return log_filename; } /** * \brief Initializes the output interface context * * \todo Support multiple interfaces */ static void SCPerfInitOPCtx(void) { if ( (sc_perf_op_ctx = malloc(sizeof(SCPerfOPIfaceContext))) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } memset(sc_perf_op_ctx, 0, sizeof(SCPerfOPIfaceContext)); sc_perf_op_ctx->iface = SC_PERF_IFACE_FILE; if ( (sc_perf_op_ctx->file = SCPerfGetLogFilename()) == NULL) { SCLogInfo("Error retrieving Perf Counter API output file path"); sc_perf_op_ctx->file = NULL; } if ( (sc_perf_op_ctx->fp = fopen(sc_perf_op_ctx->file, "w+")) == NULL) { SCLogError(SC_ERR_OPENING_FILE, "fopen error opening file %s\n", sc_perf_op_ctx->file); sc_perf_op_ctx->fp = stdout; } /* club the counter from multiple instances of the tm before o/p */ sc_perf_op_ctx->club_tm = 1; /* init the lock used by SCPerfClubTMInst */ if (pthread_mutex_init(&sc_perf_op_ctx->pctmi_lock, NULL) != 0) { SCLogError(SC_INITIALIZATION_ERROR, "error initializing pctmi mutex"); exit(EXIT_FAILURE); } return; } /** * \brief Releases the resources alloted to the output context of the Perf * Counter API */ static void SCPerfReleaseOPCtx() { if (sc_perf_op_ctx != NULL) { if (sc_perf_op_ctx->fp != NULL) fclose(sc_perf_op_ctx->fp); if (sc_perf_op_ctx->file != NULL) free(sc_perf_op_ctx->file); if (sc_perf_op_ctx->pctmi != NULL) { if (sc_perf_op_ctx->pctmi->tm_name != NULL) free(sc_perf_op_ctx->pctmi->tm_name); if (sc_perf_op_ctx->pctmi->head != NULL) free(sc_perf_op_ctx->pctmi->head); free(sc_perf_op_ctx->pctmi); } free(sc_perf_op_ctx); } return; } /** * \brief The management thread. This thread is responsible for writing the * performance stats information. * * \param arg is NULL always * * \retval NULL This is the value that is always returned */ static void *SCPerfMgmtThread(void *arg) { ThreadVars *tv_local = (ThreadVars *)arg; uint8_t run = 1; struct timespec cond_time; if (sc_perf_op_ctx == NULL) { SCLogError(SC_INVALID_ARGUMENTS, "SCPerfInitCounterApi() has to be " "called first"); return NULL; } TmThreadsSetFlag(tv_local, THV_INIT_DONE); while (run) { TmThreadTestThreadUnPaused(tv_local); cond_time.tv_sec = time(NULL) + SC_PERF_MGMTT_TTS; cond_time.tv_nsec = 0; pthread_mutex_lock(tv_local->m); pthread_cond_timedwait(tv_local->cond, tv_local->m, &cond_time); pthread_mutex_unlock(tv_local->m); SCPerfOutputCounters(); if (TmThreadsCheckFlag(tv_local, THV_KILL)) { TmThreadsSetFlag(tv_local, THV_CLOSED); run = 0; } } return NULL; } /** * \brief Wake up thread. This thread wakes up every TTS(time to sleep) seconds * and sets the flag for every ThreadVars' SCPerfContext * * \param arg is NULL always * * \retval NULL This is the value that is always returned */ static void *SCPerfWakeupThread(void *arg) { ThreadVars *tv_local = (ThreadVars *)arg; uint8_t run = 1; ThreadVars *tv = NULL; PacketQueue *q = NULL; struct timespec cond_time; TmThreadsSetFlag(tv_local, THV_INIT_DONE); while (run) { TmThreadTestThreadUnPaused(tv_local); cond_time.tv_sec = time(NULL) + SC_PERF_WUT_TTS; cond_time.tv_nsec = 0; pthread_mutex_lock(tv_local->m); pthread_cond_timedwait(tv_local->cond, tv_local->m, &cond_time); pthread_mutex_unlock(tv_local->m); tv = tv_root[TVT_PPT]; while (tv != NULL) { if (tv->inq == NULL || tv->sc_perf_pctx.head == NULL) { tv = tv->next; continue; } q = &trans_q[tv->inq->id]; /* assuming the assignment of an int to be atomic, and even if it's * not, it should be okay */ tv->sc_perf_pctx.perf_flag = 1; pthread_cond_signal(&q->cond_q); tv = tv->next; } if (TmThreadsCheckFlag(tv_local, THV_KILL)) { TmThreadsSetFlag(tv_local, THV_CLOSED); run = 0; } } return NULL; } /** * \brief Parses a time based counter interval * * \param pc Pointer to the PerfCounter that has to be updated with the * interval * \param interval Pointer to a character string that holds the time interval */ static void SCPerfParseTBCounterInterval(SCPerfCounter *pc, char *interval) { char *temp_interval = NULL; char *substr = NULL; if ( (temp_interval = strdup(interval)) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } return; } /** * \brief Registers a counter. Used internally by the Perf Counter API * * \param cname Name of the counter, to be registered * \param tm_name Thread module to which this counter belongs * \param type Datatype of this counter variable * \param desc Description of this counter * \param pctx SCPerfContext for this tm-tv instance * \param type_q Qualifier describing the type of counter to be registered * \param interval Time interval required by a SC_PERF_TYPE_Q_TIMEBASED counter * * \retval the counter id for the newly registered counter, or the already * present counter on success * \retval 0 on failure */ static uint16_t SCPerfRegisterQualifiedCounter(char *cname, char *tm_name, int type, char *desc, SCPerfContext *pctx, int type_q, char *interval) { SCPerfCounter **head = &pctx->head; SCPerfCounter *temp = NULL; SCPerfCounter *prev = NULL; SCPerfCounter *pc = NULL; if (cname == NULL || tm_name == NULL || pctx == NULL) { SCLogDebug("Counter name, tm name null or SCPerfContext NULL"); return 0; } /* (SC_PERF_TYPE_MAX - 1) because we haven't implemented SC_PERF_TYPE_STR */ if ((type >= (SC_PERF_TYPE_MAX - 1)) || (type < 0)) { SCLogError(SC_INVALID_ARGUMENTS, "Counters of type %" PRId32 " can't " "be registered", type); return 0; } temp = prev = *head; while (temp != NULL) { prev = temp; if (strcmp(cname, temp->name->cname) == 0 && strcmp(tm_name, temp->name->tm_name) == 0) { break; } temp = temp->next; } /* We already have a counter registered by this name */ if (temp != NULL) return(temp->id); if ( (pc = malloc(sizeof(SCPerfCounter))) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } memset(pc, 0, sizeof(SCPerfCounter)); if (prev == NULL) *head = pc; else prev->next = pc; if ( (pc->name = malloc(sizeof(SCPerfCounterName))) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); free(pc); exit(EXIT_FAILURE); } memset(pc->name, 0, sizeof(SCPerfCounterName)); if ( (pc->value = malloc(sizeof(SCPerfCounterValue))) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); free(pc->name); free(pc); exit(EXIT_FAILURE); } memset(pc->value, 0, sizeof(SCPerfCounterValue)); if ( (pc->name->cname = strdup(cname)) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } if ( (pc->name->tm_name = strdup(tm_name)) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } /* allocate memory to hold this counter value */ pc->value->type = type; switch (pc->value->type) { case SC_PERF_TYPE_UINT64: pc->value->size = sizeof(uint64_t); break; case SC_PERF_TYPE_DOUBLE: pc->value->size = sizeof(double); break; } if ( (pc->value->cvalue = malloc(pc->value->size)) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } memset(pc->value->cvalue, 0, pc->value->size); /* assign a unique id to this SCPerfCounter. The id is local to this * PerfContext. please note that the id start from 1, and not 0 */ pc->id = ++(pctx->curr_id); if (desc != NULL && (pc->desc = strdup(desc)) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } pc->type_q = type_q; /* handle timebased counters */ if (pc->type_q & SC_PERF_TYPE_Q_TIMEBASED) SCPerfParseTBCounterInterval(pc, interval); /* the display flag which specifies whether the counter should be displayed * or not */ pc->disp = 1; return pc->id; } /** * \brief Releases a perf counter. Used internally by * SCPerfReleaseSCPerfCounterS() * * \param pc Pointer to the SCPerfCounter to be freed */ static void SCPerfReleaseCounter(SCPerfCounter *pc) { if (pc != NULL) { if (pc->name != NULL) { if (pc->name->cname != NULL) free(pc->name->cname); if (pc->name->tm_name != NULL) free(pc->name->tm_name); free(pc->name); } if (pc->value != NULL) { if (pc->value->cvalue != NULL) free(pc->value->cvalue); free(pc->value); } if (pc->desc != NULL) free(pc->desc); free(pc); } return; } /** * \brief Copies the SCPerfCounter value from the local counter present in the * SCPerfCounterArray to its corresponding global counterpart. Used * internally by SCPerfUpdateCounterArray() * * \param pcae Pointer to the SCPerfCounterArray which holds the local * versions of the counters * \param reset_lc Flag which indicates if the values of the local counters * in the SCPerfCounterArray has to be reset or not */ static void SCPerfCopyCounterValue(SCPCAElem *pcae, int reset_lc) { SCPerfCounter *pc = NULL; double d_temp = 0; uint64_t ui64_temp = 0; int i = 0; pc = pcae->pc; switch (pc->value->type) { case SC_PERF_TYPE_UINT64: ui64_temp = pcae->ui64_cnt; if (pc->type_q & SC_PERF_TYPE_Q_AVERAGE) { for (i = 0; i < pcae->wrapped_syncs; i++) ui64_temp /= ULONG_MAX; if (pcae->syncs != 0) ui64_temp /= pcae->syncs; } memcpy(pc->value->cvalue, &ui64_temp, pc->value->size); if (reset_lc) pcae->ui64_cnt = 0; break; case SC_PERF_TYPE_DOUBLE: d_temp = pcae->d_cnt; if (pc->type_q & SC_PERF_TYPE_Q_AVERAGE) { for (i = 0; i < pcae->wrapped_syncs; i++) d_temp /= ULONG_MAX; if (pcae->syncs != 0) d_temp /= pcae->syncs; } memcpy(pc->value->cvalue, &d_temp, pc->value->size); if (reset_lc) pcae->d_cnt = 0; break; } return; } /** * \brief The file output interface for the Perf Counter api */ static int SCPerfOutputCounterFileIface() { ThreadVars *tv = NULL; SCPerfClubTMInst *pctmi = NULL; SCPerfCounter *pc = NULL; SCPerfCounter **pc_heads = NULL; uint64_t *ui64_cvalue = NULL; uint64_t ui64_result = 0; double *double_cvalue = NULL; double double_result = 0; struct timeval tval; struct tm *tms; int i = 0; int flag = 0; if (sc_perf_op_ctx->fp == NULL) { SCLogDebug("perf_op_ctx->fp is NULL"); return 0; } memset(&tval, 0, sizeof(struct timeval)); gettimeofday(&tval, NULL); tms = (struct tm *)localtime(&tval.tv_sec); fprintf(sc_perf_op_ctx->fp, "----------------------------------------------" "---------------------\n"); fprintf(sc_perf_op_ctx->fp, "%" PRId32 "/%" PRId32 "/%04d -- %02d:%02d:%02d\n", tms->tm_mday, tms->tm_mon, tms->tm_year + 1900, tms->tm_hour, tms->tm_min, tms->tm_sec); fprintf(sc_perf_op_ctx->fp, "----------------------------------------------" "---------------------\n"); fprintf(sc_perf_op_ctx->fp, "%-25s | %-25s | %-s\n", "Counter", "TM Name", "Value"); fprintf(sc_perf_op_ctx->fp, "----------------------------------------------" "---------------------\n"); if (sc_perf_op_ctx->club_tm == 0) { for (i = 0; i < TVT_MAX; i++) { tv = tv_root[i]; while (tv != NULL) { pthread_mutex_lock(&tv->sc_perf_pctx.m); pc = tv->sc_perf_pctx.head; while (pc != NULL) { if (pc->disp == 0) { pc = pc->next; continue; } ui64_cvalue = (uint64_t *)pc->value->cvalue; fprintf(sc_perf_op_ctx->fp, "%-25s | %-25s | %-" PRIu64 "\n", pc->name->cname, pc->name->tm_name, *ui64_cvalue); pc = pc->next; } pthread_mutex_unlock(&tv->sc_perf_pctx.m); tv = tv->next; } fflush(sc_perf_op_ctx->fp); } return 1; } pctmi = sc_perf_op_ctx->pctmi; while (pctmi != NULL) { if ( (pc_heads = malloc(pctmi->size * sizeof(SCPerfCounter *))) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } memset(pc_heads, 0, pctmi->size * sizeof(SCPerfCounter **)); for (i = 0; i < pctmi->size; i++) { pc_heads[i] = pctmi->head[i]->head; pthread_mutex_lock(&pctmi->head[i]->m); while(strcmp(pctmi->tm_name, pc_heads[i]->name->tm_name)) pc_heads[i] = pc_heads[i]->next; } flag = 1; while(flag) { ui64_result = 0; double_result = 0; pc = pc_heads[0]; for (i = 0; i < pctmi->size; i++) { switch (pc->value->type) { case SC_PERF_TYPE_UINT64: ui64_cvalue = pc_heads[i]->value->cvalue; ui64_result += *ui64_cvalue; break; case SC_PERF_TYPE_DOUBLE: double_cvalue = pc_heads[i]->value->cvalue; double_result += *double_cvalue; break; } pc_heads[i] = pc_heads[i]->next; if (pc_heads[i] == NULL || strcmp(pctmi->tm_name, pc_heads[0]->name->tm_name)) flag = 0; } if (pc->disp == 0) continue; switch (pc->value->type) { case SC_PERF_TYPE_UINT64: fprintf(sc_perf_op_ctx->fp, "%-25s | %-25s | %-" PRIu64 "\n", pc->name->cname, pctmi->tm_name, ui64_result); break; case SC_PERF_TYPE_DOUBLE: fprintf(sc_perf_op_ctx->fp, "%-25s | %-25s | %-lf\n", pc->name->cname, pctmi->tm_name, double_result); break; } } for (i = 0; i < pctmi->size; i++) pthread_mutex_unlock(&pctmi->head[i]->m); pctmi = pctmi->next; free(pc_heads); fflush(sc_perf_op_ctx->fp); } return 1; } /** * \brief Initializes the perf counter api. Things are hard coded currently. * More work to be done when we implement multiple interfaces */ void SCPerfInitCounterApi(void) { SCPerfInitOPCtx(); return; } /** * \brief Spawns the wakeup, and the management thread used by the perf * counter api */ void SCPerfSpawnThreads(void) { ThreadVars *tv_wakeup = NULL; ThreadVars *tv_mgmt = NULL; /* Spawn the stats wakeup thread */ tv_wakeup = TmThreadCreateMgmtThread("SCPerfWakeupThread", SCPerfWakeupThread, 1); if (tv_wakeup == NULL) { SCLogError(SC_ERR_THREAD_CREATE_ERROR, "TmThreadCreateMgmtThread " "failed"); exit(EXIT_FAILURE); } if (TmThreadSpawn(tv_wakeup) != 0) { SCLogError(SC_THREAD_SPAWN_FAILED, "TmThreadSpawn failed for " "SCPerfWakeupThread"); exit(EXIT_FAILURE); } /* Spawn the stats mgmt thread */ tv_mgmt = TmThreadCreateMgmtThread("SCPerfMgmtThread", SCPerfMgmtThread, 1); if (tv_mgmt == NULL) { SCLogError(SC_ERR_THREAD_CREATE_ERROR, "TmThreadCreateMgmtThread failed"); exit(EXIT_FAILURE); } if (TmThreadSpawn(tv_mgmt) != 0) { SCLogError(SC_THREAD_SPAWN_FAILED, "TmThreadSpawn failed for " "SCPerfWakeupThread"); exit(EXIT_FAILURE); } return; } /** * \brief Registers a normal, unqualified counter * * \param cname Name of the counter, to be registered * \param tv Pointer to the ThreadVars instance for which the counter would * be registered * \param type Datatype of this counter variable * \param desc Description of this counter * * \retval id Counter id for the newly registered counter, or the already * present counter */ uint16_t SCPerfTVRegisterCounter(char *cname, struct ThreadVars_ *tv, int type, char *desc) { uint16_t id = SCPerfRegisterQualifiedCounter(cname, tv->name, type, desc, &tv->sc_perf_pctx, SC_PERF_TYPE_Q_NORMAL, NULL); return id; } /** * \brief Registers a counter, whose value holds the average of all the values * assigned to it. * * \param cname Name of the counter, to be registered * \param tv Pointer to the ThreadVars instance for which the counter would * be registered * \param type Datatype of this counter variable * \param desc Description of this counter * * \retval id Counter id for the newly registered counter, or the already * present counter */ uint16_t SCPerfTVRegisterAvgCounter(char *cname, struct ThreadVars_ *tv, int type, char *desc) { uint16_t id = SCPerfRegisterQualifiedCounter(cname, tv->name, type, desc, &tv->sc_perf_pctx, SC_PERF_TYPE_Q_AVERAGE, NULL); return id; } /** * \brief Registers a counter, whose value holds the maximum of all the values * assigned to it. * * \param cname Name of the counter, to be registered * \param tv Pointer to the ThreadVars instance for which the counter would * be registered * \param type Datatype of this counter variable * \param desc Description of this counter * * \retval the counter id for the newly registered counter, or the already * present counter */ uint16_t SCPerfTVRegisterMaxCounter(char *cname, struct ThreadVars_ *tv, int type, char *desc) { uint16_t id = SCPerfRegisterQualifiedCounter(cname, tv->name, type, desc, &tv->sc_perf_pctx, SC_PERF_TYPE_Q_MAXIMUM, NULL); return id; } /** * \brief Registers a counter, whose value holds the value taken held the * counter in a specified time interval * * \param cname Name of the counter, to be registered * \param tv Pointer to the ThreadVars instance for which the counter * would be registered * \param type Datatype of this counter variable * \param desc Description of this counter * \param interval The time interval over which the counter value has to be * calculated. The format for the time interval is * "", where number > 0, and modifier can * be "s" for seconds, "m" for minutes, "h" for hours * * \retval id Counter id for the newly registered counter, or the already * present counter */ uint16_t SCPerfTVRegisterIntervalCounter(char *cname, struct ThreadVars_ *tv, int type, char *desc, char *time_interval) { uint16_t id = SCPerfRegisterQualifiedCounter(cname, tv->name, type, desc, &tv->sc_perf_pctx, SC_PERF_TYPE_Q_MAXIMUM, time_interval); return id; } /** * \brief Registers a normal, unqualified counter * * \param cname Name of the counter, to be registered * \param tm_name Name of the engine module under which the counter has to be * registered * \param type Datatype of this counter variable * \param desc Description of this counter * \param pctx SCPerfContext corresponding to the tm_name key under which the * key has to be registered * * \retval id Counter id for the newly registered counter, or the already * present counter */ uint16_t SCPerfRegisterCounter(char *cname, char *tm_name, int type, char *desc, SCPerfContext *pctx) { uint16_t id = SCPerfRegisterQualifiedCounter(cname, tm_name, type, desc, pctx, SC_PERF_TYPE_Q_NORMAL, NULL); return id; } /** * \brief Registers a counter, whose value holds the average of all the values * assigned to it. * * \param cname Name of the counter, to be registered * \param tm_name Name of the engine module under which the counter has to be * registered * \param type Datatype of this counter variable * \param desc Description of this counter * \param pctx SCPerfContext corresponding to the tm_name key under which the * key has to be registered * * \retval id Counter id for the newly registered counter, or the already * present counter */ uint16_t SCPerfRegisterAvgCounter(char *cname, char *tm_name, int type, char *desc, SCPerfContext *pctx) { uint16_t id = SCPerfRegisterQualifiedCounter(cname, tm_name, type, desc, pctx, SC_PERF_TYPE_Q_AVERAGE, NULL); return id; } /** * \brief Registers a counter, whose value holds the maximum of all the values * assigned to it. * * \param cname Name of the counter, to be registered * \param tm_name Name of the engine module under which the counter has to be * registered * \param type Datatype of this counter variable * \param desc Description of this counter * \param pctx SCPerfContext corresponding to the tm_name key under which the * key has to be registered * * \retval id Counter id for the newly registered counter, or the already * present counter */ uint16_t SCPerfRegisterMaxCounter(char *cname, char *tm_name, int type, char *desc, SCPerfContext *pctx) { uint16_t id = SCPerfRegisterQualifiedCounter(cname, tm_name, type, desc, pctx, SC_PERF_TYPE_Q_MAXIMUM, NULL); return id; } /** * \brief Registers a counter, whose value holds the value taken held the * counter in a specified time interval * * \param cname Name of the counter, to be registered * \param tm_name Name of the engine module under which the counter has to be * registered * \param type Datatype of this counter variable * \param desc Description of this counter * \param pctx SCPerfContext corresponding to the tm_name key under which the * key has to be registered * \param interval The time interval over which the counter value has to be * calculated. The format for the time interval is * "", where number > 0, and modifier can * be "s" for seconds, "m" for minutes, "h" for hours * * \retval id Counter id for the newly registered counter, or the already * present counter */ uint16_t SCPerfRegisterIntervalCounter(char *cname, char *tm_name, int type, char *desc, SCPerfContext *pctx, char *time_interval) { uint16_t id = SCPerfRegisterQualifiedCounter(cname, tm_name, type, desc, pctx, SC_PERF_TYPE_Q_MAXIMUM, time_interval); return id; } /** * \brief Adds a TM to the clubbed TM table. Multiple instances of the same TM * are stacked together in a PCTMI container * * \param tm_name Name of the tm to be added to the table * \param pctx SCPerfContext associated with the TM tm_name * * \retval 1 on success, 0 on failure */ int SCPerfAddToClubbedTMTable(char *tm_name, SCPerfContext *pctx) { SCPerfClubTMInst *pctmi = NULL; SCPerfClubTMInst *prev = NULL; SCPerfClubTMInst *temp = NULL; SCPerfContext **hpctx = NULL; int i = 0; if (tm_name == NULL || pctx == NULL) { SCLogDebug("supplied argument(s) to SCPerfAddToClubbedTMTable NULL"); return 0; } pthread_mutex_lock(&sc_perf_op_ctx->pctmi_lock); pctmi = sc_perf_op_ctx->pctmi; prev = pctmi; while (pctmi != NULL) { prev = pctmi; if (strcmp(tm_name, pctmi->tm_name) != 0) { pctmi = pctmi->next; continue; } break; } if (pctmi == NULL) { if ( (temp = malloc(sizeof(SCPerfClubTMInst))) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(0); } memset(temp, 0, sizeof(SCPerfClubTMInst)); temp->size++; temp->head = realloc(temp->head, temp->size * sizeof(SCPerfContext **)); temp->head[0] = pctx; temp->tm_name = strdup(tm_name); if (prev == NULL) sc_perf_op_ctx->pctmi = temp; else prev->next = temp; pthread_mutex_unlock(&sc_perf_op_ctx->pctmi_lock); return 1; } hpctx = pctmi->head; for (i = 0; i < pctmi->size; i++) { if (hpctx[i] != pctx) continue; pthread_mutex_unlock(&sc_perf_op_ctx->pctmi_lock); return 1; } pctmi->head = realloc(pctmi->head, (pctmi->size + 1) * sizeof(SCPerfContext **)); hpctx = pctmi->head; hpctx[pctmi->size] = pctx; for (i = pctmi->size - 1; i >= 0; i--) { if (pctx->curr_id <= hpctx[i]->curr_id) { hpctx[i + 1] = hpctx[i]; hpctx[i] = pctx; continue; } break; } pctmi->size++; pthread_mutex_unlock(&sc_perf_op_ctx->pctmi_lock); return 1; } /** * \brief Returns a counter array for counters in this id range(s_id - e_id) * * \param s_id Counter id of the first counter to be added to the array * \param e_id Counter id of the last counter to be added to the array * \param pctx Pointer to the tv's SCPerfContext * * \retval a counter-array in this(s_id-e_id) range for this TM instance */ SCPerfCounterArray *SCPerfGetCounterArrayRange(uint16_t s_id, uint16_t e_id, SCPerfContext *pctx) { SCPerfCounter *pc = NULL; SCPerfCounterArray *pca = NULL; uint32_t i = 0; if (pctx == NULL) { SCLogDebug("pctx is NULL"); return NULL; } if (s_id < 1 || e_id < 1 || s_id > e_id) { SCLogDebug("error with the counter ids"); return NULL; } if (e_id > pctx->curr_id) { SCLogDebug("end id is greater than the max id for this tv"); return NULL; } if (pctx == NULL) { SCLogDebug("perfcontext is NULL"); return NULL; } if ( (pca = malloc(sizeof(SCPerfCounterArray))) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } memset(pca, 0, sizeof(SCPerfCounterArray)); if ( (pca->head = malloc(sizeof(SCPCAElem) * (e_id - s_id + 2))) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } memset(pca->head, 0, sizeof(SCPCAElem) * (e_id - s_id + 2)); pc = pctx->head; while (pc->id != s_id) pc = pc->next; i = 1; while ((pc != NULL) && (pc->id <= e_id)) { pca->head[i].pc = pc; pca->head[i].id = pc->id; pc = pc->next; i++; } pca->size = i - 1; return pca; } /** * \brief Returns a counter array for all counters registered for this tm * instance * * \param pctx Pointer to the tv's SCPerfContext * * \retval a counter-array for all counters of this tm instance */ SCPerfCounterArray *SCPerfGetAllCountersArray(SCPerfContext *pctx) { return ((pctx)? SCPerfGetCounterArrayRange(1, pctx->curr_id, pctx): NULL); } /** * \brief Allows the user the set whether the counter identified with the id * should be displayed or not in the output * * \param id Id of the counter * \param pctx Pointer to the SCPerfContext in which the counter exists * \param disp Holds a 0 or a non-zero value, based on whether the counter * should be displayed or not, in the output * * \retval 1 on success, 0 on failure */ int SCPerfCounterDisplay(uint16_t id, SCPerfContext *pctx, int disp) { SCPerfCounter *pc = NULL; if (pctx == NULL) { SCLogDebug("pctx null inside SCPerfCounterDisplay"); return 0; } if ( (id < 1) || (id > pctx->curr_id) ) { SCLogDebug("counter with the id %d doesn't exist in this tm instance", id); return 0; } pc = pctx->head; while(pc->id != id) pc = pc->next; pc->disp = (disp != 0); return 1; } /** * \brief Increments the local counter * * \param id Index of the counter in the counter array * \param pca Counter array that holds the local counters for this TM */ inline void SCPerfCounterIncr(uint16_t id, SCPerfCounterArray *pca) { if (pca == NULL) { SCLogDebug("counterarray is NULL"); return; } if ((id < 1) || (id > pca->size)) { SCLogDebug("counter doesn't exist"); return; } switch (pca->head[id].pc->value->type) { case SC_PERF_TYPE_UINT64: pca->head[id].ui64_cnt++; break; case SC_PERF_TYPE_DOUBLE: pca->head[id].d_cnt++; break; } if (pca->head[id].syncs == ULONG_MAX) { pca->head[id].syncs = 0; pca->head[id].wrapped_syncs++; } pca->head[id].syncs++; return; } /** * \brief Adds a value of type uint64_t to the local counter. * * \param id ID of the counter as set by the API * \param pca Counter array that holds the local counter for this TM * \param x Value to add to this local counter */ inline void SCPerfCounterAddUI64(uint16_t id, SCPerfCounterArray *pca, uint64_t x) { if (!pca) { SCLogDebug("counterarray is NULL"); return; } if ((id < 1) || (id > pca->size)) { SCLogDebug("counter doesn't exist"); return; } switch (pca->head[id].pc->value->type) { case SC_PERF_TYPE_UINT64: pca->head[id].ui64_cnt += x; break; case SC_PERF_TYPE_DOUBLE: pca->head[id].d_cnt += x; break; } if (pca->head[id].syncs == ULONG_MAX) { pca->head[id].syncs = 0; pca->head[id].wrapped_syncs++; } pca->head[id].syncs++; return; } /** * \brief Adds a value of type double to the local counter * * \param id ID of the counter as set by the API * \param pca Counter array that holds the local counter for this TM * \param x Value to add to this local counter */ inline void SCPerfCounterAddDouble(uint16_t id, SCPerfCounterArray *pca, double x) { if (!pca) { SCLogDebug("counterarray is NULL"); return; } if ((id < 1) || (id > pca->size)) { SCLogDebug("counter doesn't exist"); return; } /* incase you are trying to add a double to a counter of type SC_PERF_TYPE_UINT64 * it will be truncated */ switch (pca->head[id].pc->value->type) { case SC_PERF_TYPE_UINT64: pca->head[id].ui64_cnt += x; break; case SC_PERF_TYPE_DOUBLE: pca->head[id].d_cnt += x; break; } if (pca->head[id].syncs == ULONG_MAX) { pca->head[id].syncs = 0; pca->head[id].wrapped_syncs++; } pca->head[id].syncs++; return; } /** * \brief Sets a value of type double to the local counter * * \param id Index of the local counter in the counter array * \param pca Pointer to the SCPerfCounterArray * \param x The value to set for the counter */ inline void SCPerfCounterSetUI64(uint16_t id, SCPerfCounterArray *pca, uint64_t x) { if (!pca) { SCLogDebug("counterarray is NULL"); return; } if ((id < 1) || (id > pca->size)) { SCLogDebug("counter doesn't exist"); return; } switch (pca->head[id].pc->value->type) { case SC_PERF_TYPE_UINT64: if ( (pca->head[id].pc->type_q & SC_PERF_TYPE_Q_MAXIMUM) && (x > pca->head[id].ui64_cnt)) { pca->head[id].ui64_cnt = x; } else if (pca->head[id].pc->type_q & SC_PERF_TYPE_Q_NORMAL) { pca->head[id].ui64_cnt = x; } break; case SC_PERF_TYPE_DOUBLE: if ( (pca->head[id].pc->type_q & SC_PERF_TYPE_Q_MAXIMUM) && (x > pca->head[id].d_cnt)) { pca->head[id].d_cnt = x; } else if (pca->head[id].pc->type_q & SC_PERF_TYPE_Q_NORMAL) { pca->head[id].d_cnt = x; } break; } if (pca->head[id].syncs == ULONG_MAX) { pca->head[id].syncs = 0; pca->head[id].wrapped_syncs++; } pca->head[id].syncs++; return; } /** * \brief Sets a local counter to an arg of type double * * \param id Index of the local counter in the counter array * \param pca Pointer to the SCPerfCounterArray * \param x The value to set for the counter */ inline void SCPerfCounterSetDouble(uint16_t id, SCPerfCounterArray *pca, double x) { if (!pca) { SCLogDebug("counterarray is NULL"); return; } if ((id < 1) || (id > pca->size)) { SCLogDebug("counter doesn't exist"); return; } switch (pca->head[id].pc->value->type) { case SC_PERF_TYPE_UINT64: if ( (pca->head[id].pc->type_q & SC_PERF_TYPE_Q_MAXIMUM) && (x > pca->head[id].ui64_cnt)) { pca->head[id].ui64_cnt = x; } else if (pca->head[id].pc->type_q & SC_PERF_TYPE_Q_NORMAL) { pca->head[id].ui64_cnt = x; } break; case SC_PERF_TYPE_DOUBLE: if ( (pca->head[id].pc->type_q & SC_PERF_TYPE_Q_MAXIMUM) && (x > pca->head[id].d_cnt)) { pca->head[id].d_cnt = x; } else if (pca->head[id].pc->type_q & SC_PERF_TYPE_Q_NORMAL) { pca->head[id].d_cnt = x; } break; } if (pca->head[id].syncs == ULONG_MAX) { pca->head[id].syncs = 0; pca->head[id].wrapped_syncs++; } pca->head[id].syncs++; return; } /** * \brief Syncs the counter array with the global counter variables * * \param pca Pointer to the SCPerfCounterArray * \param pctx Pointer the the tv's SCPerfContext * \param reset_lc Indicates whether the local counter has to be reset or not * * \retval 0 on success * \retval -1 on error */ int SCPerfUpdateCounterArray(SCPerfCounterArray *pca, SCPerfContext *pctx, int reset_lc) { SCPerfCounter *pc = NULL; SCPCAElem *pcae = NULL; uint32_t i = 0; if (pca == NULL || pctx == NULL) { SCLogDebug("pca or pctx is NULL inside SCPerfUpdateCounterArray"); return -1; } pcae = pca->head; pthread_mutex_lock(&pctx->m); pc = pctx->head; for (i = 1; i <= pca->size; i++) { while (pc != NULL) { if (pc->id != pcae[i].id) { pc = pc->next; continue; } SCPerfCopyCounterValue(&pcae[i], reset_lc); pc->updated++; pc = pc->next; break; } } pthread_mutex_unlock(&pctx->m); pctx->perf_flag = 0; return 1; } /** * \brief The output interface dispatcher for the counter api */ void SCPerfOutputCounters() { switch (sc_perf_op_ctx->iface) { case SC_PERF_IFACE_FILE: SCPerfOutputCounterFileIface(); break; case SC_PERF_IFACE_CONSOLE: /* yet to be implemented */ break; case SC_PERF_IFACE_SYSLOG: /* yet to be implemented */ break; } return; } /** * \brief Releases the resources alloted by the Perf Counter API */ void SCPerfReleaseResources() { SCPerfReleaseOPCtx(); return; } /** * \brief Releases a list of perf counters * * \param head Pointer to the head of the list of perf counters that have to * be freed */ void SCPerfReleaseSCPerfCounterS(SCPerfCounter *head) { SCPerfCounter *pc = NULL; while (head != NULL) { pc = head; head = head->next; SCPerfReleaseCounter(pc); } return; } /** * \brief Releases the SCPerfCounterArray allocated by the user, for storing and * updating local counter values * * \param pca Pointer to the SCPerfCounterArray */ void SCPerfReleasePCA(SCPerfCounterArray *pca) { if (pca != NULL) { if (pca->head != NULL) free(pca->head); free(pca); } return; } /*----------------------------------Unit_Tests--------------------------------*/ static int SCPerfTestCounterReg01() { SCPerfContext pctx; memset(&pctx, 0, sizeof(SCPerfContext)); return SCPerfRegisterCounter("t1", "c1", 5, NULL, &pctx); } static int SCPerfTestCounterReg02() { SCPerfContext pctx; memset(&pctx, 0, sizeof(SCPerfContext)); return SCPerfRegisterCounter(NULL, NULL, SC_PERF_TYPE_UINT64, NULL, &pctx); } static int SCPerfTestCounterReg03() { SCPerfContext pctx; int result; memset(&pctx, 0, sizeof(SCPerfContext)); result = SCPerfRegisterCounter("t1", "c1", SC_PERF_TYPE_UINT64, NULL, &pctx); SCPerfReleaseSCPerfCounterS(pctx.head); return result; } static int SCPerfTestCounterReg04() { SCPerfContext pctx; int result; memset(&pctx, 0, sizeof(SCPerfContext)); SCPerfRegisterCounter("t1", "c1", SC_PERF_TYPE_UINT64, NULL, &pctx); SCPerfRegisterCounter("t2", "c2", SC_PERF_TYPE_UINT64, NULL, &pctx); SCPerfRegisterCounter("t3", "c3", SC_PERF_TYPE_UINT64, NULL, &pctx); result = SCPerfRegisterCounter("t1", "c1", SC_PERF_TYPE_UINT64, NULL, &pctx); SCPerfReleaseSCPerfCounterS(pctx.head); return result; } static int SCPerfTestGetCntArray05() { ThreadVars tv; int id; memset(&tv, 0, sizeof(ThreadVars)); id = SCPerfRegisterCounter("t1", "c1", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); tv.sc_perf_pca = SCPerfGetAllCountersArray(NULL); return (!tv.sc_perf_pca)?1:0; } static int SCPerfTestGetCntArray06() { ThreadVars tv; int id; int result; memset(&tv, 0, sizeof(ThreadVars)); id = SCPerfRegisterCounter("t1", "c1", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); tv.sc_perf_pca = SCPerfGetAllCountersArray(&tv.sc_perf_pctx); result = (tv.sc_perf_pca)?1:0; SCPerfReleaseSCPerfCounterS(tv.sc_perf_pctx.head); SCPerfReleasePCA(tv.sc_perf_pca); return result; } static int SCPerfTestCntArraySize07() { ThreadVars tv; SCPerfCounterArray *pca = NULL; int result; memset(&tv, 0, sizeof(ThreadVars)); pca = (SCPerfCounterArray *)&tv.sc_perf_pca; SCPerfRegisterCounter("t1", "c1", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); SCPerfRegisterCounter("t2", "c2", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); pca = SCPerfGetAllCountersArray(&tv.sc_perf_pctx); SCPerfCounterIncr(1, pca); SCPerfCounterIncr(2, pca); result = pca->size; SCPerfReleaseSCPerfCounterS(tv.sc_perf_pctx.head); SCPerfReleasePCA(pca); return result; } static int SCPerfTestUpdateCounter08() { ThreadVars tv; SCPerfCounterArray *pca = NULL; int id; int result; memset(&tv, 0, sizeof(ThreadVars)); id = SCPerfRegisterCounter("t1", "c1", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); pca = SCPerfGetAllCountersArray(&tv.sc_perf_pctx); SCPerfCounterIncr(id, pca); SCPerfCounterAddUI64(id, pca, 100); result = pca->head[id].ui64_cnt; SCPerfReleaseSCPerfCounterS(tv.sc_perf_pctx.head); SCPerfReleasePCA(pca); return result; } static int SCPerfTestUpdateCounter09() { ThreadVars tv; SCPerfCounterArray *pca = NULL; uint16_t id1, id2; int result; memset(&tv, 0, sizeof(ThreadVars)); id1 = SCPerfRegisterCounter("t1", "c1", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); SCPerfRegisterCounter("t2", "c2", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); SCPerfRegisterCounter("t3", "c3", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); SCPerfRegisterCounter("t4", "c4", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); id2 = SCPerfRegisterCounter("t5", "c5", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); pca = SCPerfGetAllCountersArray(&tv.sc_perf_pctx); SCPerfCounterIncr(id2, pca); SCPerfCounterAddUI64(id2, pca, 100); result = (pca->head[id1].ui64_cnt == 0) && (pca->head[id2].ui64_cnt == 101); SCPerfReleaseSCPerfCounterS(tv.sc_perf_pctx.head); SCPerfReleasePCA(pca); return result; } static int SCPerfTestUpdateGlobalCounter10() { ThreadVars tv; SCPerfCounterArray *pca = NULL; int result = 1; uint16_t id1, id2, id3; uint64_t *p = NULL; memset(&tv, 0, sizeof(ThreadVars)); id1 = SCPerfRegisterCounter("t1", "c1", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); id2 = SCPerfRegisterCounter("t2", "c2", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); id3 = SCPerfRegisterCounter("t3", "c3", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); pca = SCPerfGetAllCountersArray(&tv.sc_perf_pctx); SCPerfCounterIncr(id1, pca); SCPerfCounterAddUI64(id2, pca, 100); SCPerfCounterIncr(id3, pca); SCPerfCounterAddUI64(id3, pca, 100); SCPerfUpdateCounterArray(pca, &tv.sc_perf_pctx, 0); p = (uint64_t *)tv.sc_perf_pctx.head->value->cvalue; result = (1 == *p); p = (uint64_t *)tv.sc_perf_pctx.head->next->value->cvalue; result &= (100 == *p); p = (uint64_t *)tv.sc_perf_pctx.head->next->next->value->cvalue; result &= (101 == *p); SCPerfReleaseSCPerfCounterS(tv.sc_perf_pctx.head); SCPerfReleasePCA(pca); return result; } static int SCPerfTestCounterValues11() { ThreadVars tv; SCPerfCounterArray *pca = NULL; int result = 1; uint16_t id1, id2, id3, id4; uint8_t *u8p; memset(&tv, 0, sizeof(ThreadVars)); id1 = SCPerfRegisterCounter("t1", "c1", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); id2 = SCPerfRegisterCounter("t2", "c2", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); id3 = SCPerfRegisterCounter("t3", "c3", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); id4 = SCPerfRegisterCounter("t4", "c4", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); pca = SCPerfGetAllCountersArray(&tv.sc_perf_pctx); SCPerfCounterIncr(id1, pca); SCPerfCounterAddUI64(id2, pca, 256); SCPerfCounterAddUI64(id3, pca, 257); SCPerfCounterAddUI64(id4, pca, 16843024); SCPerfUpdateCounterArray(pca, &tv.sc_perf_pctx, 0); u8p = (uint8_t *)tv.sc_perf_pctx.head->value->cvalue; result &= (1 == *u8p); result &= (0 == *(u8p + 1)); result &= (0 == *(u8p + 2)); result &= (0 == *(u8p + 3)); u8p = (uint8_t *)tv.sc_perf_pctx.head->next->value->cvalue; result &= (0 == *u8p); result &= (1 == *(u8p + 1)); result &= (0 == *(u8p + 2)); result &= (0 == *(u8p + 3)); u8p = (uint8_t *)tv.sc_perf_pctx.head->next->next->value->cvalue; result &= (1 == *u8p); result &= (1 == *(u8p + 1)); result &= (0 == *(u8p + 2)); result &= (0 == *(u8p + 3)); u8p = (uint8_t *)tv.sc_perf_pctx.head->next->next->next->value->cvalue; result &= (16 == *u8p); result &= (1 == *(u8p + 1)); result &= (1 == *(u8p + 2)); result &= (1 == *(u8p + 3)); SCPerfReleaseSCPerfCounterS(tv.sc_perf_pctx.head); SCPerfReleasePCA(pca); return result; } static int SCPerfTestAverageQual12() { ThreadVars tv; SCPerfCounterArray *pca = NULL; uint64_t *ui64_temp = NULL; double *d_temp = NULL; int result = 1; uint16_t id1, id2; memset(&tv, 0, sizeof(ThreadVars)); id1 = SCPerfRegisterAvgCounter("t1", "c1", SC_PERF_TYPE_DOUBLE, NULL, &tv.sc_perf_pctx); id2 = SCPerfRegisterAvgCounter("t2", "c2", SC_PERF_TYPE_UINT64, NULL, &tv.sc_perf_pctx); pca = SCPerfGetAllCountersArray(&tv.sc_perf_pctx); SCPerfCounterAddDouble(id1, pca, 1); SCPerfCounterAddDouble(id1, pca, 2); SCPerfCounterAddDouble(id1, pca, 3); SCPerfCounterAddDouble(id1, pca, 4); SCPerfCounterAddDouble(id1, pca, 5); SCPerfCounterAddDouble(id1, pca, 6); SCPerfUpdateCounterArray(pca, &tv.sc_perf_pctx, 0); result &= (21 == pca->head[1].d_cnt); result &= (6 == pca->head[1].syncs); result &= (0 == pca->head[1].wrapped_syncs); d_temp = tv.sc_perf_pctx.head->value->cvalue; result &= (3.5 == *d_temp); SCPerfCounterAddUI64(id2, pca, 1.635); SCPerfCounterAddUI64(id2, pca, 2.12); SCPerfCounterAddUI64(id2, pca, 3.74); SCPerfCounterAddUI64(id2, pca, 4.23); SCPerfCounterAddUI64(id2, pca, 5.76); SCPerfCounterAddDouble(id2, pca, 6.99999); SCPerfUpdateCounterArray(pca, &tv.sc_perf_pctx, 0); result &= (21 == pca->head[2].ui64_cnt); result &= (6 == pca->head[2].syncs); result &= (0 == pca->head[2].wrapped_syncs); ui64_temp = tv.sc_perf_pctx.head->next->value->cvalue; result &= (3 == *ui64_temp); return result; } static int SCPerfTestMaxQual13() { ThreadVars tv; SCPerfCounterArray *pca = NULL; double *p; int result = 1; uint16_t id1; memset(&tv, 0, sizeof(ThreadVars)); id1 = SCPerfRegisterMaxCounter("t1", "c1", SC_PERF_TYPE_DOUBLE, NULL, &tv.sc_perf_pctx); p = tv.sc_perf_pctx.head->value->cvalue; pca = SCPerfGetAllCountersArray(&tv.sc_perf_pctx); SCPerfCounterSetDouble(id1, pca, 1.352); SCPerfCounterSetDouble(id1, pca, 5.12412); SCPerfCounterSetDouble(id1, pca, 4.1234); SCPerfCounterSetDouble(id1, pca, 5.13562); SCPerfCounterSetDouble(id1, pca, 1.2342); SCPerfUpdateCounterArray(pca, &tv.sc_perf_pctx, 0); result &= (5.13562 == *p); SCPerfCounterSetDouble(id1, pca, 8); SCPerfCounterSetDouble(id1, pca, 7); SCPerfUpdateCounterArray(pca, &tv.sc_perf_pctx, 0); result &= (8 == *p); SCPerfCounterSetDouble(id1, pca, 6); SCPerfCounterSetUI64(id1, pca, 10); SCPerfCounterSetDouble(id1, pca, 9.562); SCPerfUpdateCounterArray(pca, &tv.sc_perf_pctx, 0); result &= (10 == *p); return result; } void SCPerfRegisterTests() { UtRegisterTest("SCPerfTestCounterReg01", SCPerfTestCounterReg01, 0); UtRegisterTest("SCPerfTestCounterReg02", SCPerfTestCounterReg02, 0); UtRegisterTest("SCPerfTestCounterReg03", SCPerfTestCounterReg03, 1); UtRegisterTest("SCPerfTestCounterReg04", SCPerfTestCounterReg04, 1); UtRegisterTest("SCPerfTestGetCntArray05", SCPerfTestGetCntArray05, 1); UtRegisterTest("SCPerfTestGetCntArray06", SCPerfTestGetCntArray06, 1); UtRegisterTest("SCPerfTestCntArraySize07", SCPerfTestCntArraySize07, 2); UtRegisterTest("SCPerfTestUpdateCounter08", SCPerfTestUpdateCounter08, 101); UtRegisterTest("SCPerfTestUpdateCounter09", SCPerfTestUpdateCounter09, 1); UtRegisterTest("SCPerfTestUpdateGlobalCounter10", SCPerfTestUpdateGlobalCounter10, 1); UtRegisterTest("SCPerfTestCounterValues11", SCPerfTestCounterValues11, 1); UtRegisterTest("SCPerfTestAverageQual12", SCPerfTestAverageQual12, 1); UtRegisterTest("SCPerfTestMaxQual13", SCPerfTestMaxQual13, 1); return; }