From 0eb0325b96a7eb5b585370b552c77b2363b82ef3 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Fri, 15 Nov 2024 16:02:52 +0100 Subject: [PATCH] T tracer: support float types in traces --- common/utils/T/tracer/event.c | 4 ++++ common/utils/T/tracer/event.h | 2 ++ common/utils/T/tracer/logger/textlog.c | 4 +++- common/utils/T/tracer/utils.c | 6 ++++++ common/utils/T/tracer/utils.h | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/common/utils/T/tracer/event.c b/common/utils/T/tracer/event.c index f75af1e398..61fb12dd2a 100644 --- a/common/utils/T/tracer/event.c +++ b/common/utils/T/tracer/event.c @@ -94,6 +94,10 @@ event new_event(int type, int length, char *buffer, void *database) e.e[i].type = EVENT_ULONG; e.e[i].ul = *(unsigned long *)(&buffer[offset]); offset += sizeof(unsigned long); + } else if (!strcmp(f.type[i], "float")) { + e.e[i].type = EVENT_FLOAT; + e.e[i].f = *(float *)(&buffer[offset]); + offset += sizeof(float); } else if (!strcmp(f.type[i], "string")) { e.e[i].type = EVENT_STRING; e.e[i].s = &buffer[offset]; diff --git a/common/utils/T/tracer/event.h b/common/utils/T/tracer/event.h index 4e631fbb49..e3d7637bf4 100644 --- a/common/utils/T/tracer/event.h +++ b/common/utils/T/tracer/event.h @@ -13,6 +13,7 @@ enum event_arg_type { EVENT_INT, EVENT_ULONG, + EVENT_FLOAT, EVENT_STRING, EVENT_BUFFER }; @@ -23,6 +24,7 @@ typedef struct { union { int i; unsigned long ul; + float f; char *s; struct { int bsize; diff --git a/common/utils/T/tracer/logger/textlog.c b/common/utils/T/tracer/logger/textlog.c index 8217c2b981..2003ff4233 100644 --- a/common/utils/T/tracer/logger/textlog.c +++ b/common/utils/T/tracer/logger/textlog.c @@ -11,7 +11,7 @@ enum format_item_type { INSTRING, - INT, ULONG, STRING, BUFFER }; + INT, ULONG, FLOAT, STRING, BUFFER }; struct format_item { enum format_item_type type; @@ -67,6 +67,7 @@ static void _event(void *p, event e) case INSTRING: PUTS(&l->o, l->f[i].s); break; case INT: PUTI(&l->o, e.e[l->f[i].event_arg].i); break; case ULONG: PUTUL(&l->o, e.e[l->f[i].event_arg].ul); break; + case FLOAT: PUTF(&l->o, e.e[l->f[i].event_arg].f); break; case STRING: PUTS_CLEAN(&l->o, e.e[l->f[i].event_arg].s); break; case BUFFER: PUTS(&l->o, "{buffer size:"); @@ -106,6 +107,7 @@ static int find_argument(char *name, database_event_format f, *event_arg = i; if (!strcmp(f.type[i], "int")) *it = INT; else if (!strcmp(f.type[i], "ulong")) *it = ULONG; + else if (!strcmp(f.type[i], "float")) *it = FLOAT; else if (!strcmp(f.type[i], "string")) *it = STRING; else if (!strcmp(f.type[i], "buffer")) *it = BUFFER; else return 0; diff --git a/common/utils/T/tracer/utils.c b/common/utils/T/tracer/utils.c index 39e04fb973..78b01a2516 100644 --- a/common/utils/T/tracer/utils.c +++ b/common/utils/T/tracer/utils.c @@ -276,3 +276,9 @@ void PUTUL(OBUF *o, unsigned long l) { sprintf(s, "%lu", l); PUTS(o, s); } + +void PUTF(OBUF *o, float f) { + char s[256]; + sprintf(s, "%g", f); + PUTS(o, s); +} diff --git a/common/utils/T/tracer/utils.h b/common/utils/T/tracer/utils.h index 6784117fa6..e1055d4efa 100644 --- a/common/utils/T/tracer/utils.h +++ b/common/utils/T/tracer/utils.h @@ -50,5 +50,6 @@ void PUTS_CLEAN(OBUF *o, char *s); void PUTI(OBUF *o, int i); void PUTX2(OBUF *o, int i); void PUTUL(OBUF *o, unsigned long i); +void PUTF(OBUF *o, float f); #endif /* _UTILS_H_ */