Hello,
I like better the function with variable arguments, with NULL as the
last arg.
Yes, it makes it a bit error prone. But what do you think of this ?
printf("Error %d");
Here is an error someone can easily do :
Step 1 : write the code
char const *names[] = { "free", "cached", "buffered" };
gauge_t values[] = { NAN, NAN, NAN };
[...]
Step 2 : repair your mistake (add the missing "used" item)
char const *names[] = { "free", "cached", "buffered" };
gauge_t values[] = { NAN, NAN, NAN };
[...]
Ooops, I forgot to add an item to values[]
Another one, with the variable argument function, with a given number of
args (3rd argument of plugin_dispatch_list() ):
Step 1 : write the code
plugin_dispatch_list (vl, 1, 3, "free", 100.0, "cached", 200.0,
"buffered", 300.0);
Step 2 : repair your mistake (add the missing "used" item)
plugin_dispatch_list (vl, 1, 3, "free", 100.0, "cached", 200.0,
"buffered", 300.0, "used", 1000.0);
Ooops, I forgot to set 4 as the 3rd argument
As you see, anyone can make errors...
So I prefer your version with variable arguments and NULL at the end :
it's easier to write and update.
It's only my opinion.
Happy new year !
Yves
---
- Homepage - http://ymettier.free.fr -
- GPG key - http://ymettier.free.fr/gpg.txt -
- C en action - http://ymettier.free.fr/livres/C_en_action_ed2.html -
- Guide Survie C - http://www.pearson.fr/livre/?GCOI=27440100673730 -
Le 2014-01-13 10:50, Florian Forster a écrit :
Hi Jeremy,
On Tue, Jan 07, 2014 at 07:47:25PM -0500, Jeremy Katz wrote:
In larger environments which have heterogeneous resources it's
frequently
useful to look at utilization of various resources as percentages.
[…]
But all of these end up having a ton of repetition.
I agree that the amount of repetition is bad and some infrastructure to
simplify these calculations would be nice. I would, however, prefer not
to make this a truly global option.
What do you think about an interface like this:
/* Takes a list of type instances and values and dispatches that in a
* batch, making sure that all values have the same time stamp. If
* "percentage" is set to true, "type" is set to "percent" and a
* percentage is calculated and dispatched, rather than the absolute
* values. Values that are NaN are dispatched as NaN and will not
* influence the total. Returns the number of values it failed to
* dispatch.
*/
int plugin_dispatch_set (value_list_t const *vl,
size_t argc,
char const **type_instances,
gauge_t const *values,
_Bool percentage);
It would then still be up to the plugin to use this new interface, but
the changes required to each plugin would be much simpler, for example:
char const *names[] = { "free", "cached", "buffered", "used" };
gauge_t values[] = { NAN, NAN, NAN, NAN };
value_list_t vl = VALUE_LIST_INIT;
/* Init "values" and "vl". */
plugin_dispatch_set (vl, STATIC_ARRAY_SIZE (names), names, values,
1);
Alternatively, I could picture a function with variable arguments,
that's used like this:
__attribute__((sentinel))
int plugin_dispatch_list (value_list_t const *vl,
_Bool percentage, ...);
plugin_dispatch_list (vl, 1, "free", 100.0, "cached", 200.0,
"buffered", 300.0, "used", 1000.0, NULL);
This might be a bit easier to write, but makes it a bit error prone,
e.g. when someone forgets to add the NULL pointer (the "sentinel"
attribute should catch this on GCC). An alternative would be to pass in
the number of values, but that can't be checked during compile time
either.
Best regards,
—octo
_______________________________________________
collectd mailing list
[email protected]
http://mailman.verplant.org/listinfo/collectd
_______________________________________________
collectd mailing list
[email protected]
http://mailman.verplant.org/listinfo/collectd