Skip to content

Commit

Permalink
Merge pull request checkpoint-restore#12 from adrianreber/2021-11-01-…
Browse files Browse the repository at this point in the history
…print-stats

Add '--print-stats' option
  • Loading branch information
adrianreber authored Nov 5, 2021
2 parents f505167 + fafa487 commit 7ab6709
Show file tree
Hide file tree
Showing 137 changed files with 31,236 additions and 3 deletions.
7 changes: 7 additions & 0 deletions checkpointctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
output string
input string
compress string
printStats bool
)

func main() {
Expand Down Expand Up @@ -76,6 +77,12 @@ func setupShow() *cobra.Command {
false,
"Show Pod IP in output",
)
flags.BoolVar(
&printStats,
"print-stats",
false,
"Print checkpointing statistics if available",
)

return cmd
}
Expand Down
36 changes: 36 additions & 0 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

metadata "github.com/checkpoint-restore/checkpointctl/lib"
"github.com/checkpoint-restore/go-criu/v5/stats"
"github.com/olekukonko/tablewriter"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
Expand Down Expand Up @@ -143,6 +144,41 @@ func showContainerCheckpoint(checkpointDirectory string) error {
table.Append(row)
table.Render()

if !printStats {
return nil
}

cpDir, err := os.Open(checkpointDirectory)
if err != nil {
return errors.Wrapf(err, "Not able to open %q", checkpointDirectory)
}
defer cpDir.Close()

dumpStatistics, err := stats.CriuGetDumpStats(cpDir)
if err != nil {
return errors.Wrap(err, "Displaying checkpointing statistics not possible")
}

table = tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Freezing Time",
"Frozen Time",
"Memdump Time",
"Memwrite Time",
"Pages Scanned",
"Pages Written",
})
table.Append([]string{
fmt.Sprintf("%d us", dumpStatistics.GetFreezingTime()),
fmt.Sprintf("%d us", dumpStatistics.GetFrozenTime()),
fmt.Sprintf("%d us", dumpStatistics.GetMemdumpTime()),
fmt.Sprintf("%d us", dumpStatistics.GetMemwriteTime()),
fmt.Sprintf("%d", dumpStatistics.GetPagesScanned()),
fmt.Sprintf("%d", dumpStatistics.GetPagesWritten()),
})
fmt.Println("CRIU dump statistics")
table.Render()

return nil
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/checkpoint-restore/checkpointctl
go 1.15

require (
github.com/checkpoint-restore/go-criu/v5 v5.2.0
github.com/containers/storage v1.37.0
github.com/olekukonko/tablewriter v0.0.5
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqO
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/checkpoint-restore/go-criu/v5 v5.0.0/go.mod h1:cfwC0EG7HMUenopBsUf9d89JlCLQIfgVcNsNN0t6T2M=
github.com/checkpoint-restore/go-criu/v5 v5.2.0 h1:QwsRK9EdBr2kQr44DqSdBrP4dULp2+4EkqounYQOnF8=
github.com/checkpoint-restore/go-criu/v5 v5.2.0/go.mod h1:E/eQpaFtUKGOOSEBZgmKAcn+zUUwWxqcaKZlF54wK8E=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
Expand Down Expand Up @@ -167,6 +169,7 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-intervals v0.0.2/go.mod h1:MkaR3LNRfeKLPmqgJYs4E66z5InYjmCjbbr4TQlcT6Y=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down Expand Up @@ -616,6 +619,7 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
Expand Down Expand Up @@ -721,6 +725,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
3 changes: 0 additions & 3 deletions lib/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ const (
// pod archive
PodOptionsFile = "pod.options"
PodDumpFile = "pod.dump"

StatsDump = "stats-dump"
StatsRestore = "stats-restore"
)

type CheckpointType int
Expand Down
34 changes: 34 additions & 0 deletions test/checkpointctl.bats
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,40 @@ function teardown() {
[[ ${lines[4]} == *"Podman"* ]]
}

@test "Run checkpointctl show with tar file and --print-stats and missing stats-dump" {
cp test/config.dump "$TEST_TMP_DIR1"
cp test/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show -t "$TEST_TMP_DIR2"/test.tar --print-stats
[ "$status" -eq 1 ]
[[ ${lines[6]} == *"Displaying checkpointing statistics"* ]]
}

@test "Run checkpointctl show with tar file and --print-stats and invalid stats-dump" {
cp test/config.dump "$TEST_TMP_DIR1"
cp test/spec.dump "$TEST_TMP_DIR1"
cp test/spec.dump "$TEST_TMP_DIR1"/stats-dump
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show -t "$TEST_TMP_DIR2"/test.tar --print-stats
[ "$status" -eq 1 ]
[[ ${lines[6]} == *"Primary magic not found"* ]]
}

@test "Run checkpointctl show with tar file and --print-stats and valid stats-dump" {
cp test/config.dump "$TEST_TMP_DIR1"
cp test/spec.dump "$TEST_TMP_DIR1"
cp test/stats-dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show -t "$TEST_TMP_DIR2"/test.tar --print-stats
[ "$status" -eq 0 ]
[[ ${lines[6]} == *"CRIU dump statistics"* ]]
[[ ${lines[8]} == *"MEMWRITE TIME"* ]]
[[ ${lines[10]} == *"446571 us"* ]]
}

@test "Run checkpointctl show with tar file with empty pod.dump" {
touch "$TEST_TMP_DIR1"/pod.dump
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
Expand Down
Binary file added test/stats-dump
Binary file not shown.
201 changes: 201 additions & 0 deletions vendor/github.com/checkpoint-restore/go-criu/v5/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7ab6709

Please sign in to comment.