Commit baaeff99 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Add support for artificial delays in benchmark.

parent 24a5a394
......@@ -17,11 +17,14 @@ import (
)
var CheckSuccess = fuse.CheckSuccess
var delay = 0 * time.Microsecond
type StatFs struct {
fuse.DefaultFileSystem
entries map[string]*fuse.Attr
dirs map[string][]fuse.DirEntry
delay time.Duration
}
func (me *StatFs) add(name string, a *fuse.Attr) {
......@@ -47,6 +50,10 @@ func (me *StatFs) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.
if e == nil {
return nil, fuse.ENOENT
}
if me.delay > 0 {
time.Sleep(me.delay)
}
return e, fuse.OK
}
......@@ -152,6 +159,7 @@ func GetTestLines() []string {
func BenchmarkGoFuseThreadedStat(b *testing.B) {
b.StopTimer()
fs := NewStatFs()
fs.delay = delay
files := GetTestLines()
for _, fn := range files {
fs.add(fn, &fuse.Attr{Mode: fuse.S_IFREG | 0644})
......@@ -239,7 +247,9 @@ func BenchmarkCFuseThreadedStat(b *testing.B) {
"-o",
"entry_timeout=0.0,attr_timeout=0.0,ac_attr_timeout=0.0,negative_timeout=0.0",
mountPoint)
cmd.Env = append(os.Environ(), fmt.Sprintf("STATFS_INPUT=%s", f.Name()))
cmd.Env = append(os.Environ(),
fmt.Sprintf("STATFS_INPUT=%s", f.Name()),
fmt.Sprintf("STATFS_DELAY_USEC=%d", delay / time.Microsecond))
cmd.Start()
bin, err := exec.LookPath("fusermount")
......
......@@ -18,7 +18,9 @@ extern "C" {
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
useconds_t delay_usec;
class StatFs {
public:
......@@ -42,6 +44,10 @@ public:
statbuf->st_mode = S_IFREG | 0666;
}
if (delay_usec > 0) {
usleep(delay_usec);
}
return 0;
}
......@@ -80,8 +86,13 @@ int main(int argc, char *argv[])
fprintf(stderr, "pass file in $STATFS_INPUT\n");
exit(2);
}
global->readFrom(in);
in = getenv("STATFS_DELAY_USEC");
if (in != NULL) {
delay_usec = atoi(in);
}
struct fuse_operations statfs_oper = {0};
statfs_oper.getattr = &global_getattr;
return fuse_main(argc, argv, &statfs_oper, NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment