Skip to content

Commit d81f3fb

Browse files
refactor: pass writer to printStatistics for perftrace support
Accept an io.Writer parameter instead of hardcoding s.GetOutput(), enabling PR microsoft#632 (:perftrace) to redirect statistics output via s.GetStat() after merge.
1 parent b7565f6 commit d81f3fb

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

pkg/sqlcmd/sqlcmd.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ func (s *Sqlcmd) runQuery(query string) (int, error) {
513513
}
514514
s.Format.EndBatch()
515515
elapsedMs := time.Since(startTime).Milliseconds()
516-
s.printStatistics(elapsedMs, 1)
516+
s.printStatistics(elapsedMs, 1, s.GetOutput())
517517
return retcode, qe
518518
}
519519

@@ -588,8 +588,10 @@ func (s *Sqlcmd) StopCloseHandler() {
588588
}
589589

590590
// printStatistics prints performance statistics after a batch execution
591-
// if PrintStatistics is enabled
592-
func (s *Sqlcmd) printStatistics(elapsedMs int64, numBatches int) {
591+
// if PrintStatistics is enabled. The out parameter controls where the
592+
// statistics are written (typically s.GetOutput(), or s.GetStat() when
593+
// :perftrace redirection is active).
594+
func (s *Sqlcmd) printStatistics(elapsedMs int64, numBatches int, out io.Writer) {
593595
if s.PrintStatistics == nil || numBatches <= 0 {
594596
return
595597
}
@@ -608,7 +610,6 @@ func (s *Sqlcmd) printStatistics(elapsedMs int64, numBatches int) {
608610
avgTime := float64(elapsedMs) / float64(numBatches)
609611
batchesPerSec := float64(numBatches) / (float64(elapsedMs) / 1000.0)
610612

611-
out := s.GetOutput()
612613
if *s.PrintStatistics == 1 {
613614
// Colon-separated format: n:x:t1:t2:t3
614615
// packetSize:numBatches:totalTime:avgTime:batchesPerSec

0 commit comments

Comments
 (0)