#############################################################################*/
#include <errno.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/queue.h>
// Object
char* object;
- // Timestamp
- struct timeval t;
-
// Samples
char** samples;
unsigned int num_samples;
static int collecty_queue_object_append_sample(collecty_queue* self, collecty_module* module,
const char* object, struct collecty_queue_object* o, const char* sample) {
+ struct timeval t = {};
char** samples = NULL;
char* s = NULL;
+ int r;
+
+ // Fetch the current timestamp
+ r = gettimeofday(&t, NULL);
+ if (r < 0)
+ return -errno;
// Increase the size of the array
samples = reallocarray(o->samples, o->num_samples + 1, sizeof(*o->samples));
if (!samples)
return -errno;
- // Copy the sample to the heap
- s = strdup(sample);
- if (!s)
+ // Prepend the timestamp to the sample
+ r = asprintf(&s, "%ld:%s", t.tv_sec, sample);
+ if (r < 0)
return -errno;
// Assign the sample
// Reference the module
o->module = collecty_module_ref(module);
- // Fetch the current timestamp
- r = gettimeofday(&o->t, NULL);
- if (r < 0) {
- r = -errno;
- goto ERROR;
- }
-
// Store the object
if (o->object) {
o->object = strdup(object);