summaryrefslogtreecommitdiff
path: root/cesar/lib
diff options
context:
space:
mode:
authordufour2010-02-12 15:51:25 +0000
committerdufour2010-02-12 15:51:25 +0000
commit38352f97090e3506ff2311dd66a852d2b4c8f3db (patch)
tree5c484cf81af1e1e1baee031e1f0e34e42c06715a /cesar/lib
parent074d0b4c01b516c14a0e0cc8771bc8146662cbfa (diff)
cesar/lib/stats: clean stats module (no code change)
This commit only include some cleaning changes: - move documentation in header file, - remove useless include, - conform to coding standards (wrap to 80 characters, correctly indent), - remove empty lines. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@6709 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/lib')
-rw-r--r--cesar/lib/src/stats.c294
-rw-r--r--cesar/lib/stats.h47
2 files changed, 185 insertions, 156 deletions
diff --git a/cesar/lib/src/stats.c b/cesar/lib/src/stats.c
index 2c8f4bc666..6c34645640 100644
--- a/cesar/lib/src/stats.c
+++ b/cesar/lib/src/stats.c
@@ -12,13 +12,11 @@
*/
#include "common/std.h"
-#include "common/defs/ethernet.h"
#include "stats.h"
#include "slab.h"
#include <string.h>
-#include <stdio.h>
/***********************************************************/
/* Local Definitions */
@@ -28,19 +26,19 @@
typedef struct lib_stats_stat_t
{
- const char* name;
+ const char *name;
lib_stats_types_t type;
- void* value;
- void* (*callback)(void);
- struct lib_stats_stat_t* next_stat;
+ void *value;
+ void *(*callback) (void);
+ struct lib_stats_stat_t *next_stat;
} lib_stats_stat_t;
typedef struct lib_stats_page_t
{
slab_cache_t stats_cache;
uint nb_stats; /* nb stats in page */
- lib_stats_stat_t* first_stat;
- lib_stats_stat_t* last_stat;
+ lib_stats_stat_t *first_stat;
+ lib_stats_stat_t *last_stat;
uint page_size;
struct lib_stats_page_t* next_page;
} lib_stats_page_t;
@@ -50,8 +48,8 @@ typedef struct lib_stats_book_t
slab_cache_t pages_cache;
slab_cache_t stats_cache;
uint nb_pages; /* nb pages in book */
- lib_stats_page_t* first_page;
- lib_stats_page_t* last_page;
+ lib_stats_page_t *first_page;
+ lib_stats_page_t *last_page;
} lib_stats_book_t;
/***********************************************************/
@@ -67,7 +65,8 @@ lib_stats_book_t lib_stats_book;
/**
* Get ASCII code from quartet hexa
*/
-u8 quartet2ascii(u8 quartet)
+u8
+quartet2ascii (u8 quartet)
{
u8 code;
@@ -81,20 +80,74 @@ u8 quartet2ascii(u8 quartet)
return code;
}
+/**
+ * Prepare the book to store a new stat
+ * \param name : string to be displayed before the stat value
+ * \param type : type and max size of the value in octet
+ */
+void
+lib_stats_new_stat (const char *name, lib_stats_types_t type)
+{
+ /* Check parameters */
+ dbg_assert (name);
+ dbg_assert (type);
+
+ int stat_size;
+
+ /* String lenght for this stat */
+ stat_size = strlen (name) + (2 * type) + 2;
+
+ /* Check if new stat doesn't fit in the current page */
+ if ((lib_stats_book.last_page->page_size + stat_size)
+ > LIB_STATS_MAX_PAGE_SIZE)
+ {
+ /* Create and init a new page */
+ lib_stats_book.last_page->next_page = slab_alloc
+ (&lib_stats_book.pages_cache);
+
+ dbg_assert (lib_stats_book.last_page->next_page);
+
+ lib_stats_book.last_page = lib_stats_book.last_page->next_page;
+ lib_stats_book.last_page->nb_stats = 0;
+ lib_stats_book.nb_pages++;
+ }
+
+ /* Check if stat is the 1st one of the page */
+ if (lib_stats_book.last_page->nb_stats == 0)
+ {
+ lib_stats_book.last_page->first_stat
+ = slab_alloc (&lib_stats_book.stats_cache);
+ lib_stats_book.last_page->last_stat
+ = lib_stats_book.last_page->first_stat;
+ }
+ else
+ {
+ lib_stats_book.last_page->last_stat->next_stat
+ = slab_alloc (&lib_stats_book.stats_cache);
+ lib_stats_book.last_page->last_stat
+ = lib_stats_book.last_page->last_stat->next_stat;
+ }
+
+ /* Store stat's informations and update page*/
+ lib_stats_book.last_page->last_stat->name = name;
+ lib_stats_book.last_page->last_stat->type = type;
+ lib_stats_book.last_page->last_stat->next_stat = NULL;
+
+ lib_stats_book.last_page->nb_stats++;
+ lib_stats_book.last_page->page_size += stat_size;
+}
+
/***********************************************************/
/* Public Functions */
/*********************************************************/
-/**
- * Init stat book : prepare the book so that one empty page is available
- */
void
lib_stats_init (void)
{
slab_cache_init (&lib_stats_book.pages_cache, "pages_slab",
sizeof (lib_stats_page_t), NULL);
slab_cache_init (&lib_stats_book.stats_cache, "stats_slab",
- sizeof (lib_stats_page_t), NULL);
+ sizeof (lib_stats_page_t), NULL);
lib_stats_book.first_page = slab_alloc (&lib_stats_book.pages_cache);
@@ -108,31 +161,28 @@ lib_stats_init (void)
lib_stats_book.first_page->first_stat = NULL;
}
-/**
- * Uninit stat book : clear all the pages and stats of the book
- */
void
lib_stats_uninit (void)
{
uint nb_pages = lib_stats_book.nb_pages;
- lib_stats_page_t* target_page = lib_stats_book.first_page;
+ lib_stats_page_t *target_page = lib_stats_book.first_page;
while (nb_pages--)
{
uint nb_stats = target_page->nb_stats;
- lib_stats_page_t* next_page = target_page->next_page;
- lib_stats_stat_t* target_stat = target_page->first_stat;
+ lib_stats_page_t *next_page = target_page->next_page;
+ lib_stats_stat_t *target_stat = target_page->first_stat;
- while(nb_stats--)
+ while (nb_stats--)
{
- lib_stats_stat_t* next_stat = target_stat->next_stat;
+ lib_stats_stat_t *next_stat = target_stat->next_stat;
- slab_release(target_stat);
+ slab_release (target_stat);
target_stat = next_stat;
}
- slab_release(target_page);
+ slab_release (target_page);
target_page = next_page;
}
@@ -140,20 +190,15 @@ lib_stats_uninit (void)
slab_cache_uninit (&lib_stats_book.pages_cache);
}
-
-/**
- * Write one page of stats to the bitstream
- * \param bitstream : bitstream where to write the page
- * \param page : page to send
- */
void
-lib_stats_get_page (bitstream_t* bitstream, u8 page)
+lib_stats_get_page (bitstream_t *bitstream, u8 page)
{
- lib_stats_page_t* target_page; /* point to the page to get */
- lib_stats_stat_t* target_stat; /* point to the stat to write to the bitstream */
+ lib_stats_page_t *target_page; /* point to the page to get */
+ lib_stats_stat_t *target_stat; /* point to the stat to write to the
+ bitstream */
/* First of all send the page number */
- bitstream_write(bitstream, lib_stats_book.nb_pages, 8);
+ bitstream_write (bitstream, lib_stats_book.nb_pages, 8);
/* Check if the page requested exists */
if (page < lib_stats_book.nb_pages)
@@ -168,79 +213,98 @@ lib_stats_get_page (bitstream_t* bitstream, u8 page)
while (target_stat)
{
- int nb_quartets = 2 * target_stat->type; /* nb quartets to send depends on type */
+ int nb_quartets = 2 * target_stat->type; /* nb quartets to send
+ depends on type */
/* Write value's name to bitstream */
- bitstream_write_buf(bitstream, (const u8*)target_stat->name, strlen(target_stat->name));
- bitstream_write(bitstream, ':', 8);
+ bitstream_write_buf (bitstream, (const u8 *) target_stat->name,
+ strlen (target_stat->name));
+ bitstream_write (bitstream, ':', 8);
/* Get value depending on it's type */
switch (target_stat->type)
{
- case LIB_STATS_1_BYTE:
+ case LIB_STATS_1_BYTE:
{
u8 stat_value;
if (target_stat->value)
- stat_value = *(u8*)(target_stat->value);
+ stat_value = *(u8 *) (target_stat->value);
else
- stat_value = *(u8*)(target_stat->callback());
+ stat_value = *(u8 *) (target_stat->callback ());
/* Write value to bitstream starting with MSB */
while (nb_quartets)
- bitstream_write(bitstream, quartet2ascii((u8)(stat_value>>(--nb_quartets*4))), 8);
+ bitstream_write (
+ bitstream,
+ quartet2ascii ((u8) (stat_value
+ >> (--nb_quartets * 4))),
+ 8);
}
- break;
+ break;
- case LIB_STATS_2_BYTE:
+ case LIB_STATS_2_BYTE:
{
u16 stat_value;
if (target_stat->value)
- stat_value = *(u16*)(target_stat->value);
+ stat_value = *(u16 *) (target_stat->value);
else
- stat_value = *(u16*)(target_stat->callback());
+ stat_value = *(u16 *) (target_stat->callback ());
/* Write value to bitstream starting with MSB */
while (nb_quartets)
- bitstream_write(bitstream, quartet2ascii((u8)(stat_value>>(--nb_quartets*4))), 8);
+ bitstream_write (
+ bitstream,
+ quartet2ascii ((u8) (stat_value
+ >> (--nb_quartets * 4))),
+ 8);
}
- break;
+ break;
- case LIB_STATS_4_BYTE:
- {
- u32 stat_value;
+ case LIB_STATS_4_BYTE:
+ {
+ u32 stat_value;
- if (target_stat->value)
- stat_value = *(u32*)(target_stat->value);
- else
- stat_value = *(u32*)(target_stat->callback());
+ if (target_stat->value)
+ stat_value = *(u32 *) (target_stat->value);
+ else
+ stat_value = *(u32 *) (target_stat->callback ());
- /* Write value to bitstream starting with MSB */
+ /* Write value to bitstream starting with MSB */
while (nb_quartets)
- bitstream_write(bitstream, quartet2ascii((u8)(stat_value>>(--nb_quartets*4))), 8);
- }
- break;
+ bitstream_write (
+ bitstream,
+ quartet2ascii ((u8) (stat_value
+ >> (--nb_quartets * 4))),
+ 8);
+ }
+ break;
- case LIB_STATS_8_BYTE:
- {
- u64 stat_value;
+ case LIB_STATS_8_BYTE:
+ {
+ u64 stat_value;
- if (target_stat->value)
- stat_value = *(u64*)(target_stat->value);
- else
- stat_value = *(u64*)(target_stat->callback());
+ if (target_stat->value)
+ stat_value = *(u64 *) (target_stat->value);
+ else
+ stat_value = *(u64 *) (target_stat->callback ());
- /* Write value to bitstream starting with MSB */
- while (nb_quartets)
- bitstream_write(bitstream, quartet2ascii((u8)(stat_value>>(--nb_quartets*4))), 8);
- }
- break;
+ /* Write value to bitstream starting with MSB */
+ while (nb_quartets)
+ bitstream_write (
+ bitstream,
+ quartet2ascii ((u8) (stat_value
+ >> (--nb_quartets * 4))),
+ 8);
+ }
+ break;
- default:
- bitstream_write_buf(bitstream, (u8*)"wrong_type", strlen("wrong_type"));
- break;
+ default:
+ bitstream_write_buf (bitstream, (u8 *) "wrong_type",
+ strlen ("wrong_type"));
+ break;
}
/* Point to next stat */
@@ -248,100 +312,34 @@ lib_stats_get_page (bitstream_t* bitstream, u8 page)
/* Inter-stat space if it's not the last one */
if (target_stat)
- bitstream_write(bitstream, ' ', 8);
+ bitstream_write (bitstream, ' ', 8);
}
}
/* end of string */
- bitstream_write(bitstream, 0, 8);
+ bitstream_write (bitstream, 0, 8);
}
-
-/**
- * Prepare the book to store a new stat
- * \param name : string to be displayed before the stat value
- * \param type : type and max size of the value in octet
- */
void
-lib_stats_new_stat (const char* name, lib_stats_types_t type)
-{
- /* Check parameters */
- dbg_assert (name);
- dbg_assert (type);
-
- int stat_size;
-
- /* String lenght for this stat */
- stat_size = strlen(name) + (2 * type) + 2;
-
- /* Check if new stat doesn't fit in the current page */
- if ((lib_stats_book.last_page->page_size + stat_size) > LIB_STATS_MAX_PAGE_SIZE)
- {
- /* Create and init a new page */
- lib_stats_book.last_page->next_page = slab_alloc (&lib_stats_book.pages_cache);
-
- dbg_assert (lib_stats_book.last_page->next_page);
-
- lib_stats_book.last_page = lib_stats_book.last_page->next_page;
- lib_stats_book.last_page->nb_stats = 0;
- lib_stats_book.nb_pages++;
- }
-
- /* Check if stat is the 1st one of the page */
- if (lib_stats_book.last_page->nb_stats == 0)
- {
- lib_stats_book.last_page->first_stat = slab_alloc (&lib_stats_book.stats_cache);
- lib_stats_book.last_page->last_stat = lib_stats_book.last_page->first_stat;
- }
- else
- {
- lib_stats_book.last_page->last_stat->next_stat = slab_alloc (&lib_stats_book.stats_cache);
- lib_stats_book.last_page->last_stat = lib_stats_book.last_page->last_stat->next_stat;
- }
-
- /* Store stat's informations and update page*/
- lib_stats_book.last_page->last_stat->name = name;
- lib_stats_book.last_page->last_stat->type = type;
- lib_stats_book.last_page->last_stat->next_stat = NULL;
-
- lib_stats_book.last_page->nb_stats++;
- lib_stats_book.last_page->page_size += stat_size;
-}
-
-
-/**
- * Add a new stat to the stat book using pointer to value
- * \param name : string to be displayed before the stat value
- * \param value : pointer to the value of the stat
- * \param type : type and max size of the value in octet
- */
-void
-lib_stats_set_stat_value (const char* name, void* value, lib_stats_types_t type)
+lib_stats_set_stat_value (const char *name, void *value,
+ lib_stats_types_t type)
{
dbg_assert (value);
- lib_stats_new_stat(name, type);
+ lib_stats_new_stat (name, type);
lib_stats_book.last_page->last_stat->value = value;
lib_stats_book.last_page->last_stat->callback = NULL;
-
}
-/**
- * Add a new stat to the stat book using callback
- * \param name : string to be displayed before the stat value
- * \param callback : if value param is NULL this callback will be used to retrieve the stat
- * \param type : type and max size of the value in octet
- */
void
-lib_stats_set_stat_callback (const char* name, void* (*callback)(void), lib_stats_types_t type)
+lib_stats_set_stat_callback (const char *name, void *(*callback) (void),
+ lib_stats_types_t type)
{
dbg_assert (callback);
- lib_stats_new_stat(name, type);
+ lib_stats_new_stat (name, type);
lib_stats_book.last_page->last_stat->value = NULL;
lib_stats_book.last_page->last_stat->callback = callback;
}
-
-
diff --git a/cesar/lib/stats.h b/cesar/lib/stats.h
index 8cad2d1e3d..fdbf07f28a 100644
--- a/cesar/lib/stats.h
+++ b/cesar/lib/stats.h
@@ -12,7 +12,8 @@
* \brief Trace system.
* \ingroup lib
*
- * The stats module provide stats registering function and stats retrieving function.
+ * The stats module provide stats registering function and stats retrieving
+ * function.
*/
#include "config/stats.h"
@@ -27,31 +28,59 @@ enum lib_stats_types_t
};
typedef enum lib_stats_types_t lib_stats_types_t;
-#if CONFIG_STATS
+BEGIN_DECLS
-void
-lib_stats_get_page (bitstream_t* bitstream, u8 page);
+#if CONFIG_STATS
+/**
+ * Init stat book : prepare the book so that one empty page is available
+ */
void
lib_stats_init (void);
+/**
+ * Uninit stat book : clear all the pages and stats of the book
+ */
void
lib_stats_uninit (void);
+/**
+ * Write one page of stats to the bitstream
+ * \param bitstream : bitstream where to write the page
+ * \param page : page to send
+ */
void
-lib_stats_set_stat_value (const char* name, void* value, lib_stats_types_t type);
+lib_stats_get_page (bitstream_t *bitstream, u8 page);
+/**
+ * Add a new stat to the stat book using pointer to value
+ * \param name : string to be displayed before the stat value
+ * \param value : pointer to the value of the stat
+ * \param type : type and max size of the value in octet
+ */
+void
+lib_stats_set_stat_value (const char *name, void *value,
+ lib_stats_types_t type);
+/**
+ * Add a new stat to the stat book using callback
+ * \param name : string to be displayed before the stat value
+ * \param callback : if value param is NULL this callback will be used to
+ * retrieve the stat
+ * \param type : type and max size of the value in octet
+ */
void
-lib_stats_set_stat_callback (const char* name, void* (*callback)(void), lib_stats_types_t type);
+lib_stats_set_stat_callback (const char *name, void *(*callback) (void),
+ lib_stats_types_t type);
#define lib_stats_set_stat_value_notype(name, value) do { \
- lib_stats_set_stat_value (name, value, sizeof (*value));\
+ lib_stats_set_stat_value (name, value, sizeof (*value)); \
} \
while (0)
#define lib_stats_set_stat_callback_notype(name, callback) do { \
- lib_stats_set_stat_callback (name, (void*)callback, sizeof (*callback()));\
+ lib_stats_set_stat_callback (name, (void *) callback, \
+ sizeof (*callback ())); \
} \
while (0)
@@ -65,4 +94,6 @@ lib_stats_set_stat_callback (const char* name, void* (*callback)(void), lib_stat
#endif /* !CONFIG_STATS */
+END_DECLS
+
#endif