SC_PERF_TYPE_Q_NORMAL = 1,
SC_PERF_TYPE_Q_AVERAGE = 2,
SC_PERF_TYPE_Q_MAXIMUM = 3,
- SC_PERF_TYPE_Q_MAX = 4,
+ SC_PERF_TYPE_Q_FUNC = 4,
+
+ SC_PERF_TYPE_Q_MAX = 5,
};
/**
SCPerfClubTMInst *pctmi;
SCMutex pctmi_lock;
HashTable *counters_id_hash;
+
+ //SCPerfCounter *global_counters;
+ SCPerfPublicContext global_counter_ctx;
} SCPerfOPIfaceContext;
static void *stats_thread_data = NULL;
*/
static uint16_t SCPerfRegisterQualifiedCounter(char *cname, char *tm_name,
int type, SCPerfPublicContext *pctx,
- int type_q)
+ int type_q, uint64_t (*Func)(void))
{
SCPerfCounter **head = &pctx->head;
SCPerfCounter *temp = NULL;
(tv->thread_group_name != NULL) ? tv->thread_group_name : tv->name,
type,
&tv->perf_public_ctx,
- SC_PERF_TYPE_Q_NORMAL);
+ SC_PERF_TYPE_Q_NORMAL, NULL);
return id;
}
(tv->thread_group_name != NULL) ? tv->thread_group_name : tv->name,
type,
&tv->perf_public_ctx,
- SC_PERF_TYPE_Q_AVERAGE);
+ SC_PERF_TYPE_Q_AVERAGE, NULL);
return id;
}
(tv->thread_group_name != NULL) ? tv->thread_group_name : tv->name,
type,
&tv->perf_public_ctx,
- SC_PERF_TYPE_Q_MAXIMUM);
+ SC_PERF_TYPE_Q_MAXIMUM, NULL);
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
*
static uint16_t SCPerfRegisterCounter(char *cname, char *tm_name, int type,
SCPerfPublicContext *pctx)
{
- uint16_t id = SCPerfRegisterQualifiedCounter(cname, tm_name, type,
- pctx, SC_PERF_TYPE_Q_NORMAL);
+ uint16_t id = SCPerfRegisterQualifiedCounter(cname, tm_name, type, pctx,
+ SC_PERF_TYPE_Q_NORMAL, NULL);
return id;
}
uint64_t value; /**< sum of updates/increments, or 'set' value */
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 */
char *cname;
/* name of the thread module this counter is registered to */
uint16_t SCPerfTVRegisterCounter(char *, struct ThreadVars_ *, int);
uint16_t SCPerfTVRegisterAvgCounter(char *, struct ThreadVars_ *, int);
uint16_t SCPerfTVRegisterMaxCounter(char *, struct ThreadVars_ *, int);
+uint16_t SCPerfTVRegisterGlobalCounter(char *cname, uint64_t (*Func)(void));
/* utility functions */
int SCPerfUpdateCounterArray(SCPerfPrivateContext *, SCPerfPublicContext *);