@@ -19,17 +19,24 @@ type CommandRunner interface {
1919 RunForOutput (c * command.Model ) (string , error )
2020 Run (c * command.Model ) error
2121 RunWithRetry (getCommmand func () * command.Model ) error
22+ SetPerformanceMonitoring (enable bool )
23+ PausePerformanceMonitoring ()
24+ ResumePerformanceMonitoring ()
2225}
2326
2427// DefaultRunner ...
2528type DefaultRunner struct {
29+ performanceMonitoringEnabled bool
30+ performanceMonitoringTemporarilyDisabled bool
2631}
2732
2833// RunForOutput ...
29- func (r DefaultRunner ) RunForOutput (c * command.Model ) (string , error ) {
34+ func (r * DefaultRunner ) RunForOutput (c * command.Model ) (string , error ) {
3035 fmt .Println ()
3136 log .Infof ("$ %s &> out" , c .PrintableCommandArgs ())
3237
38+ r .setupPerformanceMonitoring (c )
39+
3340 out , err := c .RunAndReturnTrimmedCombinedOutput ()
3441 if err != nil && errorutil .IsExitStatusError (err ) {
3542 return out , errors .New (out )
@@ -39,11 +46,13 @@ func (r DefaultRunner) RunForOutput(c *command.Model) (string, error) {
3946}
4047
4148// Run ...
42- func (r DefaultRunner ) Run (c * command.Model ) error {
49+ func (r * DefaultRunner ) Run (c * command.Model ) error {
4350 fmt .Println ()
4451 log .Infof ("$ %s" , c .PrintableCommandArgs ())
4552 var buffer bytes.Buffer
4653
54+ r .setupPerformanceMonitoring (c )
55+
4756 err := c .SetStdout (os .Stdout ).SetStderr (io .MultiWriter (os .Stderr , & buffer )).Run ()
4857 if err != nil {
4958 if errorutil .IsExitStatusError (err ) {
@@ -60,7 +69,7 @@ func (r DefaultRunner) Run(c *command.Model) error {
6069}
6170
6271// RunWithRetry ...
63- func (r DefaultRunner ) RunWithRetry (getCommand func () * command.Model ) error {
72+ func (r * DefaultRunner ) RunWithRetry (getCommand func () * command.Model ) error {
6473 return retry .Times (2 ).Wait (5 ).Try (func (attempt uint ) error {
6574 if attempt > 0 {
6675 log .Warnf ("Retrying..." )
@@ -75,3 +84,26 @@ func (r DefaultRunner) RunWithRetry(getCommand func() *command.Model) error {
7584 return err
7685 })
7786}
87+
88+ func (r * DefaultRunner ) SetPerformanceMonitoring (enable bool ) {
89+ r .performanceMonitoringEnabled = enable
90+ }
91+
92+ func (r * DefaultRunner ) PausePerformanceMonitoring () {
93+ r .performanceMonitoringTemporarilyDisabled = true
94+ }
95+
96+ func (r * DefaultRunner ) ResumePerformanceMonitoring () {
97+ r .performanceMonitoringTemporarilyDisabled = false
98+ }
99+
100+ func (r * DefaultRunner ) setupPerformanceMonitoring (c * command.Model ) {
101+ if r .performanceMonitoringTemporarilyDisabled {
102+ c .AppendEnvs ("GIT_TRACE2_PERF=0" )
103+ return
104+ }
105+
106+ if r .performanceMonitoringEnabled {
107+ c .AppendEnvs ("GIT_TRACE2_PERF=1" )
108+ }
109+ }
0 commit comments