Skip to content

Commit

Permalink
util/printer: add race enabled in TiDBInfo (pingcap#6311)
Browse files Browse the repository at this point in the history
Makes it easy to check if the binary is build with race.
  • Loading branch information
coocood authored and tiancaiamao committed Apr 20, 2018
1 parent d521158 commit e97d17d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ var (
func main() {
flag.Parse()
if *version {
printer.PrintRawTiDBInfo()
fmt.Println(printer.GetTiDBInfo())
os.Exit(0)
}

Expand Down
19 changes: 19 additions & 0 deletions util/israce/israce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2018 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

// +build race

package israce

// RaceEnabled checks if race is enabled.
const RaceEnabled = true
19 changes: 19 additions & 0 deletions util/israce/norace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2018 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !race

package israce

// RaceEnabled checks if race is enabled.
const RaceEnabled = false
28 changes: 16 additions & 12 deletions util/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/util/israce"
log "github.com/sirupsen/logrus"
)

Expand All @@ -41,6 +42,7 @@ func PrintTiDBInfo() {
log.Infof("Git Branch: %s", TiDBGitBranch)
log.Infof("UTC Build Time: %s", TiDBBuildTS)
log.Infof("GoVersion: %s", GoVersion)
log.Infof("Race Enabled: %v", israce.RaceEnabled)
log.Infof("TiKV Min Version: %s", TiKVMinVersion)
configJSON, err := json.Marshal(config.GetGlobalConfig())
if err != nil {
Expand All @@ -49,20 +51,22 @@ func PrintTiDBInfo() {
log.Infof("Config: %s", configJSON)
}

// PrintRawTiDBInfo prints the TiDB version information without log info.
func PrintRawTiDBInfo() {
fmt.Println("Release Version: ", mysql.TiDBReleaseVersion)
fmt.Println("Git Commit Hash: ", TiDBGitHash)
fmt.Println("Git Commit Branch: ", TiDBGitBranch)
fmt.Println("UTC Build Time: ", TiDBBuildTS)
fmt.Println("GoVersion: ", GoVersion)
fmt.Println("TiKV Min Version: ", TiKVMinVersion)
}

// GetTiDBInfo returns the git hash and build time of this tidb-server binary.
func GetTiDBInfo() string {
return fmt.Sprintf("Release Version: %s\nGit Commit Hash: %s\nGit Branch: %s\nUTC Build Time: %s\nGoVersion: %s\nTiKV Min Version: %s",
mysql.TiDBReleaseVersion, TiDBGitHash, TiDBGitBranch, TiDBBuildTS, GoVersion, TiKVMinVersion)
return fmt.Sprintf("Release Version: %s\n"+
"Git Commit Hash: %s\n"+
"Git Branch: %s\n"+
"UTC Build Time: %s\n"+
"GoVersion: %s\n"+
"Race Enabled: %v\n"+
"TiKV Min Version: %s",
mysql.TiDBReleaseVersion,
TiDBGitHash,
TiDBGitBranch,
TiDBBuildTS,
GoVersion,
israce.RaceEnabled,
TiKVMinVersion)
}

// checkValidity checks whether cols and every data have the same length.
Expand Down

0 comments on commit e97d17d

Please sign in to comment.