From: Kiran <ki...@li...> - 2009-07-31 12:42:59
|
This patch adds a new API stats_container_append to libstats. This function adds a new stats_record_t to the records list in stats_container_t. Signed-off-by: Kiran Prakash <ki...@li...> Acked-by: Gowrishankar <gow...@in...> Acked-by: Darren Hart <dv...@us...> Acked-by: Sripathi Kodi <sri...@in...> diff -upr ltp-full-20090531_orig/testcases/realtime/include/libstats.h ltp-full-20090531/testcases/realtime/include/libstats.h --- ltp-full-20090531_orig/testcases/realtime/include/libstats.h 2008-04-20 22:50:18.000000000 +0530 +++ ltp-full-20090531/testcases/realtime/include/libstats.h 2009-07-24 18:39:11.000000000 +0530 @@ -56,6 +56,7 @@ typedef struct stats_record { typedef struct stats_container { long size; + long index; stats_record_t *records; } stats_container_t; @@ -162,4 +163,11 @@ void stats_hist_print(stats_container_t */ int stats_container_save(char *filename, char *title, char *labelx, char *labely, stats_container_t *data, char *mode); +/* stats_container_append - appends stats_record_t to data + * data: stats_container_t structure for holding the records list, index of + * min and max elements in records list and the sum + * rec: stats_record_t to be appended to the records list in data + * Returns the index of the appended record on success and -1 on error + */ +int stats_container_append(stats_container_t *data, stats_record_t rec); #endif /* LIBSTAT_H */ diff -upr ltp-full-20090531_orig/testcases/realtime/lib/libstats.c ltp-full-20090531/testcases/realtime/lib/libstats.c --- ltp-full-20090531_orig/testcases/realtime/lib/libstats.c 2008-04-20 22:50:18.000000000 +0530 +++ ltp-full-20090531/testcases/realtime/lib/libstats.c 2009-07-25 21:10:06.000000000 +0530 @@ -31,6 +31,7 @@ * * HISTORY * 2006-Oct-17: Initial version by Darren Hart + * 2009-Jul-22: Addition of stats_container_append function by Kiran Prakash * * TODO: the save routine for gnuplot plotting should be more modular... * @@ -43,6 +44,7 @@ #include <unistd.h> #include <math.h> #include <libstats.h> +#include <librttest.h> int save_stats = 0; @@ -62,12 +64,26 @@ static int stats_record_compare(const vo int stats_container_init(stats_container_t *data, long size) { data->size = size; + data->index = -1; data->records = calloc(size, sizeof(stats_record_t)); if (!data->records) return -1; return 0; } +int stats_container_append(stats_container_t *data, stats_record_t rec) +{ + int myindex = ++data->index; + if (myindex >= data->size) { + debug(DBG_ERR, "Number of elements cannot be more than %d\n", + data->size); + data->index--; + return -1; + } + data->records[myindex] = rec; + return myindex; +} + int stats_container_resize(stats_container_t *data, long size) { stats_record_t *newrecords = realloc(data->records, size*sizeof(stats_record_t)); -- Thanks, Kiran |