|
@@ -26,6 +26,7 @@ import (
|
26
|
26
|
"regexp"
|
27
|
27
|
"sort"
|
28
|
28
|
"strings"
|
|
29
|
+ "sync"
|
29
|
30
|
"time"
|
30
|
31
|
)
|
31
|
32
|
|
|
@@ -47,6 +48,10 @@ type Profile struct {
|
47
|
48
|
PeriodType *ValueType
|
48
|
49
|
Period int64
|
49
|
50
|
|
|
51
|
+ // The following fields are modified during encoding and copying,
|
|
52
|
+ // so are protected by a Mutex.
|
|
53
|
+ encodeMu sync.Mutex
|
|
54
|
+
|
50
|
55
|
commentX []int64
|
51
|
56
|
dropFramesX int64
|
52
|
57
|
keepFramesX int64
|
|
@@ -296,21 +301,25 @@ func (p *Profile) updateLocationMapping(from, to *Mapping) {
|
296
|
301
|
}
|
297
|
302
|
}
|
298
|
303
|
|
299
|
|
-// Write writes the profile as a gzip-compressed marshaled protobuf.
|
300
|
|
-func (p *Profile) Write(w io.Writer) error {
|
|
304
|
+func serialize(p *Profile) []byte {
|
|
305
|
+ p.encodeMu.Lock()
|
301
|
306
|
p.preEncode()
|
302
|
307
|
b := marshal(p)
|
|
308
|
+ p.encodeMu.Unlock()
|
|
309
|
+ return b
|
|
310
|
+}
|
|
311
|
+
|
|
312
|
+// Write writes the profile as a gzip-compressed marshaled protobuf.
|
|
313
|
+func (p *Profile) Write(w io.Writer) error {
|
303
|
314
|
zw := gzip.NewWriter(w)
|
304
|
315
|
defer zw.Close()
|
305
|
|
- _, err := zw.Write(b)
|
|
316
|
+ _, err := zw.Write(serialize(p))
|
306
|
317
|
return err
|
307
|
318
|
}
|
308
|
319
|
|
309
|
320
|
// WriteUncompressed writes the profile as a marshaled protobuf.
|
310
|
321
|
func (p *Profile) WriteUncompressed(w io.Writer) error {
|
311
|
|
- p.preEncode()
|
312
|
|
- b := marshal(p)
|
313
|
|
- _, err := w.Write(b)
|
|
322
|
+ _, err := w.Write(serialize(p))
|
314
|
323
|
return err
|
315
|
324
|
}
|
316
|
325
|
|
|
@@ -605,11 +614,8 @@ func (m *Mapping) Unsymbolizable() bool {
|
605
|
614
|
|
606
|
615
|
// Copy makes a fully independent copy of a profile.
|
607
|
616
|
func (p *Profile) Copy() *Profile {
|
608
|
|
- p.preEncode()
|
609
|
|
- b := marshal(p)
|
610
|
|
-
|
611
|
617
|
pp := &Profile{}
|
612
|
|
- if err := unmarshal(b, pp); err != nil {
|
|
618
|
+ if err := unmarshal(serialize(p), pp); err != nil {
|
613
|
619
|
panic(err)
|
614
|
620
|
}
|
615
|
621
|
if err := pp.postDecode(); err != nil {
|