Skip to content

Commit 848fd1e

Browse files
Merge pull request #9 from threadedstream/account_for_labels
Account for labels
2 parents 54b2ee1 + 8f6b73c commit 848fd1e

File tree

13 files changed

+1142
-645
lines changed

13 files changed

+1142
-645
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor/
2+
.idea/
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
syntax = "proto3";
22

3-
package dummymergedprofile;
3+
package ppmerge;
44

5-
import "profile.proto";
5+
import "api/profile.proto";
66

77
option go_package = "github.com/threadedstream/ppmerge";
88

@@ -36,6 +36,7 @@ message MergedProfile {
3636
repeated uint64 num_sample_types = 13;
3737
repeated uint64 num_mappings = 14;
3838
repeated uint64 num_samples = 15;
39+
map<uint64, Labels> labels = 16;
3940
}
4041

4142
// ValueType describes the semantics and measurement units of a value.

profile.proto renamed to api/profile.proto

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
syntax = "proto3";
22

3-
package dummymergedprofile;
4-
5-
6-
option go_package = "github.com/threadedstream/ppmerge";
3+
package ppmerge;
74

5+
option go_package = "github.com/threadedstream/ppmerge/profile";
86

97
message GoroutineProfile {
108
uint64 total = 1;
@@ -117,6 +115,11 @@ message Label {
117115
int64 num_unit = 4; // Index into string table
118116
}
119117

118+
message Labels {
119+
repeated Label labels = 1;
120+
}
121+
122+
120123
message Mapping {
121124
// Unique nonzero id for the mapping.
122125
uint64 id = 1;

goroutine_merger.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"compress/gzip"
66
"io"
77

8+
"github.com/threadedstream/ppmerge/profile"
89
"google.golang.org/protobuf/proto"
910
)
1011

@@ -35,7 +36,7 @@ func (gpm *GoroutineProfileMerger) WriteCompressed(w io.Writer) error {
3536
return err
3637
}
3738

38-
func (gpm *GoroutineProfileMerger) Merge(gps ...*GoroutineProfile) *MergedGoroutineProfile {
39+
func (gpm *GoroutineProfileMerger) Merge(gps ...*profile.GoroutineProfile) *MergedGoroutineProfile {
3940
gpm.mergedProfile.Totals = make([]uint64, 0, len(gps))
4041
gpm.mergedProfile.NumStacktraces = make([]uint64, 0, len(gps))
4142

@@ -45,16 +46,16 @@ func (gpm *GoroutineProfileMerger) Merge(gps ...*GoroutineProfile) *MergedGorout
4546
return gpm.mergedProfile
4647
}
4748

48-
func (gpm *GoroutineProfileMerger) merge(gps ...*GoroutineProfile) {
49-
var resultStacktraces []*Stacktrace
49+
func (gpm *GoroutineProfileMerger) merge(gps ...*profile.GoroutineProfile) {
50+
var resultStacktraces []*profile.Stacktrace
5051
for _, gp := range gps {
5152
gpm.mergedProfile.Totals = append(gpm.mergedProfile.Totals, gp.Total)
5253
stacktraces := gp.GetStacktraces()
5354

5455
gpm.mergedProfile.NumStacktraces = append(gpm.mergedProfile.NumStacktraces, uint64(len(stacktraces)))
5556

5657
for _, st := range stacktraces {
57-
resultStacktrace := new(Stacktrace)
58+
resultStacktrace := new(profile.Stacktrace)
5859
resultStacktrace.Total = st.Total
5960

6061
resultStacktrace.PC = make([]uint64, len(st.PC))
@@ -65,7 +66,7 @@ func (gpm *GoroutineProfileMerger) merge(gps ...*GoroutineProfile) {
6566
resultStacktraces = append(resultStacktraces, resultStacktrace)
6667
continue
6768
}
68-
resultStacktrace.Frames = make([]*Frame, 0, len(frames))
69+
resultStacktrace.Frames = make([]*profile.Frame, 0, len(frames))
6970
for _, f := range frames {
7071
resultStacktrace.Frames = append(resultStacktrace.Frames, gpm.remapFrame(f, gp.StringTable))
7172
}
@@ -76,8 +77,8 @@ func (gpm *GoroutineProfileMerger) merge(gps ...*GoroutineProfile) {
7677
gpm.mergedProfile.Stacktraces = resultStacktraces
7778
}
7879

79-
func (gpm *GoroutineProfileMerger) remapFrame(frame *Frame, gpStringTable []string) *Frame {
80-
return &Frame{
80+
func (gpm *GoroutineProfileMerger) remapFrame(frame *profile.Frame, gpStringTable []string) *profile.Frame {
81+
return &profile.Frame{
8182
Address: frame.Address,
8283
FunctionName: gpm.putString(gpStringTable[frame.FunctionName]),
8384
Offset: frame.Offset,
@@ -116,7 +117,7 @@ func NewGoroutineProfileUnPacker(mergedProfile *MergedGoroutineProfile) *Gorouti
116117
}
117118
}
118119

119-
func (gpu *GoroutineProfileUnPacker) UnpackRaw(compressedRawProfile []byte, idx uint64) (*GoroutineProfile, error) {
120+
func (gpu *GoroutineProfileUnPacker) UnpackRaw(compressedRawProfile []byte, idx uint64) (*profile.GoroutineProfile, error) {
120121
bb := bytes.NewBuffer(compressedRawProfile)
121122

122123
gzReader, err := gzip.NewReader(bb)
@@ -140,11 +141,11 @@ func (gpu *GoroutineProfileUnPacker) UnpackRaw(compressedRawProfile []byte, idx
140141
return gpu.Unpack(idx)
141142
}
142143

143-
func (gpu *GoroutineProfileUnPacker) Unpack(idx uint64) (*GoroutineProfile, error) {
144+
func (gpu *GoroutineProfileUnPacker) Unpack(idx uint64) (*profile.GoroutineProfile, error) {
144145
if idx >= uint64(len(gpu.mergedProfile.NumStacktraces)) {
145146
return nil, indexOutOfRangeErr
146147
}
147-
gp := GoroutineProfileFromVTPool()
148+
gp := profile.GoroutineProfileFromVTPool()
148149

149150
gp.Total = gpu.mergedProfile.Totals[idx]
150151

@@ -157,7 +158,7 @@ func (gpu *GoroutineProfileUnPacker) Unpack(idx uint64) (*GoroutineProfile, erro
157158

158159
limit := offset + numStacktraces
159160

160-
gp.Stacktraces = make([]*Stacktrace, 0, numStacktraces)
161+
gp.Stacktraces = make([]*profile.Stacktrace, 0, numStacktraces)
161162
for offset < limit {
162163
gp.Stacktraces = append(gp.Stacktraces, gpu.remapStacktrace(gpu.mergedProfile.Stacktraces[offset]))
163164
offset++
@@ -168,8 +169,8 @@ func (gpu *GoroutineProfileUnPacker) Unpack(idx uint64) (*GoroutineProfile, erro
168169
return gp, nil
169170
}
170171

171-
func (gpu *GoroutineProfileUnPacker) remapStacktrace(st *Stacktrace) *Stacktrace {
172-
resultStacktrace := new(Stacktrace)
172+
func (gpu *GoroutineProfileUnPacker) remapStacktrace(st *profile.Stacktrace) *profile.Stacktrace {
173+
resultStacktrace := new(profile.Stacktrace)
173174
resultStacktrace.Total = st.Total
174175

175176
resultStacktrace.PC = make([]uint64, len(st.PC))
@@ -180,16 +181,16 @@ func (gpu *GoroutineProfileUnPacker) remapStacktrace(st *Stacktrace) *Stacktrace
180181
return resultStacktrace
181182
}
182183

183-
resultStacktrace.Frames = make([]*Frame, 0, len(st.Frames))
184+
resultStacktrace.Frames = make([]*profile.Frame, 0, len(st.Frames))
184185
for _, f := range frames {
185186
resultStacktrace.Frames = append(resultStacktrace.Frames, gpu.remapFrame(f))
186187
}
187188

188189
return resultStacktrace
189190
}
190191

191-
func (gpu *GoroutineProfileUnPacker) remapFrame(frame *Frame) *Frame {
192-
return &Frame{
192+
func (gpu *GoroutineProfileUnPacker) remapFrame(frame *profile.Frame) *profile.Frame {
193+
return &profile.Frame{
193194
Address: frame.Address,
194195
FunctionName: gpu.putString(gpu.mergedProfile.StringTable[frame.FunctionName]),
195196
Offset: frame.Offset,
@@ -198,7 +199,7 @@ func (gpu *GoroutineProfileUnPacker) remapFrame(frame *Frame) *Frame {
198199
}
199200
}
200201

201-
func (gpu *GoroutineProfileUnPacker) finalizeStringTable(gp *GoroutineProfile) {
202+
func (gpu *GoroutineProfileUnPacker) finalizeStringTable(gp *profile.GoroutineProfile) {
202203
gp.StringTable = make([]string, len(gpu.stringTable))
203204
for k, v := range gpu.stringTable {
204205
gp.StringTable[v] = k

0 commit comments

Comments
 (0)