From b883eee1be89b5530585c714242af92152dd64c3 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat Date: Tue, 20 Sep 2011 12:16:49 +0530 Subject: modified fs-perf-test to allow number of files to be opened to be given as the argument --- c_pgms/INFO | 2 + c_pgms/new-fs-perf.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 c_pgms/new-fs-perf.c (limited to 'c_pgms') diff --git a/c_pgms/INFO b/c_pgms/INFO index 4c4c62c..b4dccf4 100644 --- a/c_pgms/INFO +++ b/c_pgms/INFO @@ -11,3 +11,5 @@ c_pgms/inotify.c ---> program which monitors a directory and sends mail whenever =============================================== c_pgms/trucate ---> programs which truncates a file based on both path as well as fd on a file. Can be enhanced in future to write some truncate based applications. Used to verify bug 3077. + +c_pgms/new-ps-perf(new-fs-perf.c) -----> fs-perf test program modified. Now the number of files to be opened can be given as an argument. Default value is 30000 \ No newline at end of file diff --git a/c_pgms/new-fs-perf.c b/c_pgms/new-fs-perf.c new file mode 100644 index 0000000..31cbe0e --- /dev/null +++ b/c_pgms/new-fs-perf.c @@ -0,0 +1,125 @@ +/* +Date: Fri, 10 Nov 2006 16:16:27 +0300 +From: "Igor A. Valcov" + +Date: Tue 10 May 2011 17:28:10 +From: "Raghavendra Bhat" +*/ + +#include +#include +#include +#include +#include +#include +#include + +#define __BYTES 8192 +#define __FILES 30000 +#define N 30000 + +char buf [__BYTES]; + +void open_write_sync_close (int32_t num_files, int32_t iterations); +void delete_files (char *dirname, int32_t num_files); + +int main (int argc, char *argv[]) +{ + int32_t num_files = 0; + int32_t iterations = 0; + char *tail = NULL; + long tmp = 0; + int ret = -1; + + num_files = __FILES; + iterations = N; + + if (argc > 1) { + tmp = strtol (argv[1], &tail, 0); + if (tmp < 0) { + fprintf (stderr, "number of files cannot be -ve\n"); + goto out; + } + + num_files = (int32_t)tmp; + iterations = num_files; + } + + printf ("%d\n", num_files); + + open_write_sync_close (num_files, iterations); + ret = 0; + +out: + return ret; +} + + +void +open_write_sync_close (int32_t num_files, int32_t iterations) +{ + char fname[4096]; + int nFiles[num_files]; + int f, i; + int32_t ret = -1; + char *dirname = "sync_field"; + char *entries_path = NULL; + + /* Fill buf */ + for (i = 0; i < __BYTES; i++) + buf [i] = i % 128; + + entries_path = getcwd (entries_path, 255); + strcat (entries_path, dirname); + + /* Create the directory in which test are conducted */ + ret = mkdir (dirname, 0755); + if (ret == -1) { + fprintf (stderr, "cannot create directory (%s)\n", + strerror (errno)); + goto out; + } + + /* Create and open files */ + for (f = 0; f < num_files; f++) { + sprintf (fname, "%s/file-%d", dirname, f); + nFiles [f] = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0644); + printf("\r fd [%d] = %d", f, nFiles[f]); + } + + /* Write to the files opened */ + for (i = 0; i < iterations; i++) { + printf("\r%d/%d ", i, iterations); + fflush(stdout); + for (f = 1; f < num_files; f++) + write(nFiles[f], buf, __BYTES); + } + printf("\n"); + printf("syncing\n"); + + /* sync the data */ + for (f = 0; f < num_files; f++) { + fsync(nFiles [f]); + close(nFiles [f]); + } + + /* delete the files created and the directory whete tests + are conducted */ + delete_files (dirname, num_files); + rmdir (dirname); + +out: + return; +} + +void +delete_files (char *dirname, int32_t num_files) +{ + int32_t i = -1; + char name[4096]; + + for (i = 0; i < num_files; i++) { + snprintf (name, 4096, "%s/file-%d", dirname, i); + unlink (name); + } +} -- cgit