@@ -28,14 +28,12 @@ import (
2828	"errors" 
2929	"fmt" 
3030	"os" 
31- 	"runtime" 
3231	"sync" 
3332	"syscall" 
3433	"time" 
3534
3635	"go.uber.org/cadence/internal/common/debug" 
3736
38- 	"github.com/shirou/gopsutil/cpu" 
3937	"github.com/uber-go/tally" 
4038	"go.uber.org/zap" 
4139	"go.uber.org/zap/zapcore" 
@@ -50,7 +48,6 @@ import (
5048const  (
5149	retryPollOperationInitialInterval  =  20  *  time .Millisecond 
5250	retryPollOperationMaxInterval      =  10  *  time .Second 
53- 	hardwareMetricsCollectInterval     =  30  *  time .Second 
5451)
5552
5653var  (
5956
6057var  errShutdown  =  errors .New ("worker shutting down" )
6158
62- var  collectHardwareUsageOnce  sync.Once 
63- 
6459type  (
6560	// resultHandler that returns result 
6661	resultHandler    func (result  []byte , err  error )
@@ -223,7 +218,6 @@ func (bw *baseWorker) Start() {
223218	// We want the emit function run once per host instead of run once per worker 
224219	// since the emit function is host level metric. 
225220	bw .shutdownWG .Add (1 )
226- 	go  bw .emitHardwareUsage ()
227221
228222	bw .isWorkerStarted  =  true 
229223	traceLog (func () {
@@ -400,7 +394,7 @@ func (bw *baseWorker) Run() {
400394	bw .Stop ()
401395}
402396
403- // Shutdown  is a blocking call and cleans up all the resources associated with worker. 
397+ // Stop  is a blocking call and cleans up all the resources associated with worker. 
404398func  (bw  * baseWorker ) Stop () {
405399	if  ! bw .isWorkerStarted  {
406400		return 
@@ -423,53 +417,3 @@ func (bw *baseWorker) Stop() {
423417	}
424418	return 
425419}
426- 
427- func  (bw  * baseWorker ) emitHardwareUsage () {
428- 	defer  func () {
429- 		if  p  :=  recover (); p  !=  nil  {
430- 			bw .metricsScope .Counter (metrics .WorkerPanicCounter ).Inc (1 )
431- 			topLine  :=  fmt .Sprintf ("base worker for %s [panic]:" , bw .options .workerType )
432- 			st  :=  getStackTraceRaw (topLine , 7 , 0 )
433- 			bw .logger .Error ("Unhandled panic in hardware emitting." ,
434- 				zap .String (tagPanicError , fmt .Sprintf ("%v" , p )),
435- 				zap .String (tagPanicStack , st ))
436- 		}
437- 	}()
438- 	defer  bw .shutdownWG .Done ()
439- 	collectHardwareUsageOnce .Do (
440- 		func () {
441- 			ticker  :=  time .NewTicker (hardwareMetricsCollectInterval )
442- 			for  {
443- 				select  {
444- 				case  <- bw .shutdownCh :
445- 					ticker .Stop ()
446- 					return 
447- 				case  <- ticker .C :
448- 					host  :=  bw .options .host 
449- 					scope  :=  bw .metricsScope .Tagged (map [string ]string {clientHostTag : host })
450- 
451- 					cpuPercent , err  :=  cpu .Percent (0 , false )
452- 					if  err  !=  nil  {
453- 						bw .logger .Warn ("Failed to get cpu percent" , zap .Error (err ))
454- 						return 
455- 					}
456- 					cpuCores , err  :=  cpu .Counts (false )
457- 					if  err  !=  nil  {
458- 						bw .logger .Warn ("Failed to get number of cpu cores" , zap .Error (err ))
459- 						return 
460- 					}
461- 					scope .Gauge (metrics .NumCPUCores ).Update (float64 (cpuCores ))
462- 					scope .Gauge (metrics .CPUPercentage ).Update (cpuPercent [0 ])
463- 
464- 					var  memStats  runtime.MemStats 
465- 					runtime .ReadMemStats (& memStats )
466- 
467- 					scope .Gauge (metrics .NumGoRoutines ).Update (float64 (runtime .NumGoroutine ()))
468- 					scope .Gauge (metrics .TotalMemory ).Update (float64 (memStats .Sys ))
469- 					scope .Gauge (metrics .MemoryUsedHeap ).Update (float64 (memStats .HeapInuse ))
470- 					scope .Gauge (metrics .MemoryUsedStack ).Update (float64 (memStats .StackInuse ))
471- 				}
472- 			}
473- 		})
474- 
475- }
0 commit comments