GoPLS Viewer

Home|gopls/internal/event/export/metric/exporter.go
1// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Package metric aggregates events into metrics that can be exported.
6package metric
7
8import (
9    "context"
10    "sync"
11    "time"
12
13    "golang.org/x/tools/internal/event"
14    "golang.org/x/tools/internal/event/core"
15    "golang.org/x/tools/internal/event/keys"
16    "golang.org/x/tools/internal/event/label"
17)
18
19var Entries = keys.New("metric_entries""The set of metrics calculated for an event")
20
21type Config struct {
22    subscribers map[interface{}][]subscriber
23}
24
25type subscriber func(time.Timelabel.Maplabel.LabelData
26
27func (e *Configsubscribe(key label.Keys subscriber) {
28    if e.subscribers == nil {
29        e.subscribers = make(map[interface{}][]subscriber)
30    }
31    e.subscribers[key] = append(e.subscribers[key], s)
32}
33
34func (e *ConfigExporter(output event.Exporterevent.Exporter {
35    var mu sync.Mutex
36    return func(ctx context.Contextev core.Eventlm label.Mapcontext.Context {
37        if !event.IsMetric(ev) {
38            return output(ctxevlm)
39        }
40        mu.Lock()
41        defer mu.Unlock()
42        var metrics []Data
43        for index := 0ev.Valid(index); index++ {
44            l := ev.Label(index)
45            if !l.Valid() {
46                continue
47            }
48            id := l.Key()
49            if list := e.subscribers[id]; len(list) > 0 {
50                for _s := range list {
51                    metrics = append(metricss(ev.At(), lml))
52                }
53            }
54        }
55        lm = label.MergeMaps(label.NewMap(Entries.Of(metrics)), lm)
56        return output(ctxevlm)
57    }
58}
59
MembersX
Config.Exporter.output
Config.Exporter.BlockStmt.BlockStmt.l
sync
Config.subscribe.s
Config.Exporter
Config
Config.subscribe
Config.subscribers
subscriber
Config.subscribe.e
Config.Exporter.mu
Config.Exporter.BlockStmt.index
context
event
core
Config.Exporter.BlockStmt.BlockStmt.id
Config.Exporter.BlockStmt.BlockStmt.BlockStmt.RangeStmt_1320.s
Config.subscribe.key
Config.Exporter.e
Config.Exporter.BlockStmt.metrics
Members
X