mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	edge-node gc命令增加耗时和gc pause时长
This commit is contained in:
		@@ -228,11 +228,18 @@ func main() {
 | 
			
		||||
	})
 | 
			
		||||
	app.On("gc", func() {
 | 
			
		||||
		var sock = gosock.NewTmpSock(teaconst.ProcessName)
 | 
			
		||||
		_, err := sock.Send(&gosock.Command{Code: "gc"})
 | 
			
		||||
		reply, err := sock.Send(&gosock.Command{Code: "gc"})
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			fmt.Println("[ERROR]" + err.Error())
 | 
			
		||||
		} else {
 | 
			
		||||
			if reply == nil {
 | 
			
		||||
				fmt.Println("ok")
 | 
			
		||||
			} else {
 | 
			
		||||
				var paramMap = maps.NewMap(reply.Params)
 | 
			
		||||
				var pauseMS = paramMap.GetFloat64("pauseMS")
 | 
			
		||||
				var costMS = paramMap.GetFloat64("costMS")
 | 
			
		||||
				fmt.Printf("ok, cost: %.4fms, pause: %.4fms", costMS, pauseMS)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	})
 | 
			
		||||
	app.On("ip.drop", func() {
 | 
			
		||||
 
 | 
			
		||||
@@ -777,9 +777,19 @@ func (this *Node) listenSock() error {
 | 
			
		||||
					_ = cmd.ReplyOk()
 | 
			
		||||
				}
 | 
			
		||||
			case "gc":
 | 
			
		||||
				var before = time.Now()
 | 
			
		||||
				runtime.GC()
 | 
			
		||||
				debug.FreeOSMemory()
 | 
			
		||||
				_ = cmd.ReplyOk()
 | 
			
		||||
 | 
			
		||||
				var costSeconds = time.Since(before).Seconds()
 | 
			
		||||
				var gcStats = &debug.GCStats{}
 | 
			
		||||
				debug.ReadGCStats(gcStats)
 | 
			
		||||
				_ = cmd.Reply(&gosock.Command{
 | 
			
		||||
					Params: map[string]any{
 | 
			
		||||
						"pauseMS": gcStats.PauseTotal.Seconds() * 1000,
 | 
			
		||||
						"costMS":  costSeconds * 1000,
 | 
			
		||||
					},
 | 
			
		||||
				})
 | 
			
		||||
			case "reload":
 | 
			
		||||
				err := this.syncConfig(0)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user