MCPcopy Create free account
hub / github.com/SeeFlowerX/stackplz / persistentPreRunEFunc

Function persistentPreRunEFunc

cli/cmd/root.go:85–367  ·  view source on GitHub ↗

cobra.Command 中几个函数执行的顺序 PersistentPreRun PreRun Run PostRun PersistentPostRun

(command *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

83// PersistentPostRun
84
85func persistentPreRunEFunc(command *cobra.Command, args []string) error {
86 // 在执行子命令的时候 上级命令的 PersistentPreRun/PersistentPreRunE 会先执行
87
88 var err error
89
90 // 首先根据全局设定设置日志输出
91 dir, _ := os.Getwd()
92 log_path := dir + "/" + gconfig.LogFile
93 if gconfig.LogFile != "" {
94 _, err := os.Stat(log_path)
95 if err != nil {
96 if os.IsNotExist(err) {
97 os.Remove(log_path)
98 } else {
99 fmt.Printf("stat %s failed, error:%v", log_path, err)
100 os.Exit(1)
101 }
102 } else {
103 os.Remove(log_path)
104 }
105 }
106
107 // 在 init 之后各个选项的 flag 还没有初始化 到这里才初始化 所以在这里最先设置好 logger
108 logger := NewLogger(log_path)
109 mconfig.SetLogger(logger)
110 if !gconfig.NoCheck {
111 // 先检查必要的配置
112 err = util.CheckKernelConfig()
113 if err != nil {
114 logger.Fatalf("CheckKernelConfig failed, error:%v", err)
115 }
116 }
117 if gconfig.Btf {
118 mconfig.ExternalBTF = ""
119 } else {
120 if !util.HasEnableBTF {
121 // 检查平台 判断是不是开发板
122 gconfig.ExternalBTF = findBTFAssets()
123 mconfig.ExternalBTF = gconfig.ExternalBTF
124 } else {
125 mconfig.ExternalBTF = ""
126 }
127 }
128 // 这个操作有点耗时 内核版本符合要求的用不着检查 先不要这个操作
129 // 检查符号情况 用于判断部分选项是否能启用
130 // has_bpf_probe_read_user, err := findKallsymsSymbol("bpf_probe_read_user")
131 // if err != nil {
132 // logger.Printf("bpf_probe_read_user err:%v", err)
133 // return err
134 // }
135 // if !has_bpf_probe_read_user {
136 // logger.Printf("!!! may not support for this machine, has no bpf_probe_read_user")
137 // }
138
139 // 第一步先释放用于获取堆栈信息的外部库
140 exec_path, err := os.Executable()
141 if err != nil {
142 return fmt.Errorf("please build as executable binary, %v", err)

Callers

nothing calls this directly

Calls 15

SetLoggerMethod · 0.95
SetConfMethod · 0.95
ParseDumpMethod · 0.95
CheckKernelConfigFunction · 0.92
Get_PackageInfosFunction · 0.92
FindLibPathsFunction · 0.92
SaveMapsFunction · 0.92
FindLibInMapsFunction · 0.92
NewEventParserFunction · 0.92
NewLoggerFunction · 0.85
findBTFAssetsFunction · 0.85
addLibPathFunction · 0.85

Tested by

no test coverage detected