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" "fmt"
"math/rand" "math/rand"
"os" "os"
"strconv"
"time" "time"
"github.com/simple-rules/harmony-benchmark/attack" "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/db"
"github.com/simple-rules/harmony-benchmark/log" "github.com/simple-rules/harmony-benchmark/log"
"github.com/simple-rules/harmony-benchmark/node" "github.com/simple-rules/harmony-benchmark/node"
"github.com/simple-rules/harmony-benchmark/profiler"
"github.com/simple-rules/harmony-benchmark/utils" "github.com/simple-rules/harmony-benchmark/utils"
) )
@ -32,13 +32,6 @@ func attackDetermination(attackedMode int) bool {
return false 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) { func InitLDBDatabase(ip string, port string) (*db.LDBDatabase, error) {
// TODO(minhdoan): Refactor this. // TODO(minhdoan): Refactor this.
dbFileName := "/tmp/harmony_" + ip + port + ".dat" 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") 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") 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") 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() flag.Parse()
// Set up randomization seed. // Set up randomization seed.
@ -95,9 +89,10 @@ func main() {
// Consensus object. // Consensus object.
consensus := consensus.NewConsensus(*ip, *port, shardID, peers, leader) consensus := consensus.NewConsensus(*ip, *port, shardID, peers, leader)
// Start Profiler for leader // Start Profiler for leader if profile argument is on
if role == "leader" { if *profile && role == "leader" {
startProfiler(shardID, *logFolder) profiler := profiler.NewProfiler(consensus.Log, os.Getpid(), shardID)
profiler.Start()
} }
// Set logger to attack model. // 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. # Also it's recommended to use `go build` for testing the whole exe.
go build -o bin/benchmark go build -o bin/benchmark
go build -o bin/txgen client/txgen/main.go 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 # Create a tmp folder for logs
t=`date +"%Y%m%d-%H%M%S"` t=`date +"%Y%m%d-%H%M%S"`
@ -52,9 +50,9 @@ while IFS='' read -r line || [[ -n "$line" ]]; do
#echo $ip $port $mode #echo $ip $port $mode
if [ "$mode" != "client" ]; then if [ "$mode" != "client" ]; then
if [ -z "$db_supported" ]; 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 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
fi fi
done < $config done < $config
@ -62,5 +60,5 @@ done < $config
txgen_disabled=$3 txgen_disabled=$3
# Generate transactions # Generate transactions
if [ -z "$txgen_disabled" ]; then if [ -z "$txgen_disabled" ]; then
./txgen -config_file $config -log_folder $log_folder ./bin/txgen -config_file $config -log_folder $log_folder
fi 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