Browse Source

improved barak with logging into ~/.barak/outputs

pull/55/head
Jae Kwon 10 years ago
parent
commit
59e69434e1
4 changed files with 28 additions and 22 deletions
  1. +13
    -1
      cmd/barak/main.go
  2. +10
    -0
      common/os.go
  3. +5
    -12
      process/process.go
  4. +0
    -9
      state/validator_set.go

+ 13
- 1
cmd/barak/main.go View File

@ -14,6 +14,7 @@ import (
"os"
"reflect"
"sync"
"time"
"github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/cmd/barak/types"
@ -41,12 +42,14 @@ var barak = struct {
nonce uint64
processes map[string]*pcm.Process
validators []Validator
rootDir string
}{
mtx: sync.Mutex{},
pid: os.Getpid(),
nonce: 0,
processes: make(map[string]*pcm.Process),
validators: nil,
rootDir: "",
}
func main() {
@ -72,6 +75,10 @@ func main() {
}
barak.nonce = options.StartNonce
barak.validators = options.Validators
barak.rootDir = os.Getenv("BRKROOT")
if barak.rootDir == "" {
barak.rootDir = os.Getenv("HOME") + "/.barak"
}
// Debug.
fmt.Printf("Options: %v\n", options)
@ -174,7 +181,12 @@ func RunProcess(wait bool, label string, execPath string, args []string, input s
}
// Otherwise, create one.
proc, err := pcm.Create(pcm.ProcessModeDaemon, label, execPath, args, input)
err := EnsureDir(barak.rootDir + "/outputs")
if err != nil {
return nil, fmt.Errorf("Failed to create outputs dir: %v", err)
}
outPath := Fmt("%v/outputs/%v_%v.out", barak.rootDir, label, time.Now().Format("2006_01_02_15_04_05_MST"))
proc, err := pcm.Create(pcm.ProcessModeDaemon, label, execPath, args, input, outPath)
if err == nil {
barak.processes[label] = proc
}


+ 10
- 0
common/os.go View File

@ -50,3 +50,13 @@ func AtomicWriteFile(filePath string, newBytes []byte) error {
}
return nil
}
func EnsureDir(dir string) error {
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.MkdirAll(dir, 0700)
if err != nil {
return fmt.Errorf("Could not create directory %v. %v", dir, err)
}
}
return nil
}

+ 5
- 12
process/process.go View File

@ -10,16 +10,6 @@ import (
"time"
)
func makeFile(prefix string) (string, *os.File) {
now := time.Now()
path := fmt.Sprintf("%v_%v.out", prefix, now.Format("2006_01_02_15_04_05_MST"))
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
panic(err)
}
return path, file
}
type Process struct {
Label string
ExecPath string
@ -40,8 +30,11 @@ const (
// execPath: command name
// args: args to command. (should not include name)
func Create(mode int, label string, execPath string, args []string, input string) (*Process, error) {
outPath, outFile := makeFile("output_" + label)
func Create(mode int, label string, execPath string, args []string, input string, outPath string) (*Process, error) {
outFile, err := os.OpenFile(outPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
return nil, err
}
cmd := exec.Command(execPath, args...)
switch mode {
case ProcessModeStd:


+ 0
- 9
state/validator_set.go View File

@ -45,10 +45,6 @@ func NewValidatorSet(vals []*Validator) *ValidatorSet {
// TODO: mind the overflow when times and votingPower shares too large.
func (valSet *ValidatorSet) IncrementAccum(times uint) {
log.Debug("IncrementAccum", "times", times)
log.Debug(Fmt("IncrementAccum prior to accum: %v\n", valSet))
// Add VotingPower * times to each validator and order into heap.
validatorsHeap := NewHeap()
for _, val := range valSet.Validators {
@ -56,8 +52,6 @@ func (valSet *ValidatorSet) IncrementAccum(times uint) {
validatorsHeap.Push(val, accumComparable(val.Accum))
}
log.Debug(Fmt("IncrementAccum after accum: %v\n", valSet))
// Decrement the validator with most accum, times times.
for i := uint(0); i < times; i++ {
mostest := validatorsHeap.Peek().(*Validator)
@ -67,9 +61,6 @@ func (valSet *ValidatorSet) IncrementAccum(times uint) {
mostest.Accum -= int64(valSet.TotalVotingPower())
validatorsHeap.Update(mostest, accumComparable(mostest.Accum))
}
log.Debug(Fmt("IncrementAccum after decrements: %v\n", valSet))
log.Debug(Fmt("IncrementAccum chose proposer: %v\n", valSet.proposer))
}
func (valSet *ValidatorSet) Copy() *ValidatorSet {


Loading…
Cancel
Save