-
Notifications
You must be signed in to change notification settings - Fork 71
/
main.go
55 lines (45 loc) · 1.21 KB
/
main.go
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
45
46
47
48
49
50
51
52
53
54
55
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package main
import (
"log"
"os"
"runtime/pprof"
"strconv"
"strings"
"github.com/twitchdev/twitch-cli/cmd"
"github.com/twitchdev/twitch-cli/internal/util"
)
var buildVersion string
const (
CPU_PROFILER_BOOL_ENV_VARIABLE = "TWITCH_CLI_ENABLE_CPU_PROFILER"
CPU_PROFILER_FILENAME_ENV_VARIABLE = "TWITCH_CLI_CPU_PROFILER_FILE"
CPU_PROFILER_DEFAULT_FILENAME = "cpu.prof"
)
func main() {
enableCpuProfiler, err := strconv.ParseBool(os.Getenv(CPU_PROFILER_BOOL_ENV_VARIABLE))
if err != nil {
enableCpuProfiler = false
}
// Enable CPU profiler
if enableCpuProfiler {
cpuProfilerFilename := os.Getenv(CPU_PROFILER_FILENAME_ENV_VARIABLE)
if strings.TrimSpace(cpuProfilerFilename) == "" {
cpuProfilerFilename = CPU_PROFILER_DEFAULT_FILENAME
}
f, err := os.Create(cpuProfilerFilename)
if err != nil {
log.Fatal("Could not create CPU profile: ", err)
}
defer f.Close()
err = pprof.StartCPUProfile(f)
if err != nil {
log.Fatal("Could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
}
if len(buildVersion) > 0 {
util.SetVersion(buildVersion)
}
cmd.Execute()
}