From 15dfa7fd057f3dc3293e6e57b79b701f2ab785ca Mon Sep 17 00:00:00 2001 From: Naoki MATSUMOTO Date: Fri, 19 Apr 2024 10:58:24 +0900 Subject: [PATCH] add count option to 'stat diff' for benchmark Signed-off-by: Naoki MATSUMOTO --- cmd/ctr-cli/stat/stat.go | 16 +++++++++++++++- pkg/benchmark/benchmark.go | 4 ++++ tests/bench_impl.sh | 2 +- tests/plot_file_io.py | 2 ++ tests/plot_file_io_with_type.py | 2 ++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cmd/ctr-cli/stat/stat.go b/cmd/ctr-cli/stat/stat.go index d6bbfff..830f171 100644 --- a/cmd/ctr-cli/stat/stat.go +++ b/cmd/ctr-cli/stat/stat.go @@ -6,6 +6,7 @@ import ( "io" "os" "path/filepath" + "strconv" "time" "github.com/naoki9911/fuse-diff-containerd/pkg/benchmark" @@ -103,6 +104,11 @@ func diffCommand() *cli.Command { Required: false, Value: "pathB", }, + &cli.IntFlag{ + Name: "count", + Required: false, + Value: 1, + }, }, } @@ -134,7 +140,15 @@ func diffAction(c *cli.Context) error { } defer fmt.Println("done") - return diffImpl(pathA, pathB, pm, b, c.String("pathALabel"), c.String("pathBLabel"), pathA, pathB) + for i := 0; i < c.Int("count"); i++ { + b.SetLabel("count", strconv.Itoa(i)) + err = diffImpl(pathA, pathB, pm, b, c.String("pathALabel"), c.String("pathBLabel"), pathA, pathB) + if err != nil { + return err + } + } + + return nil } func doBoth[T, U any](pathA, pathB T, f func(path T) (U, error)) (U, U, error) { diff --git a/pkg/benchmark/benchmark.go b/pkg/benchmark/benchmark.go index 8ff1e46..61a3d29 100644 --- a/pkg/benchmark/benchmark.go +++ b/pkg/benchmark/benchmark.go @@ -46,6 +46,10 @@ func (b *Benchmark) SetDefaultLabels(l map[string]string) { b.defaultLabels = l } +func (b *Benchmark) SetLabel(k, v string) { + b.defaultLabels[k] = v +} + func (b *Benchmark) Close() error { err := b.logFile.Close() if err != nil { diff --git a/tests/bench_impl.sh b/tests/bench_impl.sh index a2207df..bd17d8b 100755 --- a/tests/bench_impl.sh +++ b/tests/bench_impl.sh @@ -92,7 +92,7 @@ for ((i=0; i < $(expr ${#IMAGE_VERSIONS[@]} - 1); i++));do fi set -u - $BIN_CTR_CLI --labels $LABELS,old:$LOWER,new:$UPPER,mode:binary-diff,out:$LOWER-$UPPER stat diff --benchmark --pathALabel native --pathBLabel di3fs $UPPER /tmp/fuse + $BIN_CTR_CLI --labels $LABELS,old:$LOWER,new:$UPPER,mode:binary-diff,out:$LOWER-$UPPER stat diff --benchmark --pathALabel native --pathBLabel di3fs --count 5 $UPPER /tmp/fuse fi fusermount3 -u /tmp/fuse done diff --git a/tests/plot_file_io.py b/tests/plot_file_io.py index 3e2eedd..0f1f03d 100644 --- a/tests/plot_file_io.py +++ b/tests/plot_file_io.py @@ -23,6 +23,8 @@ # ignore 0-bytes file if fileSize == 0: continue + if labels["count"] != "0": + continue elapsedUS = r["elapsedMicroseconds"] tag = "{}".format(pathLabel) if tag not in stat_open: diff --git a/tests/plot_file_io_with_type.py b/tests/plot_file_io_with_type.py index 9aeffc3..787f996 100644 --- a/tests/plot_file_io_with_type.py +++ b/tests/plot_file_io_with_type.py @@ -48,6 +48,8 @@ continue if pathLabel != "di3fs": continue + if labels["count"] != "0": + continue tag = "{}:{}-{}".format(imageName, old, new) entryType = files[tag][path]