Skip to content

Commit

Permalink
optimize: reduce memory usage by reading kallsyms only in the trace c…
Browse files Browse the repository at this point in the history
…ommand (#700)
  • Loading branch information
seiuneko authored Nov 18, 2024
1 parent d3ab0b2 commit 53b5fed
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 3 additions & 0 deletions cmd/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func init() {
traceCmd := &cobra.Command{
Use: "trace",
Short: "To trace traffic",
PreRun: func(cmd *cobra.Command, args []string) {
trace.ReadKallsyms()
},
Run: func(cmd *cobra.Command, args []string) {
internal.AutoSu()

Expand Down
6 changes: 1 addition & 5 deletions trace/kallsyms.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ var kallsyms []Symbol
var kallsymsByName map[string]Symbol = make(map[string]Symbol)
var kallsymsByAddr map[uint64]Symbol = make(map[uint64]Symbol)

func init() {
readKallsyms()
}

func readKallsyms() {
func ReadKallsyms() {
file, err := os.Open("/proc/kallsyms")
if err != nil {
logrus.Fatalf("failed to open /proc/kallsyms: %v", err)
Expand Down

0 comments on commit 53b5fed

Please sign in to comment.