forked from NVIDIA/aistore
/
main.go
67 lines (57 loc) · 1.46 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
56
57
58
59
60
61
62
63
64
65
66
67
// Package main for the AIS node executable.
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
package main
import (
"flag"
"os"
"runtime"
"runtime/pprof"
"strconv"
"syscall"
"github.com/artashesbalabekyan/aistore/ais"
"github.com/artashesbalabekyan/aistore/cmn"
"github.com/artashesbalabekyan/aistore/cmn/cos"
)
var (
cpuProfile = flag.String("cpuprofile", "", "write cpu profile to `file`")
memProfile = flag.String("memprofile", "", "write memory profile to `file`")
)
// NOTE: these variables are set by ldflags
var (
build string
buildtime string
)
func main() {
os.Exit(run())
}
func run() int {
flag.Parse()
if s := *cpuProfile; s != "" {
*cpuProfile = s + "." + strconv.Itoa(syscall.Getpid())
f, err := os.Create(*cpuProfile)
if err != nil {
cos.ExitLogf("Couldn't create CPU profile: %v", err)
}
defer f.Close()
if err := pprof.StartCPUProfile(f); err != nil {
cos.ExitLogf("Couldn't start CPU profile: %v", err)
}
defer pprof.StopCPUProfile()
}
exitCode := ais.Run(cmn.VersionAIStore+"."+build, buildtime)
if s := *memProfile; s != "" {
*memProfile = s + "." + strconv.Itoa(syscall.Getpid())
f, err := os.Create(*memProfile)
if err != nil {
cos.ExitLogf("Couldn't create memory profile: %v", err)
}
defer f.Close()
runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
cos.ExitLogf("Couldn't write memory profile: %v", err)
}
}
return exitCode
}