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 ( ...@@ -17,11 +17,14 @@ import (
) )
var CheckSuccess = fuse.CheckSuccess var CheckSuccess = fuse.CheckSuccess
var delay = 0 * time.Microsecond
type StatFs struct { type StatFs struct {
fuse.DefaultFileSystem fuse.DefaultFileSystem
entries map[string]*fuse.Attr entries map[string]*fuse.Attr
dirs map[string][]fuse.DirEntry dirs map[string][]fuse.DirEntry
delay time.Duration
} }
func (me *StatFs) add(name string, a *fuse.Attr) { 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. ...@@ -47,6 +50,10 @@ func (me *StatFs) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.
if e == nil { if e == nil {
return nil, fuse.ENOENT return nil, fuse.ENOENT
} }
if me.delay > 0 {
time.Sleep(me.delay)
}
return e, fuse.OK return e, fuse.OK
} }
...@@ -152,6 +159,7 @@ func GetTestLines() []string { ...@@ -152,6 +159,7 @@ func GetTestLines() []string {
func BenchmarkGoFuseThreadedStat(b *testing.B) { func BenchmarkGoFuseThreadedStat(b *testing.B) {
b.StopTimer() b.StopTimer()
fs := NewStatFs() fs := NewStatFs()
fs.delay = delay
files := GetTestLines() files := GetTestLines()
for _, fn := range files { for _, fn := range files {
fs.add(fn, &fuse.Attr{Mode: fuse.S_IFREG | 0644}) fs.add(fn, &fuse.Attr{Mode: fuse.S_IFREG | 0644})
...@@ -239,7 +247,9 @@ func BenchmarkCFuseThreadedStat(b *testing.B) { ...@@ -239,7 +247,9 @@ func BenchmarkCFuseThreadedStat(b *testing.B) {
"-o", "-o",
"entry_timeout=0.0,attr_timeout=0.0,ac_attr_timeout=0.0,negative_timeout=0.0", "entry_timeout=0.0,attr_timeout=0.0,ac_attr_timeout=0.0,negative_timeout=0.0",
mountPoint) 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() cmd.Start()
bin, err := exec.LookPath("fusermount") bin, err := exec.LookPath("fusermount")
......
...@@ -18,7 +18,9 @@ extern "C" { ...@@ -18,7 +18,9 @@ extern "C" {
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h>
useconds_t delay_usec;
class StatFs { class StatFs {
public: public:
...@@ -42,6 +44,10 @@ public: ...@@ -42,6 +44,10 @@ public:
statbuf->st_mode = S_IFREG | 0666; statbuf->st_mode = S_IFREG | 0666;
} }
if (delay_usec > 0) {
usleep(delay_usec);
}
return 0; return 0;
} }
...@@ -80,8 +86,13 @@ int main(int argc, char *argv[]) ...@@ -80,8 +86,13 @@ int main(int argc, char *argv[])
fprintf(stderr, "pass file in $STATFS_INPUT\n"); fprintf(stderr, "pass file in $STATFS_INPUT\n");
exit(2); exit(2);
} }
global->readFrom(in); global->readFrom(in);
in = getenv("STATFS_DELAY_USEC");
if (in != NULL) {
delay_usec = atoi(in);
}
struct fuse_operations statfs_oper = {0}; struct fuse_operations statfs_oper = {0};
statfs_oper.getattr = &global_getattr; statfs_oper.getattr = &global_getattr;
return fuse_main(argc, argv, &statfs_oper, NULL); 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