Skip to content

feat: implement :perftrace and :help commands#632

Open
dlevy-msft-sql wants to merge 2 commits intomicrosoft:mainfrom
dlevy-msft-sql:perftrace
Open

feat: implement :perftrace and :help commands#632
dlevy-msft-sql wants to merge 2 commits intomicrosoft:mainfrom
dlevy-msft-sql:perftrace

Conversation

@dlevy-msft-sql
Copy link
Copy Markdown
Contributor

@dlevy-msft-sql dlevy-msft-sql commented Jan 25, 2026

Summary Adds the :perftrace command to redirect performance statistics output to a file, stderr, or stdout. This works in conjunction with the -p flag (PR #631) to control where timing statistics are written. ## Syntax bash sqlcmd -S server -Q "SELECT 1" -p :perftrace <filename>|stderr|stdout ## Changes - pkg/sqlcmd/sqlcmd.go: Added stat writer field and GetStat/SetStat methods - pkg/sqlcmd/commands.go: Added PERFTRACE command with file/stdout/stderr support - pkg/sqlcmd/commands_test.go: Added tests for command parsing and functionality - README.md: Added documentation with usage example ## Testing - All tests pass - golangci-lint run passes (pre-existing warnings only) - Build succeeds ## Related - PR #631 implements the -p flag for print statistics

Fixes #622.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

Comment thread pkg/sqlcmd/commands_test.go
Comment thread pkg/sqlcmd/commands_test.go
Comment thread pkg/sqlcmd/commands.go Outdated
Comment thread README.md Outdated
Comment thread pkg/sqlcmd/commands.go Outdated
Comment thread pkg/sqlcmd/commands_test.go
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread README.md
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread pkg/sqlcmd/sqlcmd.go
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@dlevy-msft-sql dlevy-msft-sql self-assigned this Jan 25, 2026
@dlevy-msft-sql dlevy-msft-sql added sqlcmd switch switch in existing sqlcmd Size: S Small issue (less than one week effort) labels Jan 25, 2026
@dlevy-msft-sql dlevy-msft-sql changed the title Implement :perftrace command Implement :perftrace and :help commands Feb 5, 2026
@dlevy-msft-sql dlevy-msft-sql force-pushed the perftrace branch 2 times, most recently from e7abfe7 to 4d25bf2 Compare February 5, 2026 19:58
@dlevy-msft-sql dlevy-msft-sql changed the title Implement :perftrace and :help commands feat: implement :perftrace and :help commands Feb 5, 2026
: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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size: S Small issue (less than one week effort) sqlcmd switch switch in existing sqlcmd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: :TIMING ON/OFF command for interactive sessions

2 participants