Skip to content

Commit

Permalink
Make stats filename based on env var, enable all the time, add pid to
Browse files Browse the repository at this point in the history
logging
  • Loading branch information
anaisbetts committed Mar 7, 2010
1 parent 0d7f3da commit c7fdb16
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
20 changes: 12 additions & 8 deletions src/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@
#include <dirent.h>
#include <unistd.h>

#include <fuse.h>
#include <glib.h>

#include "stats.h"
#include "config.h"

#ifdef USE_IOSTATS

GIOChannel* stats_open_logging(void)
{
gchar* path = g_strdup_printf("/tmp/%u.csv", (unsigned int)getpid());
char* path = getenv("VCACHEFS_STATS_FILE");
if (!path)
return NULL;

GIOChannel* ret = g_io_channel_new_file(path, "w", NULL);

if (ret) {
gsize dontcare;
g_io_channel_write_chars(ret, "Timecode, Operation, Offset, Size, Info\n", -1, &dontcare, NULL);
g_io_channel_write_chars(ret, "Timecode,Operation,Offset,Size,Info,Pid\n", -1, &dontcare, NULL);
}

g_free(path);
Expand All @@ -69,11 +71,15 @@ int stats_write_record(GIOChannel* channel, const char* operation, off_t offset,

const char* safe_info = (info ? info : "");

struct fuse_context* ctx = fuse_get_context();

gchar* buf;
if (sizeof(off_t) == 8) {
buf = g_strdup_printf("%llu, \"%s\", %llu, %lu, \"%s\"\n", get_time_code(), operation, (unsigned long long)offset, size, safe_info);
buf = g_strdup_printf("%llu,\"%s\",%llu,%lu,\"%s\",%u\n",
get_time_code(), operation, (unsigned long long)offset, size, safe_info, ctx->pid);
} else {
buf = g_strdup_printf("%llu, \"%s\", %lu, %lu, \"%s\"\n", get_time_code(), operation, (unsigned long)offset, size, safe_info);
buf = g_strdup_printf("%llu,\"%s\",%lu,%lu,\"%s\",%u\n",
get_time_code(), operation, (unsigned long)offset, size, safe_info, ctx->pid);
}

gsize dontcare;
Expand All @@ -91,5 +97,3 @@ long long unsigned int get_time_code(void)
unsigned long long ret = t.tv_sec * 1000 * 1000 + t.tv_usec;
return ret;
}

#endif
12 changes: 0 additions & 12 deletions src/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,9 @@
#ifndef _STATS_H
#define _STATS_H

#define USE_IOSTATS 1

#ifndef USE_IOSTATS

#define stats_open_logging() NULL
#define stats_close_logging(x)
#define stats_write_record(c, op, of, s, i) 1

#else

GIOChannel* stats_open_logging(void);
void stats_close_logging(GIOChannel* channel);
int stats_write_record(GIOChannel* channel, const char* operation, off_t offset, size_t size, const char* info);
long long unsigned int get_time_code(void);

#endif

#endif

0 comments on commit c7fdb16

Please sign in to comment.