diff --git a/cmd/meta.go b/cmd/meta.go index 3c18d321e..e1a950819 100644 --- a/cmd/meta.go +++ b/cmd/meta.go @@ -27,6 +27,7 @@ func NewMetaCommand() *cobra.Command { return err } utils.LogBRInfo() + utils.LogArguments(c) return nil }, } diff --git a/cmd/raw.go b/cmd/raw.go index 944b7773c..bd73b1d80 100644 --- a/cmd/raw.go +++ b/cmd/raw.go @@ -21,6 +21,7 @@ func NewBackupCommand() *cobra.Command { return err } utils.LogBRInfo() + utils.LogArguments(c) return nil }, } diff --git a/cmd/restore.go b/cmd/restore.go index 0372eb239..02ea7cec2 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -26,6 +26,7 @@ func NewRestoreCommand() *cobra.Command { return err } utils.LogBRInfo() + utils.LogArguments(c) return nil }, } diff --git a/main.go b/main.go index e9e87fb5b..5eeb65a78 100644 --- a/main.go +++ b/main.go @@ -7,9 +7,10 @@ import ( "os/signal" "syscall" - "github.com/pingcap/br/cmd" "github.com/pingcap/errors" "github.com/spf13/cobra" + + "github.com/pingcap/br/cmd" ) func main() { diff --git a/pkg/raw/full.go b/pkg/raw/full.go index 7e6abd15c..427c71d31 100644 --- a/pkg/raw/full.go +++ b/pkg/raw/full.go @@ -759,6 +759,7 @@ type tableChecksum struct { checksum uint64 totalKvs uint64 totalBytes uint64 + duration time.Duration } func getChecksumFromTiDB( @@ -767,6 +768,7 @@ func getChecksumFromTiDB( dbName string, tableName string, ) (*tableChecksum, error) { + start := time.Now() var recordSets []sqlexec.RecordSet recordSets, err := dbSession.Execute(ctx, fmt.Sprintf( "ADMIN CHECKSUM TABLE %s.%s", utils.EncloseName(dbName), utils.EncloseName(tableName))) @@ -795,6 +797,7 @@ func getChecksumFromTiDB( checksum: checksum, totalKvs: totalKvs, totalBytes: totalBytes, + duration: time.Since(start), }, nil } @@ -846,7 +849,8 @@ func (bs *backupSchemas) finishTableChecksum() ([]*backup.Schema, error) { zap.String("table", checksum.name), zap.Uint64("Crc64Xor", checksum.checksum), zap.Uint64("TotalKvs", checksum.totalKvs), - zap.Uint64("TotalBytes", checksum.totalBytes)) + zap.Uint64("TotalBytes", checksum.totalBytes), + zap.Duration("take", checksum.duration)) s := bs.meta[checksum.name] s.Crc64Xor = checksum.checksum s.TotalKvs = checksum.totalKvs diff --git a/pkg/utils/version.go b/pkg/utils/version.go index 07e40b813..d378edffe 100644 --- a/pkg/utils/version.go +++ b/pkg/utils/version.go @@ -4,6 +4,8 @@ import ( "fmt" "github.com/pingcap/log" + "github.com/spf13/cobra" + "github.com/spf13/pflag" "go.uber.org/zap" ) @@ -31,3 +33,12 @@ func PrintBRInfo() { fmt.Println("Git Branch:", BRGitBranch) fmt.Println("UTC Build Time: ", BRBuildTS) } + +// LogArguments prints origin command arguments +func LogArguments(cmd *cobra.Command) { + var fields []zap.Field + cmd.Flags().VisitAll(func(f *pflag.Flag) { + fields = append(fields, zap.Stringer(f.Name, f.Value)) + }) + log.Info("arguments", fields...) +}