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** data = NULL;
FILE* f = NULL;
int w = 0;
goto ERROR;
}
+ // Set the title
+ if (self->impl->title) {
+ // Fetch the title
+ r = self->impl->title(self->ctx, self, object, &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) {
+ 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);
+ 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) {
+ r = collecty_args_push(args, "--vertical-label=%s", vlabel);
+ if (r < 0)
+ goto ERROR;
+ }
+ }
+
// Write the graph to the output stream
r = collecty_args_push(args, "-");
if (r < 0)
free(data[i]);
free(data);
}
+ if (vlabel)
+ free(vlabel);
+ if (title)
+ free(title);
if (args)
collecty_args_unref(args);
if (f)
// Render!
int (*render)(collecty_ctx* ctx, collecty_graph* graph,
collecty_args* args, const char* object);
+
+ // Title
+ int (*title)(collecty_ctx* ctx, collecty_graph* graph,
+ const char* object, char** title);
+
+ // Vertical Label
+ int (*vlabel)(collecty_ctx* ctx, collecty_graph* graph,
+ const char* object, char** title);
} collecty_graph_impl;
int collecty_graph_create(collecty_graph** graph,
#include "../colors.h"
#include "../graph.h"
#include "../i18n.h"
+#include "../util.h"
#include "loadavg.h"
// Set some colors
#define COLOR_LOAD5 ORANGE
#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"));
+}
+
static int loadavg_render(collecty_ctx* ctx,
collecty_graph* graph, collecty_args* args, const char* object) {
int r;
const collecty_graph_impl loadavg_graph = {
.name = "LoadAverage",
.render = loadavg_render,
+ .title = loadavg_title,
+ .vlabel = loadavg_title,
// Limits
.lower_limit = 0,
#############################################################################*/
#include <errno.h>
+#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
return r;
}
+
+// Helper function to set the title
+int collecty_format_title(char** title, const char* format, ...) {
+ va_list args;
+ int r;
+
+ // Format the title
+ va_start(args, format);
+ r = vasprintf(title, format, args);
+ va_end(args);
+
+ // Abort on errors
+ if (r < 0)
+ return -errno;
+
+ return 0;
+}
int collecty_file_read_uint64(const char* path, uint64_t* number);
+// Helper function to set the title
+int collecty_format_title(char** title, const char* format, ...)
+ __attribute__((format(printf, 2, 3)));
+
#endif /* COLLECTY_UTIL_H */