From 837d7d71883d559d9990b054b0d55cc5358a801b Mon Sep 17 00:00:00 2001 From: Richard Liu Date: Fri, 13 Jul 2018 19:31:15 -0700 Subject: [PATCH] updated mem and cpu usage. --- benchmark.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/benchmark.go b/benchmark.go index bf1744a3c..ebb9c6b38 100644 --- a/benchmark.go +++ b/benchmark.go @@ -9,10 +9,8 @@ import ( "harmony-benchmark/log" "harmony-benchmark/node" "harmony-benchmark/p2p" - "harmony-benchmark/utils" "math/rand" "os" - "runtime" "strings" "time" @@ -95,25 +93,21 @@ func attackDetermination(attackedMode int) bool { } func logMemUsage(consensus *consensus.Consensus) { + p, _ := process.NewProcess(int32(os.Getpid())) for { - var m runtime.MemStats - runtime.ReadMemStats(&m) - log.Info("Mem Report", "Alloc", utils.BToMb(m.Alloc), "TotalAlloc", utils.BToMb(m.TotalAlloc), - "Sys", utils.BToMb(m.Sys), "NumGC", m.NumGC, "consensus", consensus) + info, _ := p.MemoryInfo() + memMap, _ := p.MemoryMaps(false) + log.Info("Mem Report", "info", info, "map", memMap) time.Sleep(10 * time.Second) } } // TODO: @ricl, start another process for reporting. func logCPUUsage(consensus *consensus.Consensus) { - log.Info("PPID", "ppid", os.Getpid()) p, _ := process.NewProcess(int32(os.Getpid())) for { percent, _ := p.CPUPercent() - times, err := p.Times() - if err != nil { - log.Info("ERR", "Err", err) - } + times, _ := p.Times() log.Info("CPU Report", "Percent", percent, "Times", times, "consensus", consensus) time.Sleep(10 * time.Second) } @@ -157,7 +151,6 @@ func main() { // Consensus object. consensus := consensus.NewConsensus(*ip, *port, shardID, peers, leader) // Logging for consensus. - log.Info("PID", "pid", os.Getpid()) go logMemUsage(consensus) go logCPUUsage(consensus)