@@ -5,93 +5,124 @@ import (
5
5
"fmt"
6
6
"log"
7
7
8
- pprof "github.com/google/pprof/profile "
9
-
8
+ googlev1 "github.com/grafana/pyroscope/api/gen/proto/go/google/v1 "
9
+ queryv1 "github.com/grafana/pyroscope/api/gen/proto/go/query/v1"
10
10
"github.com/grafana/pyroscope/pkg/experiment/symbolizer"
11
11
)
12
12
13
13
const (
14
14
debuginfodBaseURL = "https://debuginfod.elfutils.org"
15
- buildID = "2fa2055ef20fabc972d5751147e093275514b142"
15
+ // buildID = "c047672cae7964324658491e7dee26748ae5d2f8"
16
+ buildID = "2fa2055ef20fabc972d5751147e093275514b142"
16
17
)
17
18
18
19
func main () {
19
- client := symbolizer .NewDebuginfodClient (debuginfodBaseURL , nil )
20
+ client := symbolizer .NewDebuginfodClient (debuginfodBaseURL , symbolizer . NewMetrics ( nil ) )
20
21
21
22
// Alternatively, use a local debug info file:
22
23
//client := &localDebuginfodClient{debugFilePath: "/path/to/your/debug/file"}
23
24
24
- s := symbolizer .NewSymbolizer (client , nil , nil )
25
+ s := symbolizer .NewProfileSymbolizer (client , nil , symbolizer . NewMetrics ( nil ) )
25
26
ctx := context .Background ()
26
27
27
28
_ , err := client .FetchDebuginfo (buildID )
28
29
if err != nil {
29
30
log .Fatalf ("Failed to fetch debug info: %v" , err )
30
31
}
31
- //defer os.Remove(debugFilePath)
32
32
33
- // Create a request to symbolize specific addresses
34
- req := symbolizer.Request {
35
- BuildID : buildID ,
36
- Mappings : []symbolizer.RequestMapping {
33
+ // {
34
+ // Address: 0x1500,
35
+ // Mapping: &pprof.Mapping{},
36
+ // },
37
+ // {
38
+ // Address: 0x3c5a,
39
+ // Mapping: &pprof.Mapping{},
40
+ // },
41
+ // {
42
+ // Address: 0x2745,
43
+ // Mapping: &pprof.Mapping{},
44
+ // },
45
+
46
+ // Create a profile with the address we want to symbolize
47
+ // c047672cae7964324658491e7dee26748ae5d2f8
48
+ // profile := &googlev1.Profile{
49
+ // Mapping: []*googlev1.Mapping{{
50
+ // BuildId: 1,
51
+ // MemoryStart: 0x0,
52
+ // MemoryLimit: 0x1000000,
53
+ // FileOffset: 0x0,
54
+ // }},
55
+ // Location: []*googlev1.Location{{
56
+ // MappingId: 1,
57
+ // Address: 0x11a230,
58
+ // }},
59
+ // StringTable: []string{"", buildID},
60
+ // }
61
+
62
+ profile := & googlev1.Profile {
63
+ Mapping : []* googlev1.Mapping {{
64
+ BuildId : 1 ,
65
+ MemoryStart : 0x0 ,
66
+ MemoryLimit : 0x1000000 ,
67
+ FileOffset : 0x0 ,
68
+ }},
69
+ Location : []* googlev1.Location {
70
+ {
71
+ MappingId : 1 ,
72
+ Address : 0x1500 ,
73
+ },
74
+ {
75
+ MappingId : 1 ,
76
+ Address : 0x3c5a ,
77
+ },
37
78
{
38
- Locations : []* symbolizer.Location {
39
- {
40
- Address : 0x1500 ,
41
- Mapping : & pprof.Mapping {},
42
- },
43
- {
44
- Address : 0x3c5a ,
45
- Mapping : & pprof.Mapping {},
46
- },
47
- {
48
- Address : 0x2745 ,
49
- Mapping : & pprof.Mapping {},
50
- },
51
- },
79
+ MappingId : 1 ,
80
+ Address : 0x2745 ,
52
81
},
53
82
},
83
+ StringTable : []string {"" , buildID },
84
+ }
85
+
86
+ // Marshal profile into tree report
87
+ data , err := profile .MarshalVT ()
88
+ if err != nil {
89
+ log .Fatalf ("Failed to marshal profile: %v" , err )
54
90
}
91
+ report := & queryv1.TreeReport {Tree : data }
55
92
56
- if err := s .Symbolize (ctx , req ); err != nil {
93
+ // Run symbolization
94
+ if err := s .SymbolizeTree (ctx , report ); err != nil {
57
95
log .Fatalf ("Failed to symbolize: %v" , err )
58
96
}
59
97
98
+ // Unmarshal result for printing
99
+ result := & googlev1.Profile {}
100
+ if err := result .UnmarshalVT (report .Tree ); err != nil {
101
+ log .Fatalf ("Failed to unmarshal result: %v" , err )
102
+ }
103
+
104
+ printResults (result )
105
+ }
106
+
107
+ func printResults (p * googlev1.Profile ) {
60
108
fmt .Println ("Symbolization Results:" )
61
- fmt .Printf ("Build ID: %s\n " , buildID )
62
- fmt .Println ("----------------------------------------" )
63
-
64
- for i , mapping := range req .Mappings {
65
- fmt .Printf ("Mapping #%d:\n " , i + 1 )
66
- for _ , loc := range mapping .Locations {
67
- fmt .Printf ("\n Address: 0x%x\n " , loc .Address )
68
- if len (loc .Lines ) == 0 {
69
- fmt .Println (" No symbolization information found" )
70
- continue
71
- }
109
+ for _ , loc := range p .Location {
110
+ fmt .Printf ("\n Address: 0x%x\n " , loc .Address )
111
+ if len (loc .Line ) == 0 {
112
+ fmt .Println (" No symbolization information found" )
113
+ continue
114
+ }
72
115
73
- for j , line := range loc .Lines {
74
- fmt .Printf (" Line %d:\n " , j + 1 )
75
- if line .Function != nil {
76
- fmt .Printf (" Function: %s\n " , line .Function .Name )
77
- fmt .Printf (" File: %s\n " , line .Function .Filename )
78
- fmt .Printf (" Line: %d\n " , line .Line )
79
- fmt .Printf (" StartLine: %d\n " , line .Function .StartLine )
80
- } else {
81
- fmt .Println (" No function information available" )
82
- }
116
+ for i , line := range loc .Line {
117
+ fmt .Printf (" Line %d:\n " , i + 1 )
118
+ if fn := p .Function [line .FunctionId ]; fn != nil {
119
+ fmt .Printf (" Function: %s\n " , p .StringTable [fn .Name ])
120
+ fmt .Printf (" File: %s\n " , p .StringTable [fn .Filename ])
121
+ fmt .Printf (" Line: %d\n " , line .Line )
122
+ fmt .Printf (" StartLine: %d\n " , fn .StartLine )
83
123
}
84
- fmt .Println ("----------------------------------------" )
85
124
}
86
125
}
87
-
88
- // Alternatively: Symbolize all addresses in the binary
89
- // Note: Comment out the above specific symbolization when using this
90
- // as it's a different approach meant for exploring all available symbols
91
- //if err := symbolizer.SymbolizeAll(ctx, buildID); err != nil {
92
- // log.Fatalf("Failed to symbolize all addresses: %v", err)
93
- //}
94
-
95
126
fmt .Println ("\n Symbolization completed successfully." )
96
127
}
97
128
0 commit comments