Index: bootstat_log.c |
diff --git a/bootstat_log.c b/bootstat_log.c |
index 079c6f26196523a8c4856f11218e9c0fba795270..1a90b5e556c0950723916694c9a2916fbaeb2169 100644 |
--- a/bootstat_log.c |
+++ b/bootstat_log.c |
@@ -6,48 +6,48 @@ |
// facility. |
#include "bootstat.h" |
+#include "bootstat_test.h" |
#include <stdio.h> |
#include <stddef.h> |
-#include <sys/types.h> |
-#include <sys/stat.h> |
#include <sys/fcntl.h> |
+#include <sys/param.h> |
+#include <sys/stat.h> |
+#include <sys/types.h> |
#include <unistd.h> |
// |
+// Default path to directory where output statistics will be stored. |
+// |
+static const char kDefaultOutputDirectoryName[] = "/tmp"; |
+ |
+// |
// Paths to the statistics files we snapshot as part of the data to |
// be logged. |
// |
-static const char kUptimeStatisticsFileName[] = "/proc/uptime"; |
+static const char kDefaultUptimeStatisticsFileName[] = "/proc/uptime"; |
#if defined (__amd64__) || defined (__x86_64__) || defined (__i386__) |
-static const char kDiskStatisticsFileName[] = "/sys/block/sda/stat"; |
+static const char kDefaultDiskStatisticsFileName[] = "/sys/block/sda/stat"; |
#elif defined (__arm__) |
-static const char kDiskStatisticsFileName[] = "/sys/block/mmcblk0/stat"; |
+static const char kDefaultDiskStatisticsFileName[] = "/sys/block/mmcblk0/stat"; |
#else |
#error "unknown processor type?" |
#endif |
- |
-// |
-// Maximum length of any pathname for storing event statistics. |
-// Arbitrarily chosen, but see the comment below about truncation. |
-// |
-#define MAX_STAT_PATH 128 |
- |
-// |
-// Output file creation mode: 0666, a.k.a. rw-rw-rw-. |
-// |
-static const int kFileCreationMode = |
- (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); |
- |
+static const char *output_directory_name = kDefaultOutputDirectoryName; |
+static const char *uptime_statistics_file_name = |
+ kDefaultUptimeStatisticsFileName; |
+static const char *disk_statistics_file_name = kDefaultDiskStatisticsFileName; |
static void append_logdata(const char* input_path, |
const char* output_name_prefix, |
const char* event_name) |
{ |
- char output_path[MAX_STAT_PATH]; |
+ const mode_t kFileCreationMode = |
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; |
+ char output_path[PATH_MAX]; |
char buffer[256]; |
ssize_t num_read; |
int ifd, ofd; |
@@ -58,14 +58,12 @@ static void append_logdata(const char* input_path, |
} |
// |
- // We don't want the file name "/tmp/uptime-..." truncated |
- // differently from the the name "/tmp/disk-...", so we truncate |
+ // We don't want the file name ".../uptime-..." truncated |
+ // differently from the the name ".../disk-...", so we truncate |
// event_name separately using the "%.*s" format. |
kmixter1
2010/12/06 04:23:52
Confused by this comment. Say BOOTSTAT_MAX_EVENT_
|
// |
- // We expect that BOOTSTAT_MAX_EVENT_LEN is enough smaller than |
- // MAX_STAT_PATH that output_path will never be truncated. |
- // |
- (void) snprintf(output_path, sizeof(output_path), "/tmp/%s-%.*s", |
+ (void) snprintf(output_path, sizeof(output_path), "%s/%s-%.*s", |
kmixter1
2010/12/06 04:23:52
space after (void) seems unusual. Actually I gues
|
+ output_directory_name, |
output_name_prefix, |
BOOTSTAT_MAX_EVENT_LEN - 1, event_name); |
ofd = open(output_path, O_WRONLY | O_APPEND | O_CREAT, |
@@ -87,6 +85,35 @@ static void append_logdata(const char* input_path, |
void bootstat_log(const char* event_name) |
{ |
- append_logdata(kUptimeStatisticsFileName, "uptime", event_name); |
- append_logdata(kDiskStatisticsFileName, "disk", event_name); |
+ append_logdata(uptime_statistics_file_name, "uptime", event_name); |
+ append_logdata(disk_statistics_file_name, "disk", event_name); |
+} |
+ |
+ |
+#ifdef CONFIG_UNIT_TEST |
+void bootstat_set_output_directory(const char* dirname) |
+{ |
+ if (dirname != NULL) |
+ output_directory_name = dirname; |
+ else |
+ output_directory_name = kDefaultOutputDirectoryName; |
+} |
+ |
+ |
+void bootstat_set_uptime_file_name(const char* filename) |
+{ |
+ if (filename != NULL) |
+ uptime_statistics_file_name = filename; |
+ else |
+ uptime_statistics_file_name = kDefaultUptimeStatisticsFileName; |
} |
+ |
+ |
+void bootstat_set_disk_file_name(const char* filename) |
+{ |
+ if (filename != NULL) |
+ disk_statistics_file_name = filename; |
+ else |
+ disk_statistics_file_name = kDefaultDiskStatisticsFileName; |
+} |
+#endif |