feat: implement :perftrace and :help commands#632
Open
dlevy-msft-sql wants to merge 5 commits intomicrosoft:mainfrom
Open
feat: implement :perftrace and :help commands#632dlevy-msft-sql wants to merge 5 commits intomicrosoft:mainfrom
dlevy-msft-sql wants to merge 5 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements the :perftrace command to redirect performance statistics output to a file, stderr, or stdout, working in conjunction with the -p flag from PR #631.
Changes:
- Added stat writer infrastructure with GetStat/SetStat methods following the established pattern for output/error writers
- Implemented PERFTRACE command supporting file paths, "stdout", and "stderr" with variable substitution
- Added comprehensive test coverage for the command functionality
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/sqlcmd/sqlcmd.go | Added stat field and GetStat()/SetStat() methods for managing performance statistics output writer |
| pkg/sqlcmd/commands.go | Registered PERFTRACE command and implemented perftraceCommand() function with file/stdout/stderr support |
| pkg/sqlcmd/commands_test.go | Added TestPerftraceCommand() with comprehensive test scenarios and added PERFTRACE parsing tests |
| README.md | Documented the :perftrace command with usage example |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Jan 25, 2026
Closed
e7abfe7 to
4d25bf2
Compare
652c011 to
1175a7e
Compare
:perftrace redirects timing/statistics output to a file, stderr, or stdout. :help displays the list of available sqlcmd commands with usage. Both commands validate arguments and return appropriate errors.
1175a7e to
ccd2a31
Compare
dlevy-msft-sql
added a commit
to dlevy-msft-sql/go-sqlcmd
that referenced
this pull request
Apr 17, 2026
Accept an io.Writer parameter instead of hardcoding s.GetOutput(), enabling PR microsoft#632 (:perftrace) to redirect statistics output via s.GetStat() after merge.
After merging print-statistics, the printStatistics call site should pass s.GetStat() instead of s.GetOutput() so :perftrace redirection applies to performance statistics output.
- Generate :help output from registered Command.help fields instead of hardcoded string literal (eliminates drift when commands are added) - Add help field to every registered command in newCommands() - Extract redirectWriter() to deduplicate outCommand/errorCommand/perftraceCommand - Remove DB dependency from TestHelpCommand and TestPerftraceCommand - Add TestAllCommandsHaveHelp to catch commands with missing help text - Strengthen TestHelpCommand to cross-reference registered help fields - Remove stale PR merge note from GetStat() godoc
- :HELP <command> now shows help for a single command (case-insensitive) - Unknown command names fall through to the full help listing - Sort help entries by help text (stable: all start with command name) - README: clarify :perftrace requires -p flag for timing data - Add tests for per-command help, case-insensitive lookup, and unknown command fallback
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two new interactive commands:
:helpand:perftrace.:helpdisplays a reference of all available sqlcmd commands with short descriptions. It can also show help for a single command::help connect.:perftraceredirects performance statistics output (from the-pflag, PR #631) to a file, stderr, or stdout -- the same way:outand:errorredirect query and error output.New commands
:help:help <command>:perftrace <file>Usage
Implementation
helpfield to theCommandstruct. Every registered command carries its own help text, so:helpoutput is always in sync with the command registry. ATestAllCommandsHaveHelptest guards against drift.:help <command>does a case-insensitive lookup into the command map. Unknown names fall through to the full listing.redirectWriter()to share file/stderr/stdout resolution logic across:out,:error, and:perftrace(was duplicated betweenoutCommandanderrorCommand).stat(io.WriteCloser) field toSqlcmdwithGetStat()/SetStat()accessors.GetStat()falls back toGetOutput()when no:perftraceredirection is active, so existing-poutput is unaffected.SetStat(nil)called during cleanup incmd/sqlcmd/sqlcmd.goto close any open perf trace file.Testing
TestHelpCommand: full listing, per-command filtering, case-insensitive lookup, unknown command fallbackTestAllCommandsHaveHelp: drift guard ensuring every command has help textTestPerftraceCommand: empty arg error, stdout, stderr, file redirect, variable resolutionTestCommandParsing: parsing for:help,:help CONNECT,:perftrace stderr, etc.Merge notes
-pflag). After both merge, update theprintStatistics()call site to useGetStat()instead ofGetOutput().:serverlist) also registers aHELPcommand. Merge this PR first, then rebase feat: implement :serverlist command #630.Fixes #622.