1
2
3
4
5 package pgo
6
7 import (
8 "bufio"
9 "fmt"
10 "io"
11 )
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 const serializationHeader = "GO PREPROFILE V1\n"
31
32
33
34
35
36
37 func (d *Profile) WriteTo(w io.Writer) (int64, error) {
38 bw := bufio.NewWriter(w)
39
40 var written int64
41
42
43 n, err := bw.WriteString(serializationHeader)
44 written += int64(n)
45 if err != nil {
46 return written, err
47 }
48
49 for _, edge := range d.NamedEdgeMap.ByWeight {
50 weight := d.NamedEdgeMap.Weight[edge]
51
52 n, err = fmt.Fprintln(bw, edge.CallerName)
53 written += int64(n)
54 if err != nil {
55 return written, err
56 }
57
58 n, err = fmt.Fprintln(bw, edge.CalleeName)
59 written += int64(n)
60 if err != nil {
61 return written, err
62 }
63
64 n, err = fmt.Fprintf(bw, "%d %d\n", edge.CallSiteOffset, weight)
65 written += int64(n)
66 if err != nil {
67 return written, err
68 }
69 }
70
71 if err := bw.Flush(); err != nil {
72 return written, err
73 }
74
75
76
77
78 return written, nil
79 }
80
View as plain text