Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
package main
import (
"flag"
"fmt"
"github.com/chrislusf/glow/flow"
"github.com/dgruber/ugego/pkg/accounting"
"os"
"strings"
)
func main() {
flag.Parse()
accountingFileName := fmt.Sprintf("%s/%s/common/accounting", os.Getenv("SGE_ROOT"), os.Getenv("SGE_CELL"))
flow.New().TextFile(
accountingFileName, 4,
).Filter(func(line string) bool {
return !strings.HasPrefix(line, "#")
}).Map(func(line string, ch chan accounting.Entry) {
if e, err := accounting.ParseLine([]byte(line)); err == nil {
ch <- e
}
}).Reduce(func(x accounting.Entry, y accounting.Entry) accounting.Entry {
y.CPU += x.CPU
return y
}).Map(func(out accounting.Entry) {
fmt.Println("Combined CPU times of all jobs.")
fmt.Printf("%f\n", out.CPU)
}).Run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment