optimize: reduce memory usage by reading kallsyms only in the trace command (#700)

This commit is contained in:
seiuneko 2024-11-18 19:47:35 +08:00 committed by GitHub
parent d3ab0b25e7
commit 53b5fedbc3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 5 deletions

View File

@ -31,6 +31,9 @@ func init() {
traceCmd := &cobra.Command{ traceCmd := &cobra.Command{
Use: "trace", Use: "trace",
Short: "To trace traffic", Short: "To trace traffic",
PreRun: func(cmd *cobra.Command, args []string) {
trace.ReadKallsyms()
},
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
internal.AutoSu() internal.AutoSu()

View File

@ -26,11 +26,7 @@ var kallsyms []Symbol
var kallsymsByName map[string]Symbol = make(map[string]Symbol) var kallsymsByName map[string]Symbol = make(map[string]Symbol)
var kallsymsByAddr map[uint64]Symbol = make(map[uint64]Symbol) var kallsymsByAddr map[uint64]Symbol = make(map[uint64]Symbol)
func init() { func ReadKallsyms() {
readKallsyms()
}
func readKallsyms() {
file, err := os.Open("/proc/kallsyms") file, err := os.Open("/proc/kallsyms")
if err != nil { if err != nil {
logrus.Fatalf("failed to open /proc/kallsyms: %v", err) logrus.Fatalf("failed to open /proc/kallsyms: %v", err)