summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9b022eb)
raw | patch | inline | side by side (parent: 9b022eb)
author | Florian Forster <octo@collectd.org> | |
Fri, 19 Jul 2013 05:39:47 +0000 (07:39 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Wed, 7 Aug 2013 05:54:43 +0000 (07:54 +0200) |
Replace the value_list_to_string() function with a version which is optimized
for data sets with a single data source. The original function is still used
for data sets with multiple data sources. This allows to reduce the number of
calls to snprintf() in this (very common) case, resulting in ~2% speedup.
for data sets with a single data source. The original function is still used
for data sets with multiple data sources. This allows to reduce the number of
calls to snprintf() in this (very common) case, resulting in ~2% speedup.
src/rrdtool.c | patch | blob | history |
diff --git a/src/rrdtool.c b/src/rrdtool.c
index 80833902a21e7b05656c3d6baa4fb91ffd5d170d..2f28329f0fbef43f17c70b3b7136a6b4f187e2b8 100644 (file)
--- a/src/rrdtool.c
+++ b/src/rrdtool.c
} /* int srrd_update */
#endif /* !HAVE_THREADSAFE_LIBRRD */
-static int value_list_to_string (char *buffer, int buffer_len,
+static int value_list_to_string_multiple (char *buffer, int buffer_len,
const data_set_t *ds, const value_list_t *vl)
{
int offset;
offset += status;
} /* for ds->ds_num */
+ return (0);
+} /* int value_list_to_string_multiple */
+
+static int value_list_to_string (char *buffer, int buffer_len,
+ const data_set_t *ds, const value_list_t *vl)
+{
+ int status;
+ time_t tt;
+
+ if (ds->ds_num != 1)
+ return (value_list_to_string_multiple (buffer, buffer_len,
+ ds, vl));
+
+ tt = CDTIME_T_TO_TIME_T (vl->time);
+ switch (ds->ds[0].type)
+ {
+ case DS_TYPE_DERIVE:
+ status = ssnprintf (buffer, buffer_len, "%u:%"PRIi64,
+ (unsigned) tt, vl->values[0].derive);
+ break;
+ case DS_TYPE_GAUGE:
+ status = ssnprintf (buffer, buffer_len, "%u:%lf",
+ (unsigned) tt, vl->values[0].gauge);
+ break;
+ case DS_TYPE_COUNTER:
+ status = ssnprintf (buffer, buffer_len, "%u:%llu",
+ (unsigned) tt, vl->values[0].counter);
+ break;
+ case DS_TYPE_ABSOLUTE:
+ status = ssnprintf (buffer, buffer_len, "%u:%"PRIu64,
+ (unsigned) tt, vl->values[0].absolute);
+ break;
+ default:
+ return (EINVAL);
+ }
+
+ if ((status < 1) || (status >= buffer_len))
+ return (ENOMEM);
+
return (0);
} /* int value_list_to_string */