Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prehensilecode/1643a9d3307823bdd96a122c9c796b5a to your computer and use it in GitHub Desktop.
Save prehensilecode/1643a9d3307823bdd96a122c9c796b5a to your computer and use it in GitHub Desktop.
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