#include "graph.h"
#include "time.h"
+// Maximum length of the title/vlabel
+#define TITLE_MAX 128
+#define VLABEL_MAX 64
+
struct collecty_graph {
collecty_ctx* ctx;
int nrefs;
int collecty_graph_render(collecty_graph* self, const char* object,
const collecty_graph_render_options* options, char** buffer, size_t* length) {
collecty_args* args = NULL;
- char* vlabel = NULL;
- char* title = NULL;
+ char vlabel[VLABEL_MAX] = "";
+ char title[TITLE_MAX] = "";
char** data = NULL;
FILE* f = NULL;
int w = 0;
// Set the title
if (self->impl->title) {
// Fetch the title
- r = self->impl->title(self->ctx, self, object, &title);
+ r = self->impl->title(self->ctx, self, object, title, sizeof(title));
if (r < 0) {
ERROR(self->ctx, "Failed to render the title: %s\n", strerror(-r));
goto ERROR;
}
// Add the title to the command line
- if (title) {
+ if (*title) {
r = collecty_args_push(args, "--title=%s", title);
if (r < 0)
goto ERROR;
// Set the vertical label
if (self->impl->vlabel) {
// Fetch the vertical label
- r = self->impl->vlabel(self->ctx, self, object, &vlabel);
+ r = self->impl->vlabel(self->ctx, self, object, vlabel, sizeof(vlabel));
if (r < 0) {
ERROR(self->ctx, "Failed to render the vertical label: %s\n", strerror(-r));
goto ERROR;
}
// Add the vertical label to the command line
- if (vlabel) {
+ if (*vlabel) {
r = collecty_args_push(args, "--vertical-label=%s", vlabel);
if (r < 0)
goto ERROR;
free(data[i]);
free(data);
}
- if (vlabel)
- free(vlabel);
- if (title)
- free(title);
if (args)
collecty_args_unref(args);
if (f)
// Title
int (*title)(collecty_ctx* ctx, collecty_graph* graph,
- const char* object, char** title);
+ const char* object, char* title, size_t length);
// Vertical Label
int (*vlabel)(collecty_ctx* ctx, collecty_graph* graph,
- const char* object, char** title);
+ const char* object, char* vlabel, size_t length);
} collecty_graph_impl;
int collecty_graph_create(collecty_graph** graph,
#include <limits.h>
+#include "../string.h"
#include "graph.h"
#include "conntrack.h"
static int conntrack_title(collecty_ctx* ctx,
- collecty_graph* graph, const char* object, char** title) {
- return collecty_format_title(title, "%s", _("Connection Tracking Table"));
+ collecty_graph* graph, const char* object, char* title, size_t length) {
+ return __collecty_string_set(title, length, _("Connection Tracking Table"));
}
static int conntrack_vlabel(collecty_ctx* ctx,
- collecty_graph* graph, const char* object, char** title) {
- return collecty_format_title(title, "%s", _("Entries"));
+ collecty_graph* graph, const char* object, char* vlabel, size_t length) {
+ return __collecty_string_set(vlabel, length, _("Entries"));
}
static int conntrack_render(collecty_ctx* ctx,
#include <limits.h>
+#include "../string.h"
#include "graph.h"
#include "contextswitches.h"
static int contextswitches_title(collecty_ctx* ctx,
- collecty_graph* graph, const char* object, char** title) {
- return collecty_format_title(title, "%s", _("Context Switches"));
+ collecty_graph* graph, const char* object, char* title, size_t length) {
+ return __collecty_string_set(title, length, _("Context Switches"));
}
static int contextswitches_vlabel(collecty_ctx* ctx,
- collecty_graph* graph, const char* object, char** title) {
- return collecty_format_title(title, "%s", _("Context Switches/s"));
+ collecty_graph* graph, const char* object, char* vlabel, size_t length) {
+ return __collecty_string_set(vlabel, length, _("Context Switches/s"));
}
static int contextswitches_render(collecty_ctx* ctx,
#include <limits.h>
+#include "../string.h"
#include "graph.h"
#include "loadavg.h"
#define COLOR_LOAD1 YELLOW
static int loadavg_title(collecty_ctx* ctx, collecty_graph* graph,
- const char* object, char** title) {
- return collecty_format_title(title, "%s", _("Load Average"));
+ const char* object, char* title, size_t length) {
+ return __collecty_string_set(title, length, _("Load Average"));
}
static int loadavg_render(collecty_ctx* ctx,
# #
#############################################################################*/
+#include "../string.h"
#include "graph.h"
#include "processor.h"
#define COLOR_IDLE LIGHT_GREY
static int processor_title(collecty_ctx* ctx, collecty_graph* graph,
- const char* object, char** title) {
- return collecty_format_title(title, "%s", _("Processor Usage"));
+ const char* object, char* title, size_t length) {
+ return __collecty_string_set(title, length, _("Processor Usage"));
}
static int processor_vlabel(collecty_ctx* ctx, collecty_graph* graph,
- const char* object, char** title) {
- return collecty_format_title(title, "%s", _("Percent"));
+ const char* object, char* vlabel, size_t length) {
+ return __collecty_string_set(vlabel, length, _("Percent"));
}
-
static int processor_render(collecty_ctx* ctx,
collecty_graph* graph, collecty_args* args, const char* object) {
int r;
#include <limits.h>
+#include "../string.h"
#include "graph.h"
#include "uptime.h"
static int uptime_title(collecty_ctx* ctx, collecty_graph* graph,
- const char* object, char** title) {
- return collecty_format_title(title, "%s", _("Uptime"));
+ const char* object, char* title, size_t length) {
+ return __collecty_string_set(title, length, _("Uptime"));
}
static int uptime_vlabel(collecty_ctx* ctx, collecty_graph* graph,
- const char* object, char** title) {
- return collecty_format_title(title, "%s", _("Days"));
+ const char* object, char* vlabel, size_t length) {
+ return __collecty_string_set(vlabel, length, _("Days"));
}
static int uptime_render(collecty_ctx* ctx,