summaryrefslogtreecommitdiffstats
path: root/client/go/script-utils/startcbinary/startcbinary.go
blob: 7a2b13ebf8782f174e9d9d2f0f6e4851f5093bee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Author: arnej

package startcbinary

import (
	"fmt"
	"os"
)

func startCbinary(spec *ProgSpec) int {
	spec.configureCommonEnv()
	spec.configurePath()
	spec.configureTuning()
	spec.configureValgrind()
	spec.configureNumaCtl()
	spec.configureHugePages()
	spec.configureUseMadvise()
	spec.configureVespaMalloc()
	err := spec.run()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return 1
	} else {
		return 0
	}
}

func (spec *ProgSpec) run() error {
	prog := spec.Program
	args := spec.Args
	if spec.shouldUseValgrind {
		args = spec.prependValgrind(args)
		prog = spec.valgrindBinary()
	} else if spec.shouldUseNumaCtl {
		args = spec.prependNumaCtl(args)
		prog = spec.numaCtlBinary()
	}
	if spec.shouldUseVespaMalloc {
		spec.setenv(ENV_LD_PRELOAD, spec.vespaMallocPreload)
	}
	envv := spec.effectiveEnv()
	return myexecvp(prog, args, envv)
}