merged profiler back.

pull/69/head
Richard Liu 6 years ago
parent 1e23a94207
commit c34f568056
  1. 17
      benchmark.go
  2. 8
      deploy.sh
  3. 55
      profiler/main.go
  4. 48
      profiler/profiler.go

@ -5,7 +5,6 @@ import (
"fmt"
"math/rand"
"os"
"strconv"
"time"
"github.com/simple-rules/harmony-benchmark/attack"
@ -13,6 +12,7 @@ import (
"github.com/simple-rules/harmony-benchmark/db"
"github.com/simple-rules/harmony-benchmark/log"
"github.com/simple-rules/harmony-benchmark/node"
"github.com/simple-rules/harmony-benchmark/profiler"
"github.com/simple-rules/harmony-benchmark/utils"
)
@ -32,13 +32,6 @@ func attackDetermination(attackedMode int) bool {
return false
}
func startProfiler(shardID string, logFolder string) {
err := utils.RunCmd("./profiler", "-pid", strconv.Itoa(os.Getpid()), "-shard_id", shardID, "-log_folder", logFolder)
if err != nil {
log.Error("Failed to start profiler")
}
}
func InitLDBDatabase(ip string, port string) (*db.LDBDatabase, error) {
// TODO(minhdoan): Refactor this.
dbFileName := "/tmp/harmony_" + ip + port + ".dat"
@ -56,6 +49,7 @@ func main() {
logFolder := flag.String("log_folder", "latest", "the folder collecting the logs of this execution")
attackedMode := flag.Int("attacked_mode", 0, "0 means not attacked, 1 means attacked, 2 means being open to be selected as attacked")
dbSupported := flag.Bool("db_supported", false, "false means not db_supported, true means db_supported")
profile := flag.Bool("profile", false, "Turn on profiling (CPU, Memory).")
flag.Parse()
// Set up randomization seed.
@ -95,9 +89,10 @@ func main() {
// Consensus object.
consensus := consensus.NewConsensus(*ip, *port, shardID, peers, leader)
// Start Profiler for leader
if role == "leader" {
startProfiler(shardID, *logFolder)
// Start Profiler for leader if profile argument is on
if *profile && role == "leader" {
profiler := profiler.NewProfiler(consensus.Log, os.Getpid(), shardID)
profiler.Start()
}
// Set logger to attack model.

@ -37,8 +37,6 @@ db_supported=$2
# Also it's recommended to use `go build` for testing the whole exe.
go build -o bin/benchmark
go build -o bin/txgen client/txgen/main.go
go build -o bin/profiler profiler/main.go
cd bin
# Create a tmp folder for logs
t=`date +"%Y%m%d-%H%M%S"`
@ -52,9 +50,9 @@ while IFS='' read -r line || [[ -n "$line" ]]; do
#echo $ip $port $mode
if [ "$mode" != "client" ]; then
if [ -z "$db_supported" ]; then
./benchmark -ip $ip -port $port -config_file $config -log_folder $log_folder&
./bin/benchmark -ip $ip -port $port -config_file $config -log_folder $log_folder&
else
./benchmark -ip $ip -port $port -config_file $config -log_folder $log_folder -db_supported&
./bin/benchmark -ip $ip -port $port -config_file $config -log_folder $log_folder -db_supported&
fi
fi
done < $config
@ -62,5 +60,5 @@ done < $config
txgen_disabled=$3
# Generate transactions
if [ -z "$txgen_disabled" ]; then
./txgen -config_file $config -log_folder $log_folder
./bin/txgen -config_file $config -log_folder $log_folder
fi

@ -1,55 +0,0 @@
package main
import (
"flag"
"fmt"
"time"
"github.com/shirou/gopsutil/process"
"github.com/simple-rules/harmony-benchmark/log"
)
type profilerSetting struct {
pid int32
shardID string
}
var (
setting profilerSetting
)
func logPerf() {
p, _ := process.NewProcess(setting.pid)
for {
// log mem usage
info, _ := p.MemoryInfo()
memMap, _ := p.MemoryMaps(false)
log.Info("Mem Report", "info", info, "map", memMap, "shardID", setting.shardID)
// log cpu usage
percent, _ := p.CPUPercent()
times, _ := p.Times()
log.Info("CPU Report", "percent", percent, "times", times, "shardID", setting.shardID)
time.Sleep(3 * time.Second)
}
}
func main() {
pid := flag.Int("pid", 0, "process id of the node")
shardID := flag.String("shard_id", "0", "the shard id of this node")
logFolder := flag.String("log_folder", "latest", "the folder collecting the logs of this execution")
flag.Parse()
setting.pid = int32(*pid)
setting.shardID = *shardID
logFileName := fmt.Sprintf("./%v/profiler-%v.log", *logFolder, *shardID)
h := log.MultiHandler(
log.StdoutHandler,
log.Must.FileHandler(logFileName, log.JSONFormat()), // Log to file
// log.Must.NetHandler("tcp", ":3000", log.JSONFormat()) // Log to remote
)
log.Root().SetHandler(h)
logPerf()
}

@ -0,0 +1,48 @@
package profiler
import (
"time"
"github.com/shirou/gopsutil/process"
"github.com/simple-rules/harmony-benchmark/log"
)
type Profiler struct {
logger log.Logger
PID int32
ShardID string
proc *process.Process
}
func NewProfiler(logger log.Logger, pid int, shardID string) *Profiler {
profiler := Profiler{logger, int32(pid), shardID, nil}
return &profiler
}
func (profiler *Profiler) LogMemory() {
for {
// log mem usage
info, _ := profiler.proc.MemoryInfo()
memMap, _ := profiler.proc.MemoryMaps(false)
profiler.logger.Info("Mem Report", "info", info, "map", memMap, "shardID", profiler.ShardID)
time.Sleep(3 * time.Second)
}
}
func (profiler *Profiler) LogCPU() {
for {
// log cpu usage
percent, _ := profiler.proc.CPUPercent()
times, _ := profiler.proc.Times()
profiler.logger.Info("CPU Report", "percent", percent, "times", times, "shardID", profiler.ShardID)
time.Sleep(3 * time.Second)
}
}
func (profiler *Profiler) Start() {
profiler.proc, _ = process.NewProcess(profiler.PID)
go profiler.LogCPU()
go profiler.LogMemory()
}
Loading…
Cancel
Save