Skip to content

Commit 94a90f0

Browse files
author
David Shiflet (from Dev Box)
committed
add trace file param
1 parent e8f9c26 commit 94a90f0

14 files changed

Lines changed: 788 additions & 51 deletions

File tree

cmd/sqlcmd/sqlcmd.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net"
1212
"os"
1313
"regexp"
14+
"runtime/trace"
1415
"strconv"
1516
"strings"
1617
"time"
@@ -78,6 +79,7 @@ type SQLCmdArguments struct {
7879
EnableColumnEncryption bool
7980
ChangePassword string
8081
ChangePasswordAndExit string
82+
TraceFile string
8183
// Keep Help at the end of the list
8284
Help bool
8385
}
@@ -380,6 +382,7 @@ func SetScreenWidthFlags(args *SQLCmdArguments, rootCmd *cobra.Command) {
380382
func setFlags(rootCmd *cobra.Command, args *SQLCmdArguments) {
381383
rootCmd.SetFlagErrorFunc(flagErrorHandler)
382384
rootCmd.Flags().BoolVarP(&args.Help, "help", "?", false, localizer.Sprintf("-? shows this syntax summary, %s shows modern sqlcmd sub-command help", localizer.HelpFlag))
385+
rootCmd.Flags().StringVar(&args.TraceFile, "trace-file", "", localizer.Sprintf("Write runtime trace to the specified file. Only for advanced debugging."))
383386
var inputfiles []string
384387
rootCmd.Flags().StringSliceVarP(&args.InputFile, "input-file", "i", inputfiles, localizer.Sprintf("Identifies one or more files that contain batches of SQL statements. If one or more files do not exist, sqlcmd will exit. Mutually exclusive with %s/%s", localizer.QueryAndExitFlag, localizer.QueryFlag))
385388
rootCmd.Flags().StringVarP(&args.OutputFile, "output-file", "o", "", localizer.Sprintf("Identifies the file that receives output from sqlcmd"))
@@ -742,6 +745,18 @@ func isConsoleInitializationRequired(connect *sqlcmd.ConnectSettings, args *SQLC
742745
}
743746

744747
func run(vars *sqlcmd.Variables, args *SQLCmdArguments) (int, error) {
748+
if args.TraceFile != "" {
749+
traceFile, err := os.Create(args.TraceFile)
750+
if err != nil {
751+
return 1, localizer.Errorf("failed to create trace file '%s': %v", args.TraceFile, err)
752+
}
753+
defer traceFile.Close()
754+
err = trace.Start(traceFile)
755+
if err != nil {
756+
return 1, localizer.Errorf("failed to start trace: %v", err)
757+
}
758+
defer trace.Stop()
759+
}
745760
wd, err := os.Getwd()
746761
if err != nil {
747762
return 1, err

internal/translations/catalog.go

Lines changed: 68 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)