gc: add events for profiling GC
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Aug 9, 2017 at 23:18 UTC
5e3fd5e7088b0d07fa8a0fa781d7252e971fdf32
1 file changed
+21
pin/gc/gc.go
+21
@@ -9,10 +9,13 @@ import (
9
dag "github.com/ipfs/go-ipfs/merkledag"
10
pin "github.com/ipfs/go-ipfs/pin"
11
12
+ logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
13
cid "gx/ipfs/QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS/go-cid"
14
node "gx/ipfs/QmYNyRZJBUYPNrLszFmrBrPJbsBh2vMsefz5gnDpB5M1P6/go-ipld-format"
15
)
16
17
+var log = logging.Logger("gc")
18
+
19
// Result represents an incremental output from a garbage collection
20
// run. It contains either an error, or the cid of a removed object.
21
type Result struct {
@@ -31,7 +34,13 @@ type Result struct {
34
// deletes any block that is not found in the marked set.
35
//
36
func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.Pinner, bestEffortRoots []*cid.Cid) <-chan Result {
37
+
38
+ elock := log.EventBegin(ctx, "GC.lockWait")
39
unlocker := bs.GCLock()
40
+ elock.Done()
41
+ elock = log.EventBegin(ctx, "GC.locked")
42
+ emark := log.EventBegin(ctx, "GC.mark")
43
+
44
ls = ls.GetOfflineLinkService()
45
46
output := make(chan Result, 128)
@@ -39,12 +48,18 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.
48
go func() {
49
defer close(output)
50
defer unlocker.Unlock()
51
+ defer elock.Done()
52
53
gcs, err := ColoredSet(ctx, pn, ls, bestEffortRoots, output)
54
if err != nil {
55
output <- Result{Error: err}
56
return
57
}
58
+ emark.Append(logging.LoggableMap{
59
+ "blackSetSize": fmt.Sprintf("%d", gcs.Len()),
60
+ })
61
+ emark.Done()
62
+ esweep := log.EventBegin(ctx, "GC.sweep")
63
64
keychan, err := bs.AllKeysChan(ctx)
65
if err != nil {
@@ -53,6 +68,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.
68
}
69
70
errors := false
71
+ var removed uint64
72
73
loop:
74
for {
@@ -63,6 +79,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.
79
}
80
if !gcs.Has(k) {
81
err := bs.DeleteBlock(k)
82
+ removed++
83
if err != nil {
84
errors = true
85
output <- Result{Error: &CannotDeleteBlockError{k, err}}
@@ -80,6 +97,10 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.
97
break loop
98
}
99
}
100
+ esweep.Append(logging.LoggableMap{
101
+ "whiteSetSize": fmt.Sprintf("%d", removed),
102
+ })
103
+ esweep.Done()
104
if errors {
105
output <- Result{Error: ErrCannotDeleteSomeBlocks}
106
}