-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4432 from kolyshkin/exec-bench
libct/int: add exec benchmark
- Loading branch information
Showing
3 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package integration | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/opencontainers/runc/libcontainer" | ||
) | ||
|
||
func BenchmarkExecTrue(b *testing.B) { | ||
config := newTemplateConfig(b, nil) | ||
container, err := newContainer(b, config) | ||
ok(b, err) | ||
defer destroyContainer(container) | ||
|
||
// Execute a first process in the container | ||
stdinR, stdinW, err := os.Pipe() | ||
ok(b, err) | ||
process := &libcontainer.Process{ | ||
Cwd: "/", | ||
Args: []string{"cat"}, | ||
Env: standardEnvironment, | ||
Stdin: stdinR, | ||
Init: true, | ||
} | ||
err = container.Run(process) | ||
_ = stdinR.Close() | ||
defer func() { | ||
_ = stdinW.Close() | ||
if _, err := process.Wait(); err != nil { | ||
b.Log(err) | ||
} | ||
}() | ||
ok(b, err) | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
exec := &libcontainer.Process{ | ||
Cwd: "/", | ||
Args: []string{"/bin/true"}, | ||
Env: standardEnvironment, | ||
LogLevel: "0", // Minimize forwardChildLogs involvement. | ||
} | ||
err := container.Run(exec) | ||
if err != nil { | ||
b.Fatal("exec failed:", err) | ||
} | ||
waitProcess(exec, b) | ||
} | ||
b.StopTimer() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters