counters: global counters registration

pull/1508/head
Victor Julien 10 years ago
parent 9bbef55c4d
commit 06461e37da

@ -58,7 +58,9 @@ enum {
SC_PERF_TYPE_Q_NORMAL = 1, SC_PERF_TYPE_Q_NORMAL = 1,
SC_PERF_TYPE_Q_AVERAGE = 2, SC_PERF_TYPE_Q_AVERAGE = 2,
SC_PERF_TYPE_Q_MAXIMUM = 3, SC_PERF_TYPE_Q_MAXIMUM = 3,
SC_PERF_TYPE_Q_MAX = 4, SC_PERF_TYPE_Q_FUNC = 4,
SC_PERF_TYPE_Q_MAX = 5,
}; };
/** /**
@ -95,6 +97,9 @@ typedef struct SCPerfOPIfaceContext_ {
SCPerfClubTMInst *pctmi; SCPerfClubTMInst *pctmi;
SCMutex pctmi_lock; SCMutex pctmi_lock;
HashTable *counters_id_hash; HashTable *counters_id_hash;
//SCPerfCounter *global_counters;
SCPerfPublicContext global_counter_ctx;
} SCPerfOPIfaceContext; } SCPerfOPIfaceContext;
static void *stats_thread_data = NULL; static void *stats_thread_data = NULL;
@ -518,7 +523,7 @@ static void SCPerfReleaseCounter(SCPerfCounter *pc)
*/ */
static uint16_t SCPerfRegisterQualifiedCounter(char *cname, char *tm_name, static uint16_t SCPerfRegisterQualifiedCounter(char *cname, char *tm_name,
int type, SCPerfPublicContext *pctx, int type, SCPerfPublicContext *pctx,
int type_q) int type_q, uint64_t (*Func)(void))
{ {
SCPerfCounter **head = &pctx->head; SCPerfCounter **head = &pctx->head;
SCPerfCounter *temp = NULL; SCPerfCounter *temp = NULL;
@ -888,7 +893,7 @@ uint16_t SCPerfTVRegisterCounter(char *cname, struct ThreadVars_ *tv, int type)
(tv->thread_group_name != NULL) ? tv->thread_group_name : tv->name, (tv->thread_group_name != NULL) ? tv->thread_group_name : tv->name,
type, type,
&tv->perf_public_ctx, &tv->perf_public_ctx,
SC_PERF_TYPE_Q_NORMAL); SC_PERF_TYPE_Q_NORMAL, NULL);
return id; return id;
} }
@ -912,7 +917,7 @@ uint16_t SCPerfTVRegisterAvgCounter(char *cname, struct ThreadVars_ *tv,
(tv->thread_group_name != NULL) ? tv->thread_group_name : tv->name, (tv->thread_group_name != NULL) ? tv->thread_group_name : tv->name,
type, type,
&tv->perf_public_ctx, &tv->perf_public_ctx,
SC_PERF_TYPE_Q_AVERAGE); SC_PERF_TYPE_Q_AVERAGE, NULL);
return id; return id;
} }
@ -936,11 +941,30 @@ uint16_t SCPerfTVRegisterMaxCounter(char *cname, struct ThreadVars_ *tv,
(tv->thread_group_name != NULL) ? tv->thread_group_name : tv->name, (tv->thread_group_name != NULL) ? tv->thread_group_name : tv->name,
type, type,
&tv->perf_public_ctx, &tv->perf_public_ctx,
SC_PERF_TYPE_Q_MAXIMUM); SC_PERF_TYPE_Q_MAXIMUM, NULL);
return id; return id;
} }
/**
* \brief Registers a counter, which represents a global value
*
* \param cname Name of the counter, to be registered
* \param Func Function Pointer returning a uint64_t
*
* \retval id Counter id for the newly registered counter, or the already
* present counter
*/
uint16_t SCPerfTVRegisterGlobalCounter(char *cname, uint64_t (*Func)(void))
{
uint16_t id = SCPerfRegisterQualifiedCounter(cname, NULL,
SC_PERF_TYPE_UINT64,
&(sc_perf_op_ctx->global_counter_ctx),
SC_PERF_TYPE_Q_FUNC,
Func);
return id;
}
/** /**
* \brief Registers a normal, unqualified counter * \brief Registers a normal, unqualified counter
* *
@ -957,8 +981,8 @@ uint16_t SCPerfTVRegisterMaxCounter(char *cname, struct ThreadVars_ *tv,
static uint16_t SCPerfRegisterCounter(char *cname, char *tm_name, int type, static uint16_t SCPerfRegisterCounter(char *cname, char *tm_name, int type,
SCPerfPublicContext *pctx) SCPerfPublicContext *pctx)
{ {
uint16_t id = SCPerfRegisterQualifiedCounter(cname, tm_name, type, uint16_t id = SCPerfRegisterQualifiedCounter(cname, tm_name, type, pctx,
pctx, SC_PERF_TYPE_Q_NORMAL); SC_PERF_TYPE_Q_NORMAL, NULL);
return id; return id;
} }

@ -52,6 +52,10 @@ typedef struct SCPerfCounter_ {
uint64_t value; /**< sum of updates/increments, or 'set' value */ uint64_t value; /**< sum of updates/increments, or 'set' value */
uint64_t updates; /**< number of updates (for avg) */ uint64_t updates; /**< number of updates (for avg) */
/* when using type SC_PERF_TYPE_Q_FUNC this function is called once
* to get the counter value, regardless of how many threads there are. */
uint64_t (*Func)(void);
/* name of the counter */ /* name of the counter */
char *cname; char *cname;
/* name of the thread module this counter is registered to */ /* name of the thread module this counter is registered to */
@ -117,6 +121,7 @@ void SCPerfRegisterTests(void);
uint16_t SCPerfTVRegisterCounter(char *, struct ThreadVars_ *, int); uint16_t SCPerfTVRegisterCounter(char *, struct ThreadVars_ *, int);
uint16_t SCPerfTVRegisterAvgCounter(char *, struct ThreadVars_ *, int); uint16_t SCPerfTVRegisterAvgCounter(char *, struct ThreadVars_ *, int);
uint16_t SCPerfTVRegisterMaxCounter(char *, struct ThreadVars_ *, int); uint16_t SCPerfTVRegisterMaxCounter(char *, struct ThreadVars_ *, int);
uint16_t SCPerfTVRegisterGlobalCounter(char *cname, uint64_t (*Func)(void));
/* utility functions */ /* utility functions */
int SCPerfUpdateCounterArray(SCPerfPrivateContext *, SCPerfPublicContext *); int SCPerfUpdateCounterArray(SCPerfPrivateContext *, SCPerfPublicContext *);

Loading…
Cancel
Save