From ddec4adf57dee208cc420c9c5f3a5502361cb774 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Fri, 16 Aug 2019 07:02:51 +0000 Subject: [PATCH] Command line flag for changing number of threads --- main.go | 7 ++++++- pew.go | 9 ++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 5239188..5b5c85f 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,9 @@ import ( "os" "os/exec" "os/user" + "runtime" "sort" + "strconv" "time" kingpin "gopkg.in/alecthomas/kingpin.v2" @@ -130,6 +132,9 @@ func main() { pewDistFlag := pewCommand.Flag("dist", "Build result path") pewDist := pewDistFlag.Default(PATH_DEV_NULL).String() + pewThreadsFlag := pewCommand.Flag("threads", "Build result path") + pewThreads := pewThreadsFlag.Default(strconv.Itoa(runtime.NumCPU())).Int() + kernelCommand := app.Command("kernel", "Manipulate kernels") kernelUseHost := kernelCommand.Flag("host", "Use also host kernels").Bool() kernelListCommand := kernelCommand.Command("list", "List kernels") @@ -240,7 +245,7 @@ func main() { case pewCommand.FullCommand(): err = pewHandler(kcfg, *path, *pewKernel, *pewBinary, *pewTest, *pewGuess, *qemuTimeout, *dockerTimeout, - *pewMax, *pewDist, db) + *pewMax, *pewDist, *pewThreads, db) case kernelListCommand.FullCommand(): err = kernelListHandler(kcfg) case kernelAutogenCommand.FullCommand(): diff --git a/pew.go b/pew.go index 924ebf9..41d5169 100644 --- a/pew.go +++ b/pew.go @@ -15,7 +15,6 @@ import ( "os" "os/exec" "os/user" - "runtime" "strings" "time" @@ -373,11 +372,11 @@ func shuffleKernels(a []config.KernelInfo) []config.KernelInfo { func performCI(ka config.Artifact, kcfg config.KernelConfig, binaryPath, testPath string, qemuTimeout, dockerTimeout time.Duration, - max int64, dist string, db *sql.DB) (err error) { + max int64, dist string, threads int, db *sql.DB) (err error) { found := false - swg := sizedwaitgroup.New(runtime.NumCPU()) + swg := sizedwaitgroup.New(threads) for _, kernel := range shuffleKernels(kcfg.Kernels) { if max <= 0 { break @@ -448,7 +447,7 @@ func genAllKernels() (sk []config.KernelMask, err error) { func pewHandler(kcfg config.KernelConfig, workPath, ovrrdKrnl, binary, test string, guess bool, qemuTimeout, dockerTimeout time.Duration, - max int64, dist string, db *sql.DB) (err error) { + max int64, dist string, threads int, db *sql.DB) (err error) { ka, err := config.ReadArtifactConfig(workPath + "/.out-of-tree.toml") if err != nil { @@ -477,7 +476,7 @@ func pewHandler(kcfg config.KernelConfig, } err = performCI(ka, kcfg, binary, test, qemuTimeout, dockerTimeout, - max, dist, db) + max, dist, threads, db) if err != nil { return }