id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
12,400
sabhiram/go-gitignore
ignore.go
CompileIgnoreLines
func CompileIgnoreLines(lines ...string) (*GitIgnore, error) { gi := &GitIgnore{} for _, line := range lines { pattern, negatePattern := getPatternFromLine(line) if pattern != nil { ip := &ignorePattern{pattern, negatePattern} gi.patterns = append(gi.patterns, ip) } } return gi, nil }
go
func CompileIgnoreLines(lines ...string) (*GitIgnore, error) { gi := &GitIgnore{} for _, line := range lines { pattern, negatePattern := getPatternFromLine(line) if pattern != nil { ip := &ignorePattern{pattern, negatePattern} gi.patterns = append(gi.patterns, ip) } } return gi, nil }
[ "func", "CompileIgnoreLines", "(", "lines", "...", "string", ")", "(", "*", "GitIgnore", ",", "error", ")", "{", "gi", ":=", "&", "GitIgnore", "{", "}", "\n", "for", "_", ",", "line", ":=", "range", "lines", "{", "pattern", ",", "negatePattern", ":=", "getPatternFromLine", "(", "line", ")", "\n", "if", "pattern", "!=", "nil", "{", "ip", ":=", "&", "ignorePattern", "{", "pattern", ",", "negatePattern", "}", "\n", "gi", ".", "patterns", "=", "append", "(", "gi", ".", "patterns", ",", "ip", ")", "\n", "}", "\n", "}", "\n", "return", "gi", ",", "nil", "\n", "}" ]
// Accepts a variadic set of strings, and returns a GitIgnore object which // converts and appends the lines in the input to regexp.Regexp patterns // held within the GitIgnore objects "patterns" field
[ "Accepts", "a", "variadic", "set", "of", "strings", "and", "returns", "a", "GitIgnore", "object", "which", "converts", "and", "appends", "the", "lines", "in", "the", "input", "to", "regexp", ".", "Regexp", "patterns", "held", "within", "the", "GitIgnore", "objects", "patterns", "field" ]
d3107576ba9425fc1c85f4b3569c4631b805a02e
https://github.com/sabhiram/go-gitignore/blob/d3107576ba9425fc1c85f4b3569c4631b805a02e/ignore.go#L166-L176
12,401
sabhiram/go-gitignore
ignore.go
CompileIgnoreFile
func CompileIgnoreFile(fpath string) (*GitIgnore, error) { buffer, error := ioutil.ReadFile(fpath) if error == nil { s := strings.Split(string(buffer), "\n") return CompileIgnoreLines(s...) } return nil, error }
go
func CompileIgnoreFile(fpath string) (*GitIgnore, error) { buffer, error := ioutil.ReadFile(fpath) if error == nil { s := strings.Split(string(buffer), "\n") return CompileIgnoreLines(s...) } return nil, error }
[ "func", "CompileIgnoreFile", "(", "fpath", "string", ")", "(", "*", "GitIgnore", ",", "error", ")", "{", "buffer", ",", "error", ":=", "ioutil", ".", "ReadFile", "(", "fpath", ")", "\n", "if", "error", "==", "nil", "{", "s", ":=", "strings", ".", "Split", "(", "string", "(", "buffer", ")", ",", "\"", "\\n", "\"", ")", "\n", "return", "CompileIgnoreLines", "(", "s", "...", ")", "\n", "}", "\n", "return", "nil", ",", "error", "\n", "}" ]
// Accepts a ignore file as the input, parses the lines out of the file // and invokes the CompileIgnoreLines method
[ "Accepts", "a", "ignore", "file", "as", "the", "input", "parses", "the", "lines", "out", "of", "the", "file", "and", "invokes", "the", "CompileIgnoreLines", "method" ]
d3107576ba9425fc1c85f4b3569c4631b805a02e
https://github.com/sabhiram/go-gitignore/blob/d3107576ba9425fc1c85f4b3569c4631b805a02e/ignore.go#L180-L187
12,402
sabhiram/go-gitignore
ignore.go
CompileIgnoreFileAndLines
func CompileIgnoreFileAndLines(fpath string, lines ...string) (*GitIgnore, error) { buffer, error := ioutil.ReadFile(fpath) if error == nil { s := strings.Split(string(buffer), "\n") return CompileIgnoreLines(append(s, lines...)...) } return nil, error }
go
func CompileIgnoreFileAndLines(fpath string, lines ...string) (*GitIgnore, error) { buffer, error := ioutil.ReadFile(fpath) if error == nil { s := strings.Split(string(buffer), "\n") return CompileIgnoreLines(append(s, lines...)...) } return nil, error }
[ "func", "CompileIgnoreFileAndLines", "(", "fpath", "string", ",", "lines", "...", "string", ")", "(", "*", "GitIgnore", ",", "error", ")", "{", "buffer", ",", "error", ":=", "ioutil", ".", "ReadFile", "(", "fpath", ")", "\n", "if", "error", "==", "nil", "{", "s", ":=", "strings", ".", "Split", "(", "string", "(", "buffer", ")", ",", "\"", "\\n", "\"", ")", "\n", "return", "CompileIgnoreLines", "(", "append", "(", "s", ",", "lines", "...", ")", "...", ")", "\n", "}", "\n", "return", "nil", ",", "error", "\n", "}" ]
// Accepts a ignore file as the input, parses the lines out of the file // and invokes the CompileIgnoreLines method with additional lines
[ "Accepts", "a", "ignore", "file", "as", "the", "input", "parses", "the", "lines", "out", "of", "the", "file", "and", "invokes", "the", "CompileIgnoreLines", "method", "with", "additional", "lines" ]
d3107576ba9425fc1c85f4b3569c4631b805a02e
https://github.com/sabhiram/go-gitignore/blob/d3107576ba9425fc1c85f4b3569c4631b805a02e/ignore.go#L191-L198
12,403
mschoch/smat
examples/bolt/boltsmat.go
Fuzz
func Fuzz(data []byte) int { return smat.Fuzz(&context{}, setup, teardown, actionMap, data) }
go
func Fuzz(data []byte) int { return smat.Fuzz(&context{}, setup, teardown, actionMap, data) }
[ "func", "Fuzz", "(", "data", "[", "]", "byte", ")", "int", "{", "return", "smat", ".", "Fuzz", "(", "&", "context", "{", "}", ",", "setup", ",", "teardown", ",", "actionMap", ",", "data", ")", "\n", "}" ]
// Fuzz using state machine driven by byte stream
[ "Fuzz", "using", "state", "machine", "driven", "by", "byte", "stream" ]
90eadee771aeab36e8bf796039b8c261bebebe4f
https://github.com/mschoch/smat/blob/90eadee771aeab36e8bf796039b8c261bebebe4f/examples/bolt/boltsmat.go#L26-L28
12,404
mschoch/smat
smat.go
Fuzz
func Fuzz(ctx Context, setup, teardown ActionID, actionMap ActionMap, data []byte) int { reader := bytes.NewReader(data) err := runReader(ctx, setup, teardown, actionMap, reader, nil) if err != nil { panic(err) } return 1 }
go
func Fuzz(ctx Context, setup, teardown ActionID, actionMap ActionMap, data []byte) int { reader := bytes.NewReader(data) err := runReader(ctx, setup, teardown, actionMap, reader, nil) if err != nil { panic(err) } return 1 }
[ "func", "Fuzz", "(", "ctx", "Context", ",", "setup", ",", "teardown", "ActionID", ",", "actionMap", "ActionMap", ",", "data", "[", "]", "byte", ")", "int", "{", "reader", ":=", "bytes", ".", "NewReader", "(", "data", ")", "\n", "err", ":=", "runReader", "(", "ctx", ",", "setup", ",", "teardown", ",", "actionMap", ",", "reader", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "1", "\n", "}" ]
// Fuzz runs the fuzzing state machine with the provided context // first, the setup action is executed unconditionally // the start state is determined by this action // actionMap is a lookup table for all actions // the data byte slice determines all future state transitions // finally, the teardown action is executed unconditionally for cleanup
[ "Fuzz", "runs", "the", "fuzzing", "state", "machine", "with", "the", "provided", "context", "first", "the", "setup", "action", "is", "executed", "unconditionally", "the", "start", "state", "is", "determined", "by", "this", "action", "actionMap", "is", "a", "lookup", "table", "for", "all", "actions", "the", "data", "byte", "slice", "determines", "all", "future", "state", "transitions", "finally", "the", "teardown", "action", "is", "executed", "unconditionally", "for", "cleanup" ]
90eadee771aeab36e8bf796039b8c261bebebe4f
https://github.com/mschoch/smat/blob/90eadee771aeab36e8bf796039b8c261bebebe4f/smat.go#L76-L83
12,405
mschoch/smat
smat.go
Longevity
func Longevity(ctx Context, setup, teardown ActionID, actionMap ActionMap, seed int64, closeChan chan struct{}) error { source := rand.NewSource(seed) return runReader(ctx, setup, teardown, actionMap, rand.New(source), closeChan) }
go
func Longevity(ctx Context, setup, teardown ActionID, actionMap ActionMap, seed int64, closeChan chan struct{}) error { source := rand.NewSource(seed) return runReader(ctx, setup, teardown, actionMap, rand.New(source), closeChan) }
[ "func", "Longevity", "(", "ctx", "Context", ",", "setup", ",", "teardown", "ActionID", ",", "actionMap", "ActionMap", ",", "seed", "int64", ",", "closeChan", "chan", "struct", "{", "}", ")", "error", "{", "source", ":=", "rand", ".", "NewSource", "(", "seed", ")", "\n", "return", "runReader", "(", "ctx", ",", "setup", ",", "teardown", ",", "actionMap", ",", "rand", ".", "New", "(", "source", ")", ",", "closeChan", ")", "\n", "}" ]
// Longevity runs the state machine with the provided context // first, the setup action is executed unconditionally // the start state is determined by this action // actionMap is a lookup table for all actions // random bytes are generated to determine all future state transitions // finally, the teardown action is executed unconditionally for cleanup
[ "Longevity", "runs", "the", "state", "machine", "with", "the", "provided", "context", "first", "the", "setup", "action", "is", "executed", "unconditionally", "the", "start", "state", "is", "determined", "by", "this", "action", "actionMap", "is", "a", "lookup", "table", "for", "all", "actions", "random", "bytes", "are", "generated", "to", "determine", "all", "future", "state", "transitions", "finally", "the", "teardown", "action", "is", "executed", "unconditionally", "for", "cleanup" ]
90eadee771aeab36e8bf796039b8c261bebebe4f
https://github.com/mschoch/smat/blob/90eadee771aeab36e8bf796039b8c261bebebe4f/smat.go#L91-L94
12,406
mschoch/smat
smat.go
PercentExecute
func PercentExecute(next byte, pas ...PercentAction) ActionID { percent := int(99 * int(next) / 255) sofar := 0 for _, pa := range pas { sofar = sofar + pa.Percent if percent < sofar { return pa.Action } } return NopAction }
go
func PercentExecute(next byte, pas ...PercentAction) ActionID { percent := int(99 * int(next) / 255) sofar := 0 for _, pa := range pas { sofar = sofar + pa.Percent if percent < sofar { return pa.Action } } return NopAction }
[ "func", "PercentExecute", "(", "next", "byte", ",", "pas", "...", "PercentAction", ")", "ActionID", "{", "percent", ":=", "int", "(", "99", "*", "int", "(", "next", ")", "/", "255", ")", "\n\n", "sofar", ":=", "0", "\n", "for", "_", ",", "pa", ":=", "range", "pas", "{", "sofar", "=", "sofar", "+", "pa", ".", "Percent", "\n", "if", "percent", "<", "sofar", "{", "return", "pa", ".", "Action", "\n", "}", "\n\n", "}", "\n", "return", "NopAction", "\n", "}" ]
// PercentExecute interprets the next byte as a random value and normalizes it // to values 0-99, it then looks to see which action should be execued based // on the action distributions
[ "PercentExecute", "interprets", "the", "next", "byte", "as", "a", "random", "value", "and", "normalizes", "it", "to", "values", "0", "-", "99", "it", "then", "looks", "to", "see", "which", "action", "should", "be", "execued", "based", "on", "the", "action", "distributions" ]
90eadee771aeab36e8bf796039b8c261bebebe4f
https://github.com/mschoch/smat/blob/90eadee771aeab36e8bf796039b8c261bebebe4f/smat.go#L149-L161
12,407
mschoch/smat
actionseq.go
ByteEncoding
func (a ActionSeq) ByteEncoding(ctx Context, setup, teardown ActionID, actionMap ActionMap) ([]byte, error) { setupFunc, teardownFunc, err := actionMap.findSetupTeardown(setup, teardown) if err != nil { return nil, err } state, err := setupFunc(ctx) if err != nil { return nil, err } defer func() { _, _ = teardownFunc(ctx) }() var rv []byte for _, actionID := range a { b, err := probeStateForAction(state, actionID) if err != nil { return nil, err } rv = append(rv, b) action, ok := actionMap[actionID] if !ok { continue } state, err = action(ctx) if err != nil { return nil, err } } return rv, nil }
go
func (a ActionSeq) ByteEncoding(ctx Context, setup, teardown ActionID, actionMap ActionMap) ([]byte, error) { setupFunc, teardownFunc, err := actionMap.findSetupTeardown(setup, teardown) if err != nil { return nil, err } state, err := setupFunc(ctx) if err != nil { return nil, err } defer func() { _, _ = teardownFunc(ctx) }() var rv []byte for _, actionID := range a { b, err := probeStateForAction(state, actionID) if err != nil { return nil, err } rv = append(rv, b) action, ok := actionMap[actionID] if !ok { continue } state, err = action(ctx) if err != nil { return nil, err } } return rv, nil }
[ "func", "(", "a", "ActionSeq", ")", "ByteEncoding", "(", "ctx", "Context", ",", "setup", ",", "teardown", "ActionID", ",", "actionMap", "ActionMap", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "setupFunc", ",", "teardownFunc", ",", "err", ":=", "actionMap", ".", "findSetupTeardown", "(", "setup", ",", "teardown", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "state", ",", "err", ":=", "setupFunc", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "_", ",", "_", "=", "teardownFunc", "(", "ctx", ")", "\n", "}", "(", ")", "\n\n", "var", "rv", "[", "]", "byte", "\n", "for", "_", ",", "actionID", ":=", "range", "a", "{", "b", ",", "err", ":=", "probeStateForAction", "(", "state", ",", "actionID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "rv", "=", "append", "(", "rv", ",", "b", ")", "\n", "action", ",", "ok", ":=", "actionMap", "[", "actionID", "]", "\n", "if", "!", "ok", "{", "continue", "\n", "}", "\n", "state", ",", "err", "=", "action", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "rv", ",", "nil", "\n", "}" ]
// ByteEncoding runs the FSM to produce a byte sequence to trigger the // desired action
[ "ByteEncoding", "runs", "the", "FSM", "to", "produce", "a", "byte", "sequence", "to", "trigger", "the", "desired", "action" ]
90eadee771aeab36e8bf796039b8c261bebebe4f
https://github.com/mschoch/smat/blob/90eadee771aeab36e8bf796039b8c261bebebe4f/actionseq.go#L21-L51
12,408
jordic/goics
decoder_types.go
DateDecode
func (n *IcsNode) DateDecode() (time.Time, error) { // DTEND;VALUE=DATE:20140406 if val, ok := n.Params["VALUE"]; ok { switch { case val == "DATE": t, err := time.Parse("20060102", n.Val) if err != nil { return time.Time{}, err } return t, nil case val == "DATE-TIME": t, err := time.Parse("20060102T150405", n.Val) if err != nil { return time.Time{}, err } return t, nil } } // DTSTART;TZID=Europe/Paris:20140116T120000 if val, ok := n.Params["TZID"]; ok { loc, err := time.LoadLocation(val) if err != nil { return time.Time{}, err } t, err := time.ParseInLocation("20060102T150405", n.Val, loc) if err != nil { return time.Time{}, err } return t, nil } //DTSTART:19980119T070000Z utf datetime if len(n.Val) == 16 { t, err := time.Parse("20060102T150405Z", n.Val) if err != nil { return time.Time{}, err } return t, nil } return time.Time{}, nil }
go
func (n *IcsNode) DateDecode() (time.Time, error) { // DTEND;VALUE=DATE:20140406 if val, ok := n.Params["VALUE"]; ok { switch { case val == "DATE": t, err := time.Parse("20060102", n.Val) if err != nil { return time.Time{}, err } return t, nil case val == "DATE-TIME": t, err := time.Parse("20060102T150405", n.Val) if err != nil { return time.Time{}, err } return t, nil } } // DTSTART;TZID=Europe/Paris:20140116T120000 if val, ok := n.Params["TZID"]; ok { loc, err := time.LoadLocation(val) if err != nil { return time.Time{}, err } t, err := time.ParseInLocation("20060102T150405", n.Val, loc) if err != nil { return time.Time{}, err } return t, nil } //DTSTART:19980119T070000Z utf datetime if len(n.Val) == 16 { t, err := time.Parse("20060102T150405Z", n.Val) if err != nil { return time.Time{}, err } return t, nil } return time.Time{}, nil }
[ "func", "(", "n", "*", "IcsNode", ")", "DateDecode", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "// DTEND;VALUE=DATE:20140406", "if", "val", ",", "ok", ":=", "n", ".", "Params", "[", "\"", "\"", "]", ";", "ok", "{", "switch", "{", "case", "val", "==", "\"", "\"", ":", "t", ",", "err", ":=", "time", ".", "Parse", "(", "\"", "\"", ",", "n", ".", "Val", ")", "\n", "if", "err", "!=", "nil", "{", "return", "time", ".", "Time", "{", "}", ",", "err", "\n", "}", "\n", "return", "t", ",", "nil", "\n", "case", "val", "==", "\"", "\"", ":", "t", ",", "err", ":=", "time", ".", "Parse", "(", "\"", "\"", ",", "n", ".", "Val", ")", "\n", "if", "err", "!=", "nil", "{", "return", "time", ".", "Time", "{", "}", ",", "err", "\n", "}", "\n", "return", "t", ",", "nil", "\n", "}", "\n", "}", "\n", "// DTSTART;TZID=Europe/Paris:20140116T120000", "if", "val", ",", "ok", ":=", "n", ".", "Params", "[", "\"", "\"", "]", ";", "ok", "{", "loc", ",", "err", ":=", "time", ".", "LoadLocation", "(", "val", ")", "\n", "if", "err", "!=", "nil", "{", "return", "time", ".", "Time", "{", "}", ",", "err", "\n", "}", "\n", "t", ",", "err", ":=", "time", ".", "ParseInLocation", "(", "\"", "\"", ",", "n", ".", "Val", ",", "loc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "time", ".", "Time", "{", "}", ",", "err", "\n", "}", "\n", "return", "t", ",", "nil", "\n", "}", "\n", "//DTSTART:19980119T070000Z utf datetime", "if", "len", "(", "n", ".", "Val", ")", "==", "16", "{", "t", ",", "err", ":=", "time", ".", "Parse", "(", "\"", "\"", ",", "n", ".", "Val", ")", "\n", "if", "err", "!=", "nil", "{", "return", "time", ".", "Time", "{", "}", ",", "err", "\n", "}", "\n", "return", "t", ",", "nil", "\n", "}", "\n\n", "return", "time", ".", "Time", "{", "}", ",", "nil", "\n", "}" ]
// DateDecode Decodes a date in the distincts formats
[ "DateDecode", "Decodes", "a", "date", "in", "the", "distincts", "formats" ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/decoder_types.go#L8-L49
12,409
jordic/goics
string.go
splitLength
func splitLength(s string, length int) []string { var ret []string for len(s) > 0 { tmp := truncateString(s, length) if len(tmp) == 0 { // too short length, or invalid UTF-8 string break } ret = append(ret, tmp) s = s[len(tmp):] } return ret }
go
func splitLength(s string, length int) []string { var ret []string for len(s) > 0 { tmp := truncateString(s, length) if len(tmp) == 0 { // too short length, or invalid UTF-8 string break } ret = append(ret, tmp) s = s[len(tmp):] } return ret }
[ "func", "splitLength", "(", "s", "string", ",", "length", "int", ")", "[", "]", "string", "{", "var", "ret", "[", "]", "string", "\n\n", "for", "len", "(", "s", ")", ">", "0", "{", "tmp", ":=", "truncateString", "(", "s", ",", "length", ")", "\n", "if", "len", "(", "tmp", ")", "==", "0", "{", "// too short length, or invalid UTF-8 string", "break", "\n", "}", "\n", "ret", "=", "append", "(", "ret", ",", "tmp", ")", "\n", "s", "=", "s", "[", "len", "(", "tmp", ")", ":", "]", "\n", "}", "\n\n", "return", "ret", "\n", "}" ]
// splitLength returns a slice of strings, each string is at most length bytes long. // Does not break UTF-8 codepoints.
[ "splitLength", "returns", "a", "slice", "of", "strings", "each", "string", "is", "at", "most", "length", "bytes", "long", ".", "Does", "not", "break", "UTF", "-", "8", "codepoints", "." ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/string.go#L5-L19
12,410
jordic/goics
string.go
truncateString
func truncateString(s string, length int) string { if len(s) <= length { return s } // UTF-8 continuation bytes start with 10xx xxxx: // 0xc0 = 1100 0000 // 0x80 = 1000 0000 cutoff := length for s[cutoff]&0xc0 == 0x80 { cutoff-- if cutoff < 0 { cutoff = 0 break } } return s[0:cutoff] }
go
func truncateString(s string, length int) string { if len(s) <= length { return s } // UTF-8 continuation bytes start with 10xx xxxx: // 0xc0 = 1100 0000 // 0x80 = 1000 0000 cutoff := length for s[cutoff]&0xc0 == 0x80 { cutoff-- if cutoff < 0 { cutoff = 0 break } } return s[0:cutoff] }
[ "func", "truncateString", "(", "s", "string", ",", "length", "int", ")", "string", "{", "if", "len", "(", "s", ")", "<=", "length", "{", "return", "s", "\n", "}", "\n\n", "// UTF-8 continuation bytes start with 10xx xxxx:", "// 0xc0 = 1100 0000", "// 0x80 = 1000 0000", "cutoff", ":=", "length", "\n", "for", "s", "[", "cutoff", "]", "&", "0xc0", "==", "0x80", "{", "cutoff", "--", "\n", "if", "cutoff", "<", "0", "{", "cutoff", "=", "0", "\n", "break", "\n", "}", "\n", "}", "\n\n", "return", "s", "[", "0", ":", "cutoff", "]", "\n", "}" ]
// truncateString truncates s to a maximum of length bytes without breaking UTF-8 codepoints.
[ "truncateString", "truncates", "s", "to", "a", "maximum", "of", "length", "bytes", "without", "breaking", "UTF", "-", "8", "codepoints", "." ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/string.go#L22-L40
12,411
jordic/goics
encoder.go
NewComponent
func NewComponent() *Component { return &Component{ Elements: make([]Componenter, 0), Properties: make(map[string]string), } }
go
func NewComponent() *Component { return &Component{ Elements: make([]Componenter, 0), Properties: make(map[string]string), } }
[ "func", "NewComponent", "(", ")", "*", "Component", "{", "return", "&", "Component", "{", "Elements", ":", "make", "(", "[", "]", "Componenter", ",", "0", ")", ",", "Properties", ":", "make", "(", "map", "[", "string", "]", "string", ")", ",", "}", "\n", "}" ]
// NewComponent returns a new Component and setups // and setups Properties map for the component // and also allows more Components inside it. // VCALENDAR is a Component that has VEVENTS, // VEVENTS can hold VALARMS
[ "NewComponent", "returns", "a", "new", "Component", "and", "setups", "and", "setups", "Properties", "map", "for", "the", "component", "and", "also", "allows", "more", "Components", "inside", "it", ".", "VCALENDAR", "is", "a", "Component", "that", "has", "VEVENTS", "VEVENTS", "can", "hold", "VALARMS" ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/encoder.go#L21-L26
12,412
jordic/goics
encoder.go
Write
func (c *Component) Write(w *ICalEncode) { w.WriteLine("BEGIN:" + c.Tipo + CRLF) // Iterate over component properites var keys []string for k := range c.Properties { keys = append(keys, k) } sort.Strings(keys) for _, key := range keys { val := c.Properties[key] w.WriteLine(WriteStringField(key, val)) } for _, xc := range c.Elements { xc.Write(w) } w.WriteLine("END:" + c.Tipo + CRLF) }
go
func (c *Component) Write(w *ICalEncode) { w.WriteLine("BEGIN:" + c.Tipo + CRLF) // Iterate over component properites var keys []string for k := range c.Properties { keys = append(keys, k) } sort.Strings(keys) for _, key := range keys { val := c.Properties[key] w.WriteLine(WriteStringField(key, val)) } for _, xc := range c.Elements { xc.Write(w) } w.WriteLine("END:" + c.Tipo + CRLF) }
[ "func", "(", "c", "*", "Component", ")", "Write", "(", "w", "*", "ICalEncode", ")", "{", "w", ".", "WriteLine", "(", "\"", "\"", "+", "c", ".", "Tipo", "+", "CRLF", ")", "\n\n", "// Iterate over component properites", "var", "keys", "[", "]", "string", "\n", "for", "k", ":=", "range", "c", ".", "Properties", "{", "keys", "=", "append", "(", "keys", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "keys", ")", "\n", "for", "_", ",", "key", ":=", "range", "keys", "{", "val", ":=", "c", ".", "Properties", "[", "key", "]", "\n", "w", ".", "WriteLine", "(", "WriteStringField", "(", "key", ",", "val", ")", ")", "\n", "}", "\n\n", "for", "_", ",", "xc", ":=", "range", "c", ".", "Elements", "{", "xc", ".", "Write", "(", "w", ")", "\n", "}", "\n\n", "w", ".", "WriteLine", "(", "\"", "\"", "+", "c", ".", "Tipo", "+", "CRLF", ")", "\n", "}" ]
// Writes the component to the Writer
[ "Writes", "the", "component", "to", "the", "Writer" ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/encoder.go#L37-L56
12,413
jordic/goics
encoder.go
AddComponent
func (c *Component) AddComponent(cc Componenter) { c.Elements = append(c.Elements, cc) }
go
func (c *Component) AddComponent(cc Componenter) { c.Elements = append(c.Elements, cc) }
[ "func", "(", "c", "*", "Component", ")", "AddComponent", "(", "cc", "Componenter", ")", "{", "c", ".", "Elements", "=", "append", "(", "c", ".", "Elements", ",", "cc", ")", "\n", "}" ]
// AddComponent to the base component, just for building // the component tree
[ "AddComponent", "to", "the", "base", "component", "just", "for", "building", "the", "component", "tree" ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/encoder.go#L66-L68
12,414
jordic/goics
encoder.go
AddProperty
func (c *Component) AddProperty(key string, val string) { c.Properties[key] = val }
go
func (c *Component) AddProperty(key string, val string) { c.Properties[key] = val }
[ "func", "(", "c", "*", "Component", ")", "AddProperty", "(", "key", "string", ",", "val", "string", ")", "{", "c", ".", "Properties", "[", "key", "]", "=", "val", "\n", "}" ]
// AddProperty ads a property to the component
[ "AddProperty", "ads", "a", "property", "to", "the", "component" ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/encoder.go#L71-L73
12,415
jordic/goics
encoder.go
Encode
func (enc *ICalEncode) Encode(c ICalEmiter) { component := c.EmitICal() component.Write(enc) }
go
func (enc *ICalEncode) Encode(c ICalEmiter) { component := c.EmitICal() component.Write(enc) }
[ "func", "(", "enc", "*", "ICalEncode", ")", "Encode", "(", "c", "ICalEmiter", ")", "{", "component", ":=", "c", ".", "EmitICal", "(", ")", "\n", "component", ".", "Write", "(", "enc", ")", "\n", "}" ]
// Encode the Component into the ical format
[ "Encode", "the", "Component", "into", "the", "ical", "format" ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/encoder.go#L90-L93
12,416
jordic/goics
encoder.go
WriteLine
func (enc *ICalEncode) WriteLine(s string) { if len(s) <= LineSize { io.WriteString(enc.w, s) return } // The first line does not begin with a space. firstLine := truncateString(s, LineSize-len(CRLF)) io.WriteString(enc.w, firstLine+CRLF) // Reserve three bytes for space + CRLF. lines := splitLength(s[len(firstLine):], LineSize-len(CRLFSP)) for i, line := range lines { if i < len(lines)-1 { io.WriteString(enc.w, " "+line+CRLF) } else { // This is the last line, don't append CRLF. io.WriteString(enc.w, " "+line) } } }
go
func (enc *ICalEncode) WriteLine(s string) { if len(s) <= LineSize { io.WriteString(enc.w, s) return } // The first line does not begin with a space. firstLine := truncateString(s, LineSize-len(CRLF)) io.WriteString(enc.w, firstLine+CRLF) // Reserve three bytes for space + CRLF. lines := splitLength(s[len(firstLine):], LineSize-len(CRLFSP)) for i, line := range lines { if i < len(lines)-1 { io.WriteString(enc.w, " "+line+CRLF) } else { // This is the last line, don't append CRLF. io.WriteString(enc.w, " "+line) } } }
[ "func", "(", "enc", "*", "ICalEncode", ")", "WriteLine", "(", "s", "string", ")", "{", "if", "len", "(", "s", ")", "<=", "LineSize", "{", "io", ".", "WriteString", "(", "enc", ".", "w", ",", "s", ")", "\n", "return", "\n", "}", "\n\n", "// The first line does not begin with a space.", "firstLine", ":=", "truncateString", "(", "s", ",", "LineSize", "-", "len", "(", "CRLF", ")", ")", "\n", "io", ".", "WriteString", "(", "enc", ".", "w", ",", "firstLine", "+", "CRLF", ")", "\n\n", "// Reserve three bytes for space + CRLF.", "lines", ":=", "splitLength", "(", "s", "[", "len", "(", "firstLine", ")", ":", "]", ",", "LineSize", "-", "len", "(", "CRLFSP", ")", ")", "\n", "for", "i", ",", "line", ":=", "range", "lines", "{", "if", "i", "<", "len", "(", "lines", ")", "-", "1", "{", "io", ".", "WriteString", "(", "enc", ".", "w", ",", "\"", "\"", "+", "line", "+", "CRLF", ")", "\n", "}", "else", "{", "// This is the last line, don't append CRLF.", "io", ".", "WriteString", "(", "enc", ".", "w", ",", "\"", "\"", "+", "line", ")", "\n", "}", "\n", "}", "\n", "}" ]
// WriteLine in ics format max length = LineSize // continuation lines start with a space.
[ "WriteLine", "in", "ics", "format", "max", "length", "=", "LineSize", "continuation", "lines", "start", "with", "a", "space", "." ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/encoder.go#L100-L120
12,417
jordic/goics
examples/mysqlsource/main.go
load_config
func load_config() { file, err := ioutil.ReadFile(*configFile) if err != nil { log.Fatalf("Error reading config file %s", err) } err = json.Unmarshal(file, &config) if err != nil { log.Fatalf("Error decoding config file %s", err) } }
go
func load_config() { file, err := ioutil.ReadFile(*configFile) if err != nil { log.Fatalf("Error reading config file %s", err) } err = json.Unmarshal(file, &config) if err != nil { log.Fatalf("Error decoding config file %s", err) } }
[ "func", "load_config", "(", ")", "{", "file", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "*", "configFile", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "err", "=", "json", ".", "Unmarshal", "(", "file", ",", "&", "config", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}" ]
// Load and parse config json file
[ "Load", "and", "parse", "config", "json", "file" ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/examples/mysqlsource/main.go#L69-L79
12,418
jordic/goics
decoder_line.go
ParamsLen
func (n *IcsNode) ParamsLen() int { if n.Params == nil { return 0 } return len(n.Params) }
go
func (n *IcsNode) ParamsLen() int { if n.Params == nil { return 0 } return len(n.Params) }
[ "func", "(", "n", "*", "IcsNode", ")", "ParamsLen", "(", ")", "int", "{", "if", "n", ".", "Params", "==", "nil", "{", "return", "0", "\n", "}", "\n", "return", "len", "(", "n", ".", "Params", ")", "\n", "}" ]
// ParamsLen returns how many params has a token
[ "ParamsLen", "returns", "how", "many", "params", "has", "a", "token" ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/decoder_line.go#L20-L25
12,419
jordic/goics
decoder_line.go
GetOneParam
func (n *IcsNode) GetOneParam() (string, string) { if n.ParamsLen() == 0 { return "", "" } var key, val string for k, v := range n.Params { key, val = k, v break } return key, val }
go
func (n *IcsNode) GetOneParam() (string, string) { if n.ParamsLen() == 0 { return "", "" } var key, val string for k, v := range n.Params { key, val = k, v break } return key, val }
[ "func", "(", "n", "*", "IcsNode", ")", "GetOneParam", "(", ")", "(", "string", ",", "string", ")", "{", "if", "n", ".", "ParamsLen", "(", ")", "==", "0", "{", "return", "\"", "\"", ",", "\"", "\"", "\n", "}", "\n", "var", "key", ",", "val", "string", "\n", "for", "k", ",", "v", ":=", "range", "n", ".", "Params", "{", "key", ",", "val", "=", "k", ",", "v", "\n", "break", "\n", "}", "\n", "return", "key", ",", "val", "\n", "}" ]
// GetOneParam resturns the first param found // usefull when you know that there is a only // one param token
[ "GetOneParam", "resturns", "the", "first", "param", "found", "usefull", "when", "you", "know", "that", "there", "is", "a", "only", "one", "param", "token" ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/decoder_line.go#L30-L40
12,420
jordic/goics
decoder_line.go
DecodeLine
func DecodeLine(line string) *IcsNode { if strings.Contains(line, keySep) == false { return &IcsNode{} } key, val := getKeyVal(line) //@todo test if val containes , multipleparams if strings.Contains(key, vParamSep) == false { return &IcsNode{ Key: key, Val: val, } } // Extract key firstParam := strings.Index(key, vParamSep) realkey := key[0:firstParam] n := &IcsNode{ Key: realkey, Val: val, } // Extract params params := key[firstParam+1:] n.Params = decodeParams(params) return n }
go
func DecodeLine(line string) *IcsNode { if strings.Contains(line, keySep) == false { return &IcsNode{} } key, val := getKeyVal(line) //@todo test if val containes , multipleparams if strings.Contains(key, vParamSep) == false { return &IcsNode{ Key: key, Val: val, } } // Extract key firstParam := strings.Index(key, vParamSep) realkey := key[0:firstParam] n := &IcsNode{ Key: realkey, Val: val, } // Extract params params := key[firstParam+1:] n.Params = decodeParams(params) return n }
[ "func", "DecodeLine", "(", "line", "string", ")", "*", "IcsNode", "{", "if", "strings", ".", "Contains", "(", "line", ",", "keySep", ")", "==", "false", "{", "return", "&", "IcsNode", "{", "}", "\n", "}", "\n", "key", ",", "val", ":=", "getKeyVal", "(", "line", ")", "\n", "//@todo test if val containes , multipleparams", "if", "strings", ".", "Contains", "(", "key", ",", "vParamSep", ")", "==", "false", "{", "return", "&", "IcsNode", "{", "Key", ":", "key", ",", "Val", ":", "val", ",", "}", "\n", "}", "\n", "// Extract key", "firstParam", ":=", "strings", ".", "Index", "(", "key", ",", "vParamSep", ")", "\n", "realkey", ":=", "key", "[", "0", ":", "firstParam", "]", "\n", "n", ":=", "&", "IcsNode", "{", "Key", ":", "realkey", ",", "Val", ":", "val", ",", "}", "\n", "// Extract params", "params", ":=", "key", "[", "firstParam", "+", "1", ":", "]", "\n", "n", ".", "Params", "=", "decodeParams", "(", "params", ")", "\n", "return", "n", "\n", "}" ]
// DecodeLine extracts key, val and extra params from a line
[ "DecodeLine", "extracts", "key", "val", "and", "extra", "params", "from", "a", "line" ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/decoder_line.go#L43-L66
12,421
jordic/goics
decoder_line.go
getKeyVal
func getKeyVal(s string) (key, value string) { p := strings.SplitN(s, keySep, 2) return p[0], icsReplacer.Replace(p[1]) }
go
func getKeyVal(s string) (key, value string) { p := strings.SplitN(s, keySep, 2) return p[0], icsReplacer.Replace(p[1]) }
[ "func", "getKeyVal", "(", "s", "string", ")", "(", "key", ",", "value", "string", ")", "{", "p", ":=", "strings", ".", "SplitN", "(", "s", ",", "keySep", ",", "2", ")", "\n", "return", "p", "[", "0", "]", ",", "icsReplacer", ".", "Replace", "(", "p", "[", "1", "]", ")", "\n", "}" ]
// Returns a key, val... for a line..
[ "Returns", "a", "key", "val", "...", "for", "a", "line", ".." ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/decoder_line.go#L109-L112
12,422
jordic/goics
examples/mysqlsource/models.go
EmitICal
func (rc ReservasCollection) EmitICal() goics.Componenter { c := goics.NewComponent() c.SetType("VCALENDAR") c.AddProperty("CALSCAL", "GREGORIAN") c.AddProperty("PRODID;X-RICAL-TZSOURCE=TZINFO", "-//tmpo.io") for _, ev := range rc { s := goics.NewComponent() s.SetType("VEVENT") dtend := ev.Data.AddDate(0, 0, ev.Nits) k, v := goics.FormatDateField("DTEND", dtend) s.AddProperty(k, v) k, v = goics.FormatDateField("DTSTART", ev.Data) s.AddProperty(k, v) s.AddProperty("UID", ev.Clau+"@whotells.com") des := fmt.Sprintf("%s Llegada: %s", ev.Extra.String, ev.Llegada.String) s.AddProperty("DESCRIPTION", des) s.AddProperty("SUMMARY", fmt.Sprintf("Reserva de %s", ev.Client)) s.AddProperty("LOCATION", ev.Apartament) c.AddComponent(s) } return c }
go
func (rc ReservasCollection) EmitICal() goics.Componenter { c := goics.NewComponent() c.SetType("VCALENDAR") c.AddProperty("CALSCAL", "GREGORIAN") c.AddProperty("PRODID;X-RICAL-TZSOURCE=TZINFO", "-//tmpo.io") for _, ev := range rc { s := goics.NewComponent() s.SetType("VEVENT") dtend := ev.Data.AddDate(0, 0, ev.Nits) k, v := goics.FormatDateField("DTEND", dtend) s.AddProperty(k, v) k, v = goics.FormatDateField("DTSTART", ev.Data) s.AddProperty(k, v) s.AddProperty("UID", ev.Clau+"@whotells.com") des := fmt.Sprintf("%s Llegada: %s", ev.Extra.String, ev.Llegada.String) s.AddProperty("DESCRIPTION", des) s.AddProperty("SUMMARY", fmt.Sprintf("Reserva de %s", ev.Client)) s.AddProperty("LOCATION", ev.Apartament) c.AddComponent(s) } return c }
[ "func", "(", "rc", "ReservasCollection", ")", "EmitICal", "(", ")", "goics", ".", "Componenter", "{", "c", ":=", "goics", ".", "NewComponent", "(", ")", "\n", "c", ".", "SetType", "(", "\"", "\"", ")", "\n", "c", ".", "AddProperty", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "c", ".", "AddProperty", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "for", "_", ",", "ev", ":=", "range", "rc", "{", "s", ":=", "goics", ".", "NewComponent", "(", ")", "\n", "s", ".", "SetType", "(", "\"", "\"", ")", "\n", "dtend", ":=", "ev", ".", "Data", ".", "AddDate", "(", "0", ",", "0", ",", "ev", ".", "Nits", ")", "\n", "k", ",", "v", ":=", "goics", ".", "FormatDateField", "(", "\"", "\"", ",", "dtend", ")", "\n", "s", ".", "AddProperty", "(", "k", ",", "v", ")", "\n", "k", ",", "v", "=", "goics", ".", "FormatDateField", "(", "\"", "\"", ",", "ev", ".", "Data", ")", "\n", "s", ".", "AddProperty", "(", "k", ",", "v", ")", "\n", "s", ".", "AddProperty", "(", "\"", "\"", ",", "ev", ".", "Clau", "+", "\"", "\"", ")", "\n", "des", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ev", ".", "Extra", ".", "String", ",", "ev", ".", "Llegada", ".", "String", ")", "\n", "s", ".", "AddProperty", "(", "\"", "\"", ",", "des", ")", "\n", "s", ".", "AddProperty", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ev", ".", "Client", ")", ")", "\n", "s", ".", "AddProperty", "(", "\"", "\"", ",", "ev", ".", "Apartament", ")", "\n\n", "c", ".", "AddComponent", "(", "s", ")", "\n", "}", "\n\n", "return", "c", "\n\n", "}" ]
// We implement ICalEmiter interface that will return a goics.Componenter.
[ "We", "implement", "ICalEmiter", "interface", "that", "will", "return", "a", "goics", ".", "Componenter", "." ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/examples/mysqlsource/models.go#L28-L54
12,423
jordic/goics
examples/mysqlsource/models.go
GetReservas
func GetReservas() ReservasCollection { t := time.Now() q := `SELECT clau, data, nits, limpieza, llegada, CONCAT(b.tipus, " ", b.title) as apartament, CONCAT(c.nom, " ", c.cognom) as client FROM reserves_reserva as a LEFT join crm_client as c on a.client_id = c.id LEFT JOIN reserves_apartament as b on a.apartament_id = b.id WHERE data>=? and a.status<=3` reservas := ReservasCollection{} err := Db.Select(&reservas, q, t.Format("2006-01-02")) _ = Db.Unsafe() if err != nil { log.Println(err) } return reservas }
go
func GetReservas() ReservasCollection { t := time.Now() q := `SELECT clau, data, nits, limpieza, llegada, CONCAT(b.tipus, " ", b.title) as apartament, CONCAT(c.nom, " ", c.cognom) as client FROM reserves_reserva as a LEFT join crm_client as c on a.client_id = c.id LEFT JOIN reserves_apartament as b on a.apartament_id = b.id WHERE data>=? and a.status<=3` reservas := ReservasCollection{} err := Db.Select(&reservas, q, t.Format("2006-01-02")) _ = Db.Unsafe() if err != nil { log.Println(err) } return reservas }
[ "func", "GetReservas", "(", ")", "ReservasCollection", "{", "t", ":=", "time", ".", "Now", "(", ")", "\n", "q", ":=", "`SELECT clau, data, nits, limpieza, llegada, \n\t\t\tCONCAT(b.tipus, \" \", b.title) as apartament,\n\t\t\tCONCAT(c.nom, \" \", c.cognom) as client \n\t\tFROM reserves_reserva as a LEFT join crm_client as c on a.client_id = c.id\n\t\tLEFT JOIN reserves_apartament as b on a.apartament_id = b.id\n\t\tWHERE data>=? and a.status<=3`", "\n\n", "reservas", ":=", "ReservasCollection", "{", "}", "\n", "err", ":=", "Db", ".", "Select", "(", "&", "reservas", ",", "q", ",", "t", ".", "Format", "(", "\"", "\"", ")", ")", "\n", "_", "=", "Db", ".", "Unsafe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Println", "(", "err", ")", "\n", "}", "\n", "return", "reservas", "\n", "}" ]
// Get data from database populating ReservasCollection
[ "Get", "data", "from", "database", "populating", "ReservasCollection" ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/examples/mysqlsource/models.go#L57-L74
12,424
jordic/goics
decoder.go
NewDecoder
func NewDecoder(r io.Reader) *decoder { d := &decoder{ scanner: bufio.NewScanner(r), nextFn: decodeInit, line: 0, buffered: "", } return d }
go
func NewDecoder(r io.Reader) *decoder { d := &decoder{ scanner: bufio.NewScanner(r), nextFn: decodeInit, line: 0, buffered: "", } return d }
[ "func", "NewDecoder", "(", "r", "io", ".", "Reader", ")", "*", "decoder", "{", "d", ":=", "&", "decoder", "{", "scanner", ":", "bufio", ".", "NewScanner", "(", "r", ")", ",", "nextFn", ":", "decodeInit", ",", "line", ":", "0", ",", "buffered", ":", "\"", "\"", ",", "}", "\n", "return", "d", "\n", "}" ]
// NewDecoder creates an instance of de decoder
[ "NewDecoder", "creates", "an", "instance", "of", "de", "decoder" ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/decoder.go#L40-L48
12,425
jordic/goics
decoder.go
next
func (d *decoder) next() { // If there's not buffered line if d.buffered == "" { res := d.scanner.Scan() if true != res { d.err = d.scanner.Err() return } d.line++ d.current = d.scanner.Text() } else { d.current = d.buffered d.buffered = "" } for d.scanner.Scan() { d.line++ line := d.scanner.Text() if strings.HasPrefix(line, " ") || strings.HasPrefix(line, "\t") { d.current = d.current + line[1:] } else { // If is not a continuation line, buffer it, for the // next call. d.buffered = line break } } d.err = d.scanner.Err() if d.nextFn != nil { d.nextFn(d) } }
go
func (d *decoder) next() { // If there's not buffered line if d.buffered == "" { res := d.scanner.Scan() if true != res { d.err = d.scanner.Err() return } d.line++ d.current = d.scanner.Text() } else { d.current = d.buffered d.buffered = "" } for d.scanner.Scan() { d.line++ line := d.scanner.Text() if strings.HasPrefix(line, " ") || strings.HasPrefix(line, "\t") { d.current = d.current + line[1:] } else { // If is not a continuation line, buffer it, for the // next call. d.buffered = line break } } d.err = d.scanner.Err() if d.nextFn != nil { d.nextFn(d) } }
[ "func", "(", "d", "*", "decoder", ")", "next", "(", ")", "{", "// If there's not buffered line", "if", "d", ".", "buffered", "==", "\"", "\"", "{", "res", ":=", "d", ".", "scanner", ".", "Scan", "(", ")", "\n", "if", "true", "!=", "res", "{", "d", ".", "err", "=", "d", ".", "scanner", ".", "Err", "(", ")", "\n", "return", "\n", "}", "\n", "d", ".", "line", "++", "\n", "d", ".", "current", "=", "d", ".", "scanner", ".", "Text", "(", ")", "\n", "}", "else", "{", "d", ".", "current", "=", "d", ".", "buffered", "\n", "d", ".", "buffered", "=", "\"", "\"", "\n", "}", "\n\n", "for", "d", ".", "scanner", ".", "Scan", "(", ")", "{", "d", ".", "line", "++", "\n", "line", ":=", "d", ".", "scanner", ".", "Text", "(", ")", "\n", "if", "strings", ".", "HasPrefix", "(", "line", ",", "\"", "\"", ")", "||", "strings", ".", "HasPrefix", "(", "line", ",", "\"", "\\t", "\"", ")", "{", "d", ".", "current", "=", "d", ".", "current", "+", "line", "[", "1", ":", "]", "\n", "}", "else", "{", "// If is not a continuation line, buffer it, for the", "// next call.", "d", ".", "buffered", "=", "line", "\n", "break", "\n", "}", "\n", "}", "\n\n", "d", ".", "err", "=", "d", ".", "scanner", ".", "Err", "(", ")", "\n\n", "if", "d", ".", "nextFn", "!=", "nil", "{", "d", ".", "nextFn", "(", "d", ")", "\n", "}", "\n", "}" ]
// Advances a new line in the decoder // And calls the next stateFunc // checks if next line is continuation line
[ "Advances", "a", "new", "line", "in", "the", "decoder", "And", "calls", "the", "next", "stateFunc", "checks", "if", "next", "line", "is", "continuation", "line" ]
feb996c8e01f48a15f84459592b5d1993e12f0ec
https://github.com/jordic/goics/blob/feb996c8e01f48a15f84459592b5d1993e12f0ec/decoder.go#L83-L116
12,426
retailnext/hllpp
sparse.go
Append
func (writer *sparseWriter) Append(k, idx uint32, rho uint8) { if writer.hasCurrVal { if idx == writer.currIdx { if rho > writer.currRho { writer.currRho = rho writer.currVal = k } return } else { writer.commit() } } writer.hasCurrVal = true writer.currVal = k writer.currIdx = idx writer.currRho = rho }
go
func (writer *sparseWriter) Append(k, idx uint32, rho uint8) { if writer.hasCurrVal { if idx == writer.currIdx { if rho > writer.currRho { writer.currRho = rho writer.currVal = k } return } else { writer.commit() } } writer.hasCurrVal = true writer.currVal = k writer.currIdx = idx writer.currRho = rho }
[ "func", "(", "writer", "*", "sparseWriter", ")", "Append", "(", "k", ",", "idx", "uint32", ",", "rho", "uint8", ")", "{", "if", "writer", ".", "hasCurrVal", "{", "if", "idx", "==", "writer", ".", "currIdx", "{", "if", "rho", ">", "writer", ".", "currRho", "{", "writer", ".", "currRho", "=", "rho", "\n", "writer", ".", "currVal", "=", "k", "\n", "}", "\n", "return", "\n", "}", "else", "{", "writer", ".", "commit", "(", ")", "\n", "}", "\n", "}", "\n\n", "writer", ".", "hasCurrVal", "=", "true", "\n", "writer", ".", "currVal", "=", "k", "\n", "writer", ".", "currIdx", "=", "idx", "\n", "writer", ".", "currRho", "=", "rho", "\n", "}" ]
// This takes the index and rho well so it can easily discard duplicate indexes // and pick the biggest rho among the duplicates since tmpSet is sorted by index // but not by rho.
[ "This", "takes", "the", "index", "and", "rho", "well", "so", "it", "can", "easily", "discard", "duplicate", "indexes", "and", "pick", "the", "biggest", "rho", "among", "the", "duplicates", "since", "tmpSet", "is", "sorted", "by", "index", "but", "not", "by", "rho", "." ]
101a6d2f8b52abfc409ac188958e7e7be0116331
https://github.com/retailnext/hllpp/blob/101a6d2f8b52abfc409ac188958e7e7be0116331/sparse.go#L70-L87
12,427
retailnext/hllpp
sparse.go
decodeHash
func (h *HLLPP) decodeHash(k uint32, p uint8) (_ uint32, r uint8) { if k&1 > 0 { r = uint8(sliceBits32(k, 6, 1)) + (h.pp - h.p) } else { r = rho((uint64(k) | 1) << (64 - (h.pp + 1) + h.p)) } return h.getIndex(k, p), r }
go
func (h *HLLPP) decodeHash(k uint32, p uint8) (_ uint32, r uint8) { if k&1 > 0 { r = uint8(sliceBits32(k, 6, 1)) + (h.pp - h.p) } else { r = rho((uint64(k) | 1) << (64 - (h.pp + 1) + h.p)) } return h.getIndex(k, p), r }
[ "func", "(", "h", "*", "HLLPP", ")", "decodeHash", "(", "k", "uint32", ",", "p", "uint8", ")", "(", "_", "uint32", ",", "r", "uint8", ")", "{", "if", "k", "&", "1", ">", "0", "{", "r", "=", "uint8", "(", "sliceBits32", "(", "k", ",", "6", ",", "1", ")", ")", "+", "(", "h", ".", "pp", "-", "h", ".", "p", ")", "\n", "}", "else", "{", "r", "=", "rho", "(", "(", "uint64", "(", "k", ")", "|", "1", ")", "<<", "(", "64", "-", "(", "h", ".", "pp", "+", "1", ")", "+", "h", ".", "p", ")", ")", "\n", "}", "\n\n", "return", "h", ".", "getIndex", "(", "k", ",", "p", ")", ",", "r", "\n", "}" ]
// Return index with respect to "p" arg, and rho with respect to h.p. This is so // the h.pp index can be recovered easily when flushing the tmpSet.
[ "Return", "index", "with", "respect", "to", "p", "arg", "and", "rho", "with", "respect", "to", "h", ".", "p", ".", "This", "is", "so", "the", "h", ".", "pp", "index", "can", "be", "recovered", "easily", "when", "flushing", "the", "tmpSet", "." ]
101a6d2f8b52abfc409ac188958e7e7be0116331
https://github.com/retailnext/hllpp/blob/101a6d2f8b52abfc409ac188958e7e7be0116331/sparse.go#L195-L203
12,428
retailnext/hllpp
sparse.go
getIndex
func (h *HLLPP) getIndex(k uint32, p uint8) uint32 { if k&1 > 0 { return sliceBits32(k, 6+h.pp, 1+6+h.pp-p) } else { return sliceBits32(k, h.pp, 1+h.pp-p) } }
go
func (h *HLLPP) getIndex(k uint32, p uint8) uint32 { if k&1 > 0 { return sliceBits32(k, 6+h.pp, 1+6+h.pp-p) } else { return sliceBits32(k, h.pp, 1+h.pp-p) } }
[ "func", "(", "h", "*", "HLLPP", ")", "getIndex", "(", "k", "uint32", ",", "p", "uint8", ")", "uint32", "{", "if", "k", "&", "1", ">", "0", "{", "return", "sliceBits32", "(", "k", ",", "6", "+", "h", ".", "pp", ",", "1", "+", "6", "+", "h", ".", "pp", "-", "p", ")", "\n", "}", "else", "{", "return", "sliceBits32", "(", "k", ",", "h", ".", "pp", ",", "1", "+", "h", ".", "pp", "-", "p", ")", "\n", "}", "\n", "}" ]
// Return index with respect to precision "p".
[ "Return", "index", "with", "respect", "to", "precision", "p", "." ]
101a6d2f8b52abfc409ac188958e7e7be0116331
https://github.com/retailnext/hllpp/blob/101a6d2f8b52abfc409ac188958e7e7be0116331/sparse.go#L206-L212
12,429
retailnext/hllpp
marshal.go
Marshal
func (h *HLLPP) Marshal() []byte { if h.sparse { h.flushTmpSet() } buf := make([]byte, marshalHeaderSize+len(h.data)) offset := 0 binary.BigEndian.PutUint16(buf[offset:], marshalVersion) offset += 2 binary.BigEndian.PutUint32(buf[offset:], uint32(len(buf))) offset += 4 var flags uint16 if h.sparse { flags |= marshalFlagSparse } binary.BigEndian.PutUint16(buf[offset:], flags) offset += 2 buf[offset] = h.p offset += 1 buf[offset] = h.pp offset += 1 binary.BigEndian.PutUint32(buf[offset:], h.sparseLength) offset += 4 buf[offset] = byte(h.bitsPerRegister) offset += 1 copy(buf[offset:], h.data) return buf }
go
func (h *HLLPP) Marshal() []byte { if h.sparse { h.flushTmpSet() } buf := make([]byte, marshalHeaderSize+len(h.data)) offset := 0 binary.BigEndian.PutUint16(buf[offset:], marshalVersion) offset += 2 binary.BigEndian.PutUint32(buf[offset:], uint32(len(buf))) offset += 4 var flags uint16 if h.sparse { flags |= marshalFlagSparse } binary.BigEndian.PutUint16(buf[offset:], flags) offset += 2 buf[offset] = h.p offset += 1 buf[offset] = h.pp offset += 1 binary.BigEndian.PutUint32(buf[offset:], h.sparseLength) offset += 4 buf[offset] = byte(h.bitsPerRegister) offset += 1 copy(buf[offset:], h.data) return buf }
[ "func", "(", "h", "*", "HLLPP", ")", "Marshal", "(", ")", "[", "]", "byte", "{", "if", "h", ".", "sparse", "{", "h", ".", "flushTmpSet", "(", ")", "\n", "}", "\n\n", "buf", ":=", "make", "(", "[", "]", "byte", ",", "marshalHeaderSize", "+", "len", "(", "h", ".", "data", ")", ")", "\n\n", "offset", ":=", "0", "\n\n", "binary", ".", "BigEndian", ".", "PutUint16", "(", "buf", "[", "offset", ":", "]", ",", "marshalVersion", ")", "\n", "offset", "+=", "2", "\n\n", "binary", ".", "BigEndian", ".", "PutUint32", "(", "buf", "[", "offset", ":", "]", ",", "uint32", "(", "len", "(", "buf", ")", ")", ")", "\n", "offset", "+=", "4", "\n\n", "var", "flags", "uint16", "\n", "if", "h", ".", "sparse", "{", "flags", "|=", "marshalFlagSparse", "\n", "}", "\n\n", "binary", ".", "BigEndian", ".", "PutUint16", "(", "buf", "[", "offset", ":", "]", ",", "flags", ")", "\n", "offset", "+=", "2", "\n\n", "buf", "[", "offset", "]", "=", "h", ".", "p", "\n", "offset", "+=", "1", "\n\n", "buf", "[", "offset", "]", "=", "h", ".", "pp", "\n", "offset", "+=", "1", "\n\n", "binary", ".", "BigEndian", ".", "PutUint32", "(", "buf", "[", "offset", ":", "]", ",", "h", ".", "sparseLength", ")", "\n", "offset", "+=", "4", "\n\n", "buf", "[", "offset", "]", "=", "byte", "(", "h", ".", "bitsPerRegister", ")", "\n", "offset", "+=", "1", "\n\n", "copy", "(", "buf", "[", "offset", ":", "]", ",", "h", ".", "data", ")", "\n\n", "return", "buf", "\n", "}" ]
// Marshal serializes h into a byte slice that can be deserialized via // Unmarshal. The data is naturally compressed, so don't bother trying // to compress it any more.
[ "Marshal", "serializes", "h", "into", "a", "byte", "slice", "that", "can", "be", "deserialized", "via", "Unmarshal", ".", "The", "data", "is", "naturally", "compressed", "so", "don", "t", "bother", "trying", "to", "compress", "it", "any", "more", "." ]
101a6d2f8b52abfc409ac188958e7e7be0116331
https://github.com/retailnext/hllpp/blob/101a6d2f8b52abfc409ac188958e7e7be0116331/marshal.go#L38-L76
12,430
retailnext/hllpp
marshal.go
Unmarshal
func Unmarshal(data []byte) (*HLLPP, error) { if len(data) < marshalHeaderSize { return nil, fmt.Errorf("data too short (%d bytes)", len(data)) } offset := 0 version := binary.BigEndian.Uint16(data[offset:]) offset += 2 if version != marshalVersion { return nil, fmt.Errorf("unknown version: %d", version) } length := binary.BigEndian.Uint32(data[offset:]) offset += 4 if int(length) != len(data) { return nil, fmt.Errorf("length mismatch: header says %d, was %d", length, len(data)) } flags := binary.BigEndian.Uint16(data[offset:]) offset += 2 p := data[offset] offset++ pp := data[offset] offset++ h, err := NewWithConfig(Config{ Precision: p, SparsePrecision: pp, }) if err != nil { return nil, err } h.sparse = flags&marshalFlagSparse > 0 h.sparseLength = binary.BigEndian.Uint32(data[offset:]) offset += 4 h.bitsPerRegister = uint32(data[offset]) offset++ if len(data) > offset { h.data = make([]byte, len(data)-offset) copy(h.data, data[offset:]) } return h, nil }
go
func Unmarshal(data []byte) (*HLLPP, error) { if len(data) < marshalHeaderSize { return nil, fmt.Errorf("data too short (%d bytes)", len(data)) } offset := 0 version := binary.BigEndian.Uint16(data[offset:]) offset += 2 if version != marshalVersion { return nil, fmt.Errorf("unknown version: %d", version) } length := binary.BigEndian.Uint32(data[offset:]) offset += 4 if int(length) != len(data) { return nil, fmt.Errorf("length mismatch: header says %d, was %d", length, len(data)) } flags := binary.BigEndian.Uint16(data[offset:]) offset += 2 p := data[offset] offset++ pp := data[offset] offset++ h, err := NewWithConfig(Config{ Precision: p, SparsePrecision: pp, }) if err != nil { return nil, err } h.sparse = flags&marshalFlagSparse > 0 h.sparseLength = binary.BigEndian.Uint32(data[offset:]) offset += 4 h.bitsPerRegister = uint32(data[offset]) offset++ if len(data) > offset { h.data = make([]byte, len(data)-offset) copy(h.data, data[offset:]) } return h, nil }
[ "func", "Unmarshal", "(", "data", "[", "]", "byte", ")", "(", "*", "HLLPP", ",", "error", ")", "{", "if", "len", "(", "data", ")", "<", "marshalHeaderSize", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "data", ")", ")", "\n", "}", "\n\n", "offset", ":=", "0", "\n\n", "version", ":=", "binary", ".", "BigEndian", ".", "Uint16", "(", "data", "[", "offset", ":", "]", ")", "\n", "offset", "+=", "2", "\n\n", "if", "version", "!=", "marshalVersion", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "version", ")", "\n", "}", "\n\n", "length", ":=", "binary", ".", "BigEndian", ".", "Uint32", "(", "data", "[", "offset", ":", "]", ")", "\n", "offset", "+=", "4", "\n\n", "if", "int", "(", "length", ")", "!=", "len", "(", "data", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "length", ",", "len", "(", "data", ")", ")", "\n", "}", "\n\n", "flags", ":=", "binary", ".", "BigEndian", ".", "Uint16", "(", "data", "[", "offset", ":", "]", ")", "\n", "offset", "+=", "2", "\n\n", "p", ":=", "data", "[", "offset", "]", "\n", "offset", "++", "\n\n", "pp", ":=", "data", "[", "offset", "]", "\n", "offset", "++", "\n\n", "h", ",", "err", ":=", "NewWithConfig", "(", "Config", "{", "Precision", ":", "p", ",", "SparsePrecision", ":", "pp", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "h", ".", "sparse", "=", "flags", "&", "marshalFlagSparse", ">", "0", "\n\n", "h", ".", "sparseLength", "=", "binary", ".", "BigEndian", ".", "Uint32", "(", "data", "[", "offset", ":", "]", ")", "\n", "offset", "+=", "4", "\n\n", "h", ".", "bitsPerRegister", "=", "uint32", "(", "data", "[", "offset", "]", ")", "\n", "offset", "++", "\n\n", "if", "len", "(", "data", ")", ">", "offset", "{", "h", ".", "data", "=", "make", "(", "[", "]", "byte", ",", "len", "(", "data", ")", "-", "offset", ")", "\n", "copy", "(", "h", ".", "data", ",", "data", "[", "offset", ":", "]", ")", "\n", "}", "\n\n", "return", "h", ",", "nil", "\n", "}" ]
// Unmarshal deserializes a byte slice returned by Marshal back into an // HLLPP object.
[ "Unmarshal", "deserializes", "a", "byte", "slice", "returned", "by", "Marshal", "back", "into", "an", "HLLPP", "object", "." ]
101a6d2f8b52abfc409ac188958e7e7be0116331
https://github.com/retailnext/hllpp/blob/101a6d2f8b52abfc409ac188958e7e7be0116331/marshal.go#L80-L132
12,431
retailnext/hllpp
hllpp.go
New
func New() *HLLPP { h, err := NewWithConfig(Config{}) if err != nil { panic(err) } return h }
go
func New() *HLLPP { h, err := NewWithConfig(Config{}) if err != nil { panic(err) } return h }
[ "func", "New", "(", ")", "*", "HLLPP", "{", "h", ",", "err", ":=", "NewWithConfig", "(", "Config", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "h", "\n", "}" ]
// New creates a HyperLogLog++ estimator with p=14, p'=20.
[ "New", "creates", "a", "HyperLogLog", "++", "estimator", "with", "p", "=", "14", "p", "=", "20", "." ]
101a6d2f8b52abfc409ac188958e7e7be0116331
https://github.com/retailnext/hllpp/blob/101a6d2f8b52abfc409ac188958e7e7be0116331/hllpp.go#L46-L52
12,432
retailnext/hllpp
hllpp.go
NewWithConfig
func NewWithConfig(c Config) (*HLLPP, error) { if c.Precision == 0 { c.Precision = 14 } if c.SparsePrecision == 0 { c.SparsePrecision = 20 } p, pp := c.Precision, c.SparsePrecision if p < 4 || p > 16 || pp < p || pp > 25 { return nil, fmt.Errorf("invalid precision (p: %d, p': %d)", p, pp) } return &HLLPP{ p: p, pp: pp, m: 1 << p, mp: 1 << pp, sparse: true, }, nil }
go
func NewWithConfig(c Config) (*HLLPP, error) { if c.Precision == 0 { c.Precision = 14 } if c.SparsePrecision == 0 { c.SparsePrecision = 20 } p, pp := c.Precision, c.SparsePrecision if p < 4 || p > 16 || pp < p || pp > 25 { return nil, fmt.Errorf("invalid precision (p: %d, p': %d)", p, pp) } return &HLLPP{ p: p, pp: pp, m: 1 << p, mp: 1 << pp, sparse: true, }, nil }
[ "func", "NewWithConfig", "(", "c", "Config", ")", "(", "*", "HLLPP", ",", "error", ")", "{", "if", "c", ".", "Precision", "==", "0", "{", "c", ".", "Precision", "=", "14", "\n", "}", "\n\n", "if", "c", ".", "SparsePrecision", "==", "0", "{", "c", ".", "SparsePrecision", "=", "20", "\n", "}", "\n\n", "p", ",", "pp", ":=", "c", ".", "Precision", ",", "c", ".", "SparsePrecision", "\n", "if", "p", "<", "4", "||", "p", ">", "16", "||", "pp", "<", "p", "||", "pp", ">", "25", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "p", ",", "pp", ")", "\n", "}", "\n\n", "return", "&", "HLLPP", "{", "p", ":", "p", ",", "pp", ":", "pp", ",", "m", ":", "1", "<<", "p", ",", "mp", ":", "1", "<<", "pp", ",", "sparse", ":", "true", ",", "}", ",", "nil", "\n", "}" ]
// NewWithConfig creates a HyperLogLog++ estimator with the given Config.
[ "NewWithConfig", "creates", "a", "HyperLogLog", "++", "estimator", "with", "the", "given", "Config", "." ]
101a6d2f8b52abfc409ac188958e7e7be0116331
https://github.com/retailnext/hllpp/blob/101a6d2f8b52abfc409ac188958e7e7be0116331/hllpp.go#L75-L96
12,433
retailnext/hllpp
hllpp.go
Add
func (h *HLLPP) Add(v []byte) { x := murmurSum64(v) if h.sparse { h.tmpSet = append(h.tmpSet, h.encodeHash(x)) // is tmpSet >= 1/4 of memory limit? if 4*uint32(len(h.tmpSet))*8 >= 6*h.m/4 { h.flushTmpSet() } } else { idx := uint32(sliceBits64(x, 63, 64-h.p)) rho := rho(x<<h.p | 1<<(h.p-1)) h.updateRegisterIfBigger(idx, rho) } }
go
func (h *HLLPP) Add(v []byte) { x := murmurSum64(v) if h.sparse { h.tmpSet = append(h.tmpSet, h.encodeHash(x)) // is tmpSet >= 1/4 of memory limit? if 4*uint32(len(h.tmpSet))*8 >= 6*h.m/4 { h.flushTmpSet() } } else { idx := uint32(sliceBits64(x, 63, 64-h.p)) rho := rho(x<<h.p | 1<<(h.p-1)) h.updateRegisterIfBigger(idx, rho) } }
[ "func", "(", "h", "*", "HLLPP", ")", "Add", "(", "v", "[", "]", "byte", ")", "{", "x", ":=", "murmurSum64", "(", "v", ")", "\n\n", "if", "h", ".", "sparse", "{", "h", ".", "tmpSet", "=", "append", "(", "h", ".", "tmpSet", ",", "h", ".", "encodeHash", "(", "x", ")", ")", "\n\n", "// is tmpSet >= 1/4 of memory limit?", "if", "4", "*", "uint32", "(", "len", "(", "h", ".", "tmpSet", ")", ")", "*", "8", ">=", "6", "*", "h", ".", "m", "/", "4", "{", "h", ".", "flushTmpSet", "(", ")", "\n", "}", "\n", "}", "else", "{", "idx", ":=", "uint32", "(", "sliceBits64", "(", "x", ",", "63", ",", "64", "-", "h", ".", "p", ")", ")", "\n", "rho", ":=", "rho", "(", "x", "<<", "h", ".", "p", "|", "1", "<<", "(", "h", ".", "p", "-", "1", ")", ")", "\n", "h", ".", "updateRegisterIfBigger", "(", "idx", ",", "rho", ")", "\n", "}", "\n", "}" ]
// Add will hash v and add the result to the HyperLogLog++ estimator h. hllpp // uses a built-in non-streaming implementation of murmur3.
[ "Add", "will", "hash", "v", "and", "add", "the", "result", "to", "the", "HyperLogLog", "++", "estimator", "h", ".", "hllpp", "uses", "a", "built", "-", "in", "non", "-", "streaming", "implementation", "of", "murmur3", "." ]
101a6d2f8b52abfc409ac188958e7e7be0116331
https://github.com/retailnext/hllpp/blob/101a6d2f8b52abfc409ac188958e7e7be0116331/hllpp.go#L100-L115
12,434
retailnext/hllpp
hllpp.go
Count
func (h *HLLPP) Count() uint64 { if h.sparse { h.flushTmpSet() return linearCounting(h.mp, h.mp-h.sparseLength) } var ( est float64 numZeros uint32 ) for i := uint32(0); i < h.m; i++ { reg := getRegister(h.data, h.bitsPerRegister, i) est += 1.0 / float64(uint64(1)<<reg) if reg == 0 { numZeros++ } } if numZeros > 0 { lc := linearCounting(h.m, numZeros) if lc < threshold[h.p-4] { return lc } } est = alpha(h.m) * float64(h.m) * float64(h.m) / est if est <= float64(h.m*5) { est -= h.estimateBias(est) } return uint64(est + 0.5) }
go
func (h *HLLPP) Count() uint64 { if h.sparse { h.flushTmpSet() return linearCounting(h.mp, h.mp-h.sparseLength) } var ( est float64 numZeros uint32 ) for i := uint32(0); i < h.m; i++ { reg := getRegister(h.data, h.bitsPerRegister, i) est += 1.0 / float64(uint64(1)<<reg) if reg == 0 { numZeros++ } } if numZeros > 0 { lc := linearCounting(h.m, numZeros) if lc < threshold[h.p-4] { return lc } } est = alpha(h.m) * float64(h.m) * float64(h.m) / est if est <= float64(h.m*5) { est -= h.estimateBias(est) } return uint64(est + 0.5) }
[ "func", "(", "h", "*", "HLLPP", ")", "Count", "(", ")", "uint64", "{", "if", "h", ".", "sparse", "{", "h", ".", "flushTmpSet", "(", ")", "\n", "return", "linearCounting", "(", "h", ".", "mp", ",", "h", ".", "mp", "-", "h", ".", "sparseLength", ")", "\n", "}", "\n\n", "var", "(", "est", "float64", "\n", "numZeros", "uint32", "\n", ")", "\n", "for", "i", ":=", "uint32", "(", "0", ")", ";", "i", "<", "h", ".", "m", ";", "i", "++", "{", "reg", ":=", "getRegister", "(", "h", ".", "data", ",", "h", ".", "bitsPerRegister", ",", "i", ")", "\n", "est", "+=", "1.0", "/", "float64", "(", "uint64", "(", "1", ")", "<<", "reg", ")", "\n", "if", "reg", "==", "0", "{", "numZeros", "++", "\n", "}", "\n", "}", "\n\n", "if", "numZeros", ">", "0", "{", "lc", ":=", "linearCounting", "(", "h", ".", "m", ",", "numZeros", ")", "\n", "if", "lc", "<", "threshold", "[", "h", ".", "p", "-", "4", "]", "{", "return", "lc", "\n", "}", "\n", "}", "\n\n", "est", "=", "alpha", "(", "h", ".", "m", ")", "*", "float64", "(", "h", ".", "m", ")", "*", "float64", "(", "h", ".", "m", ")", "/", "est", "\n\n", "if", "est", "<=", "float64", "(", "h", ".", "m", "*", "5", ")", "{", "est", "-=", "h", ".", "estimateBias", "(", "est", ")", "\n", "}", "\n\n", "return", "uint64", "(", "est", "+", "0.5", ")", "\n", "}" ]
// Count returns the current cardinality estimate for h.
[ "Count", "returns", "the", "current", "cardinality", "estimate", "for", "h", "." ]
101a6d2f8b52abfc409ac188958e7e7be0116331
https://github.com/retailnext/hllpp/blob/101a6d2f8b52abfc409ac188958e7e7be0116331/hllpp.go#L133-L165
12,435
retailnext/hllpp
hllpp.go
Merge
func (h *HLLPP) Merge(other *HLLPP) error { if h.p != other.p || h.pp != other.pp { return errors.New("HLLPPs have different parameters") } if h.sparse && !other.sparse { h.toNormal() } if other.sparse { other.flushTmpSet() } if h.sparse && other.sparse { tmpSet := make([]uint32, other.sparseLength) reader := newSparseReader(other.data) for index := 0; !reader.Done(); index++ { tmpSet[index] = reader.Next() } h.mergeSparse(tmpSet) } else if !h.sparse && !other.sparse { for i := uint32(0); i < h.m; i++ { rho := getRegister(other.data, other.bitsPerRegister, i) h.updateRegisterIfBigger(i, rho) } } else { reader := newSparseReader(other.data) for !reader.Done() { idx, rho := other.decodeHash(reader.Next(), other.p) h.updateRegisterIfBigger(idx, rho) } } return nil }
go
func (h *HLLPP) Merge(other *HLLPP) error { if h.p != other.p || h.pp != other.pp { return errors.New("HLLPPs have different parameters") } if h.sparse && !other.sparse { h.toNormal() } if other.sparse { other.flushTmpSet() } if h.sparse && other.sparse { tmpSet := make([]uint32, other.sparseLength) reader := newSparseReader(other.data) for index := 0; !reader.Done(); index++ { tmpSet[index] = reader.Next() } h.mergeSparse(tmpSet) } else if !h.sparse && !other.sparse { for i := uint32(0); i < h.m; i++ { rho := getRegister(other.data, other.bitsPerRegister, i) h.updateRegisterIfBigger(i, rho) } } else { reader := newSparseReader(other.data) for !reader.Done() { idx, rho := other.decodeHash(reader.Next(), other.p) h.updateRegisterIfBigger(idx, rho) } } return nil }
[ "func", "(", "h", "*", "HLLPP", ")", "Merge", "(", "other", "*", "HLLPP", ")", "error", "{", "if", "h", ".", "p", "!=", "other", ".", "p", "||", "h", ".", "pp", "!=", "other", ".", "pp", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "h", ".", "sparse", "&&", "!", "other", ".", "sparse", "{", "h", ".", "toNormal", "(", ")", "\n", "}", "\n\n", "if", "other", ".", "sparse", "{", "other", ".", "flushTmpSet", "(", ")", "\n", "}", "\n\n", "if", "h", ".", "sparse", "&&", "other", ".", "sparse", "{", "tmpSet", ":=", "make", "(", "[", "]", "uint32", ",", "other", ".", "sparseLength", ")", "\n", "reader", ":=", "newSparseReader", "(", "other", ".", "data", ")", "\n", "for", "index", ":=", "0", ";", "!", "reader", ".", "Done", "(", ")", ";", "index", "++", "{", "tmpSet", "[", "index", "]", "=", "reader", ".", "Next", "(", ")", "\n", "}", "\n", "h", ".", "mergeSparse", "(", "tmpSet", ")", "\n", "}", "else", "if", "!", "h", ".", "sparse", "&&", "!", "other", ".", "sparse", "{", "for", "i", ":=", "uint32", "(", "0", ")", ";", "i", "<", "h", ".", "m", ";", "i", "++", "{", "rho", ":=", "getRegister", "(", "other", ".", "data", ",", "other", ".", "bitsPerRegister", ",", "i", ")", "\n", "h", ".", "updateRegisterIfBigger", "(", "i", ",", "rho", ")", "\n", "}", "\n", "}", "else", "{", "reader", ":=", "newSparseReader", "(", "other", ".", "data", ")", "\n", "for", "!", "reader", ".", "Done", "(", ")", "{", "idx", ",", "rho", ":=", "other", ".", "decodeHash", "(", "reader", ".", "Next", "(", ")", ",", "other", ".", "p", ")", "\n", "h", ".", "updateRegisterIfBigger", "(", "idx", ",", "rho", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Merge turns h into the union of h and other. h and other must have the same // p and p' values.
[ "Merge", "turns", "h", "into", "the", "union", "of", "h", "and", "other", ".", "h", "and", "other", "must", "have", "the", "same", "p", "and", "p", "values", "." ]
101a6d2f8b52abfc409ac188958e7e7be0116331
https://github.com/retailnext/hllpp/blob/101a6d2f8b52abfc409ac188958e7e7be0116331/hllpp.go#L169-L203
12,436
performancecopilot/speed
metrics.go
IsCompatible
func (m MetricType) IsCompatible(val interface{}) bool { switch v := val.(type) { case int: return m.isCompatibleInt(v) case int32: return m == Int32Type case int64: return m == Int64Type case uint: return m.isCompatibleUint(v) case uint32: return m == Uint32Type case uint64: return m == Uint64Type case float32: return m == FloatType case float64: return m.isCompatibleFloat(v) case string: return m == StringType } return false }
go
func (m MetricType) IsCompatible(val interface{}) bool { switch v := val.(type) { case int: return m.isCompatibleInt(v) case int32: return m == Int32Type case int64: return m == Int64Type case uint: return m.isCompatibleUint(v) case uint32: return m == Uint32Type case uint64: return m == Uint64Type case float32: return m == FloatType case float64: return m.isCompatibleFloat(v) case string: return m == StringType } return false }
[ "func", "(", "m", "MetricType", ")", "IsCompatible", "(", "val", "interface", "{", "}", ")", "bool", "{", "switch", "v", ":=", "val", ".", "(", "type", ")", "{", "case", "int", ":", "return", "m", ".", "isCompatibleInt", "(", "v", ")", "\n", "case", "int32", ":", "return", "m", "==", "Int32Type", "\n", "case", "int64", ":", "return", "m", "==", "Int64Type", "\n", "case", "uint", ":", "return", "m", ".", "isCompatibleUint", "(", "v", ")", "\n", "case", "uint32", ":", "return", "m", "==", "Uint32Type", "\n", "case", "uint64", ":", "return", "m", "==", "Uint64Type", "\n", "case", "float32", ":", "return", "m", "==", "FloatType", "\n", "case", "float64", ":", "return", "m", ".", "isCompatibleFloat", "(", "v", ")", "\n", "case", "string", ":", "return", "m", "==", "StringType", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsCompatible checks if the passed value is compatible with the current MetricType.
[ "IsCompatible", "checks", "if", "the", "passed", "value", "is", "compatible", "with", "the", "current", "MetricType", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L66-L88
12,437
performancecopilot/speed
metrics.go
resolveInt
func (m MetricType) resolveInt(val interface{}) interface{} { if vi, isInt := val.(int); isInt { switch m { case Int64Type: return int64(vi) case Uint32Type: return uint32(vi) case Uint64Type: return uint64(vi) } return int32(val.(int)) } if vui, isUint := val.(uint); isUint { if m == Uint64Type { return uint64(vui) } return uint32(vui) } return val }
go
func (m MetricType) resolveInt(val interface{}) interface{} { if vi, isInt := val.(int); isInt { switch m { case Int64Type: return int64(vi) case Uint32Type: return uint32(vi) case Uint64Type: return uint64(vi) } return int32(val.(int)) } if vui, isUint := val.(uint); isUint { if m == Uint64Type { return uint64(vui) } return uint32(vui) } return val }
[ "func", "(", "m", "MetricType", ")", "resolveInt", "(", "val", "interface", "{", "}", ")", "interface", "{", "}", "{", "if", "vi", ",", "isInt", ":=", "val", ".", "(", "int", ")", ";", "isInt", "{", "switch", "m", "{", "case", "Int64Type", ":", "return", "int64", "(", "vi", ")", "\n", "case", "Uint32Type", ":", "return", "uint32", "(", "vi", ")", "\n", "case", "Uint64Type", ":", "return", "uint64", "(", "vi", ")", "\n", "}", "\n", "return", "int32", "(", "val", ".", "(", "int", ")", ")", "\n", "}", "\n\n", "if", "vui", ",", "isUint", ":=", "val", ".", "(", "uint", ")", ";", "isUint", "{", "if", "m", "==", "Uint64Type", "{", "return", "uint64", "(", "vui", ")", "\n", "}", "\n", "return", "uint32", "(", "vui", ")", "\n", "}", "\n\n", "return", "val", "\n", "}" ]
// resolveInt will resolve an int to one of the 4 compatible types.
[ "resolveInt", "will", "resolve", "an", "int", "to", "one", "of", "the", "4", "compatible", "types", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L91-L112
12,438
performancecopilot/speed
metrics.go
resolveFloat
func (m MetricType) resolveFloat(val interface{}) interface{} { _, isFloat64 := val.(float64) if isFloat64 && m == FloatType { return float32(val.(float64)) } return val }
go
func (m MetricType) resolveFloat(val interface{}) interface{} { _, isFloat64 := val.(float64) if isFloat64 && m == FloatType { return float32(val.(float64)) } return val }
[ "func", "(", "m", "MetricType", ")", "resolveFloat", "(", "val", "interface", "{", "}", ")", "interface", "{", "}", "{", "_", ",", "isFloat64", ":=", "val", ".", "(", "float64", ")", "\n", "if", "isFloat64", "&&", "m", "==", "FloatType", "{", "return", "float32", "(", "val", ".", "(", "float64", ")", ")", "\n", "}", "\n\n", "return", "val", "\n", "}" ]
// resolveFloat will resolve a float64 to one of the 2 compatible types.
[ "resolveFloat", "will", "resolve", "a", "float64", "to", "one", "of", "the", "2", "compatible", "types", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L115-L122
12,439
performancecopilot/speed
metrics.go
Count
func (t TimeUnit) Count(c CountUnit, dimension int8) MetricUnit { return (&metricUnit{uint32(t)}).Count(c, dimension) }
go
func (t TimeUnit) Count(c CountUnit, dimension int8) MetricUnit { return (&metricUnit{uint32(t)}).Count(c, dimension) }
[ "func", "(", "t", "TimeUnit", ")", "Count", "(", "c", "CountUnit", ",", "dimension", "int8", ")", "MetricUnit", "{", "return", "(", "&", "metricUnit", "{", "uint32", "(", "t", ")", "}", ")", ".", "Count", "(", "c", ",", "dimension", ")", "\n", "}" ]
// Count adds a count unit to the current unit at a specific dimension
[ "Count", "adds", "a", "count", "unit", "to", "the", "current", "unit", "at", "a", "specific", "dimension" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L333-L335
12,440
performancecopilot/speed
metrics.go
newpcpMetricDesc
func newpcpMetricDesc(n string, t MetricType, s MetricSemantics, u MetricUnit, desc ...string) (*pcpMetricDesc, error) { if n == "" { return nil, errors.New("Metric name cannot be empty") } if len(n) > StringLength { return nil, errors.New("metric name is too long") } if len(desc) > 2 { return nil, errors.New("only 2 optional strings allowed, short and long descriptions") } shortdesc, longdesc := "", "" if len(desc) > 0 { shortdesc = desc[0] } if len(desc) > 1 { longdesc = desc[1] } return &pcpMetricDesc{ hash(n, PCPMetricItemBitLength), n, t, s, u, shortdesc, longdesc, }, nil }
go
func newpcpMetricDesc(n string, t MetricType, s MetricSemantics, u MetricUnit, desc ...string) (*pcpMetricDesc, error) { if n == "" { return nil, errors.New("Metric name cannot be empty") } if len(n) > StringLength { return nil, errors.New("metric name is too long") } if len(desc) > 2 { return nil, errors.New("only 2 optional strings allowed, short and long descriptions") } shortdesc, longdesc := "", "" if len(desc) > 0 { shortdesc = desc[0] } if len(desc) > 1 { longdesc = desc[1] } return &pcpMetricDesc{ hash(n, PCPMetricItemBitLength), n, t, s, u, shortdesc, longdesc, }, nil }
[ "func", "newpcpMetricDesc", "(", "n", "string", ",", "t", "MetricType", ",", "s", "MetricSemantics", ",", "u", "MetricUnit", ",", "desc", "...", "string", ")", "(", "*", "pcpMetricDesc", ",", "error", ")", "{", "if", "n", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "n", ")", ">", "StringLength", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "desc", ")", ">", "2", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "shortdesc", ",", "longdesc", ":=", "\"", "\"", ",", "\"", "\"", "\n\n", "if", "len", "(", "desc", ")", ">", "0", "{", "shortdesc", "=", "desc", "[", "0", "]", "\n", "}", "\n\n", "if", "len", "(", "desc", ")", ">", "1", "{", "longdesc", "=", "desc", "[", "1", "]", "\n", "}", "\n\n", "return", "&", "pcpMetricDesc", "{", "hash", "(", "n", ",", "PCPMetricItemBitLength", ")", ",", "n", ",", "t", ",", "s", ",", "u", ",", "shortdesc", ",", "longdesc", ",", "}", ",", "nil", "\n", "}" ]
// newpcpMetricDesc creates a new Metric Description wrapper type.
[ "newpcpMetricDesc", "creates", "a", "new", "Metric", "Description", "wrapper", "type", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L479-L507
12,441
performancecopilot/speed
metrics.go
newupdateClosure
func newupdateClosure(offset int, writer bytewriter.Writer) updateClosure { return func(val interface{}) error { if _, isString := val.(string); isString { writer.MustWrite(make([]byte, StringLength), offset) } _, err := writer.WriteVal(val, offset) return err } }
go
func newupdateClosure(offset int, writer bytewriter.Writer) updateClosure { return func(val interface{}) error { if _, isString := val.(string); isString { writer.MustWrite(make([]byte, StringLength), offset) } _, err := writer.WriteVal(val, offset) return err } }
[ "func", "newupdateClosure", "(", "offset", "int", ",", "writer", "bytewriter", ".", "Writer", ")", "updateClosure", "{", "return", "func", "(", "val", "interface", "{", "}", ")", "error", "{", "if", "_", ",", "isString", ":=", "val", ".", "(", "string", ")", ";", "isString", "{", "writer", ".", "MustWrite", "(", "make", "(", "[", "]", "byte", ",", "StringLength", ")", ",", "offset", ")", "\n", "}", "\n\n", "_", ",", "err", ":=", "writer", ".", "WriteVal", "(", "val", ",", "offset", ")", "\n", "return", "err", "\n", "}", "\n", "}" ]
// newupdateClosure creates a new update closure for an offset, type and buffer.
[ "newupdateClosure", "creates", "a", "new", "update", "closure", "for", "an", "offset", "type", "and", "buffer", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L543-L552
12,442
performancecopilot/speed
metrics.go
newpcpSingletonMetric
func newpcpSingletonMetric(val interface{}, desc *pcpMetricDesc) (*pcpSingletonMetric, error) { if !desc.t.IsCompatible(val) { return nil, errors.Errorf("type %v is not compatible with value %v(%T)", desc.t, val, val) } val = desc.t.resolve(val) return &pcpSingletonMetric{desc, val, nil}, nil }
go
func newpcpSingletonMetric(val interface{}, desc *pcpMetricDesc) (*pcpSingletonMetric, error) { if !desc.t.IsCompatible(val) { return nil, errors.Errorf("type %v is not compatible with value %v(%T)", desc.t, val, val) } val = desc.t.resolve(val) return &pcpSingletonMetric{desc, val, nil}, nil }
[ "func", "newpcpSingletonMetric", "(", "val", "interface", "{", "}", ",", "desc", "*", "pcpMetricDesc", ")", "(", "*", "pcpSingletonMetric", ",", "error", ")", "{", "if", "!", "desc", ".", "t", ".", "IsCompatible", "(", "val", ")", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "desc", ".", "t", ",", "val", ",", "val", ")", "\n", "}", "\n\n", "val", "=", "desc", ".", "t", ".", "resolve", "(", "val", ")", "\n", "return", "&", "pcpSingletonMetric", "{", "desc", ",", "val", ",", "nil", "}", ",", "nil", "\n", "}" ]
// newpcpSingletonMetric creates a new instance of pcpSingletonMetric.
[ "newpcpSingletonMetric", "creates", "a", "new", "instance", "of", "pcpSingletonMetric", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L564-L571
12,443
performancecopilot/speed
metrics.go
set
func (m *pcpSingletonMetric) set(val interface{}) error { if !m.t.IsCompatible(val) { return errors.Errorf("value %v is incompatible with MetricType %v", val, m.t) } val = m.t.resolve(val) if val != m.val { if m.update != nil { err := m.update(val) if err != nil { return err } } m.val = val } return nil }
go
func (m *pcpSingletonMetric) set(val interface{}) error { if !m.t.IsCompatible(val) { return errors.Errorf("value %v is incompatible with MetricType %v", val, m.t) } val = m.t.resolve(val) if val != m.val { if m.update != nil { err := m.update(val) if err != nil { return err } } m.val = val } return nil }
[ "func", "(", "m", "*", "pcpSingletonMetric", ")", "set", "(", "val", "interface", "{", "}", ")", "error", "{", "if", "!", "m", ".", "t", ".", "IsCompatible", "(", "val", ")", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "val", ",", "m", ".", "t", ")", "\n", "}", "\n\n", "val", "=", "m", ".", "t", ".", "resolve", "(", "val", ")", "\n\n", "if", "val", "!=", "m", ".", "val", "{", "if", "m", ".", "update", "!=", "nil", "{", "err", ":=", "m", ".", "update", "(", "val", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "m", ".", "val", "=", "val", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// set Sets the current value of pcpSingletonMetric.
[ "set", "Sets", "the", "current", "value", "of", "pcpSingletonMetric", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L574-L592
12,444
performancecopilot/speed
metrics.go
NewPCPSingletonMetric
func NewPCPSingletonMetric(val interface{}, name string, t MetricType, s MetricSemantics, u MetricUnit, desc ...string) (*PCPSingletonMetric, error) { d, err := newpcpMetricDesc(name, t, s, u, desc...) if err != nil { return nil, err } sm, err := newpcpSingletonMetric(val, d) if err != nil { return nil, err } return &PCPSingletonMetric{sm, sync.RWMutex{}}, nil }
go
func NewPCPSingletonMetric(val interface{}, name string, t MetricType, s MetricSemantics, u MetricUnit, desc ...string) (*PCPSingletonMetric, error) { d, err := newpcpMetricDesc(name, t, s, u, desc...) if err != nil { return nil, err } sm, err := newpcpSingletonMetric(val, d) if err != nil { return nil, err } return &PCPSingletonMetric{sm, sync.RWMutex{}}, nil }
[ "func", "NewPCPSingletonMetric", "(", "val", "interface", "{", "}", ",", "name", "string", ",", "t", "MetricType", ",", "s", "MetricSemantics", ",", "u", "MetricUnit", ",", "desc", "...", "string", ")", "(", "*", "PCPSingletonMetric", ",", "error", ")", "{", "d", ",", "err", ":=", "newpcpMetricDesc", "(", "name", ",", "t", ",", "s", ",", "u", ",", "desc", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "sm", ",", "err", ":=", "newpcpSingletonMetric", "(", "val", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "PCPSingletonMetric", "{", "sm", ",", "sync", ".", "RWMutex", "{", "}", "}", ",", "nil", "\n", "}" ]
// NewPCPSingletonMetric creates a new instance of PCPSingletonMetric // it takes 2 extra optional strings as short and long description parameters, // which on not being present are set to blank strings.
[ "NewPCPSingletonMetric", "creates", "a", "new", "instance", "of", "PCPSingletonMetric", "it", "takes", "2", "extra", "optional", "strings", "as", "short", "and", "long", "description", "parameters", "which", "on", "not", "being", "present", "are", "set", "to", "blank", "strings", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L608-L620
12,445
performancecopilot/speed
metrics.go
Val
func (m *PCPSingletonMetric) Val() interface{} { m.mutex.RLock() defer m.mutex.RUnlock() return m.val }
go
func (m *PCPSingletonMetric) Val() interface{} { m.mutex.RLock() defer m.mutex.RUnlock() return m.val }
[ "func", "(", "m", "*", "PCPSingletonMetric", ")", "Val", "(", ")", "interface", "{", "}", "{", "m", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "m", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "return", "m", ".", "val", "\n", "}" ]
// Val returns the current Set value of PCPSingletonMetric.
[ "Val", "returns", "the", "current", "Set", "value", "of", "PCPSingletonMetric", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L623-L628
12,446
performancecopilot/speed
metrics.go
Set
func (m *PCPSingletonMetric) Set(val interface{}) error { m.mutex.Lock() defer m.mutex.Unlock() return m.set(val) }
go
func (m *PCPSingletonMetric) Set(val interface{}) error { m.mutex.Lock() defer m.mutex.Unlock() return m.set(val) }
[ "func", "(", "m", "*", "PCPSingletonMetric", ")", "Set", "(", "val", "interface", "{", "}", ")", "error", "{", "m", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "return", "m", ".", "set", "(", "val", ")", "\n", "}" ]
// Set Sets the current value of PCPSingletonMetric.
[ "Set", "Sets", "the", "current", "value", "of", "PCPSingletonMetric", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L631-L636
12,447
performancecopilot/speed
metrics.go
MustSet
func (m *PCPSingletonMetric) MustSet(val interface{}) { if err := m.Set(val); err != nil { panic(err) } }
go
func (m *PCPSingletonMetric) MustSet(val interface{}) { if err := m.Set(val); err != nil { panic(err) } }
[ "func", "(", "m", "*", "PCPSingletonMetric", ")", "MustSet", "(", "val", "interface", "{", "}", ")", "{", "if", "err", ":=", "m", ".", "Set", "(", "val", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// MustSet is a Set that panics on failure.
[ "MustSet", "is", "a", "Set", "that", "panics", "on", "failure", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L639-L643
12,448
performancecopilot/speed
metrics.go
NewPCPCounter
func NewPCPCounter(val int64, name string, desc ...string) (*PCPCounter, error) { d, err := newpcpMetricDesc(name, Int64Type, CounterSemantics, OneUnit, desc...) if err != nil { return nil, err } sm, err := newpcpSingletonMetric(val, d) if err != nil { return nil, err } return &PCPCounter{sm, sync.RWMutex{}}, nil }
go
func NewPCPCounter(val int64, name string, desc ...string) (*PCPCounter, error) { d, err := newpcpMetricDesc(name, Int64Type, CounterSemantics, OneUnit, desc...) if err != nil { return nil, err } sm, err := newpcpSingletonMetric(val, d) if err != nil { return nil, err } return &PCPCounter{sm, sync.RWMutex{}}, nil }
[ "func", "NewPCPCounter", "(", "val", "int64", ",", "name", "string", ",", "desc", "...", "string", ")", "(", "*", "PCPCounter", ",", "error", ")", "{", "d", ",", "err", ":=", "newpcpMetricDesc", "(", "name", ",", "Int64Type", ",", "CounterSemantics", ",", "OneUnit", ",", "desc", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "sm", ",", "err", ":=", "newpcpSingletonMetric", "(", "val", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "PCPCounter", "{", "sm", ",", "sync", ".", "RWMutex", "{", "}", "}", ",", "nil", "\n", "}" ]
// NewPCPCounter creates a new PCPCounter instance. // It requires an initial int64 value and a metric name for construction. // optionally it can also take a couple of description strings that are used as // short and long descriptions respectively. // Internally it creates a PCP SingletonMetric with Int64Type, CounterSemantics // and CountUnit.
[ "NewPCPCounter", "creates", "a", "new", "PCPCounter", "instance", ".", "It", "requires", "an", "initial", "int64", "value", "and", "a", "metric", "name", "for", "construction", ".", "optionally", "it", "can", "also", "take", "a", "couple", "of", "description", "strings", "that", "are", "used", "as", "short", "and", "long", "descriptions", "respectively", ".", "Internally", "it", "creates", "a", "PCP", "SingletonMetric", "with", "Int64Type", "CounterSemantics", "and", "CountUnit", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L678-L690
12,449
performancecopilot/speed
metrics.go
Val
func (c *PCPCounter) Val() int64 { c.mutex.RLock() defer c.mutex.RUnlock() return c.val.(int64) }
go
func (c *PCPCounter) Val() int64 { c.mutex.RLock() defer c.mutex.RUnlock() return c.val.(int64) }
[ "func", "(", "c", "*", "PCPCounter", ")", "Val", "(", ")", "int64", "{", "c", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "return", "c", ".", "val", ".", "(", "int64", ")", "\n", "}" ]
// Val returns the current value of the counter.
[ "Val", "returns", "the", "current", "value", "of", "the", "counter", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L693-L698
12,450
performancecopilot/speed
metrics.go
Set
func (c *PCPCounter) Set(val int64) error { c.mutex.Lock() defer c.mutex.Unlock() v := c.val.(int64) if val < v { return errors.Errorf("cannot set counter to %v, current value is %v and PCP counters cannot go backwards", val, v) } return c.set(val) }
go
func (c *PCPCounter) Set(val int64) error { c.mutex.Lock() defer c.mutex.Unlock() v := c.val.(int64) if val < v { return errors.Errorf("cannot set counter to %v, current value is %v and PCP counters cannot go backwards", val, v) } return c.set(val) }
[ "func", "(", "c", "*", "PCPCounter", ")", "Set", "(", "val", "int64", ")", "error", "{", "c", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "v", ":=", "c", ".", "val", ".", "(", "int64", ")", "\n\n", "if", "val", "<", "v", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "val", ",", "v", ")", "\n", "}", "\n\n", "return", "c", ".", "set", "(", "val", ")", "\n", "}" ]
// Set sets the value of the counter.
[ "Set", "sets", "the", "value", "of", "the", "counter", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L701-L712
12,451
performancecopilot/speed
metrics.go
Inc
func (c *PCPCounter) Inc(val int64) error { c.mutex.Lock() defer c.mutex.Unlock() if val < 0 { return errors.New("cannot decrement a counter") } if val == 0 { return nil } v := c.val.(int64) v += val return c.set(v) }
go
func (c *PCPCounter) Inc(val int64) error { c.mutex.Lock() defer c.mutex.Unlock() if val < 0 { return errors.New("cannot decrement a counter") } if val == 0 { return nil } v := c.val.(int64) v += val return c.set(v) }
[ "func", "(", "c", "*", "PCPCounter", ")", "Inc", "(", "val", "int64", ")", "error", "{", "c", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "if", "val", "<", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "val", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "v", ":=", "c", ".", "val", ".", "(", "int64", ")", "\n", "v", "+=", "val", "\n", "return", "c", ".", "set", "(", "v", ")", "\n", "}" ]
// Inc increases the stored counter's value by the passed increment.
[ "Inc", "increases", "the", "stored", "counter", "s", "value", "by", "the", "passed", "increment", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L715-L730
12,452
performancecopilot/speed
metrics.go
MustInc
func (c *PCPCounter) MustInc(val int64) { if err := c.Inc(val); err != nil { panic(err) } }
go
func (c *PCPCounter) MustInc(val int64) { if err := c.Inc(val); err != nil { panic(err) } }
[ "func", "(", "c", "*", "PCPCounter", ")", "MustInc", "(", "val", "int64", ")", "{", "if", "err", ":=", "c", ".", "Inc", "(", "val", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// MustInc is Inc that panics on failure.
[ "MustInc", "is", "Inc", "that", "panics", "on", "failure", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L733-L737
12,453
performancecopilot/speed
metrics.go
NewPCPGauge
func NewPCPGauge(val float64, name string, desc ...string) (*PCPGauge, error) { d, err := newpcpMetricDesc(name, DoubleType, InstantSemantics, OneUnit, desc...) if err != nil { return nil, err } sm, err := newpcpSingletonMetric(val, d) if err != nil { return nil, err } return &PCPGauge{sm, sync.RWMutex{}}, nil }
go
func NewPCPGauge(val float64, name string, desc ...string) (*PCPGauge, error) { d, err := newpcpMetricDesc(name, DoubleType, InstantSemantics, OneUnit, desc...) if err != nil { return nil, err } sm, err := newpcpSingletonMetric(val, d) if err != nil { return nil, err } return &PCPGauge{sm, sync.RWMutex{}}, nil }
[ "func", "NewPCPGauge", "(", "val", "float64", ",", "name", "string", ",", "desc", "...", "string", ")", "(", "*", "PCPGauge", ",", "error", ")", "{", "d", ",", "err", ":=", "newpcpMetricDesc", "(", "name", ",", "DoubleType", ",", "InstantSemantics", ",", "OneUnit", ",", "desc", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "sm", ",", "err", ":=", "newpcpSingletonMetric", "(", "val", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "PCPGauge", "{", "sm", ",", "sync", ".", "RWMutex", "{", "}", "}", ",", "nil", "\n", "}" ]
// NewPCPGauge creates a new PCPGauge instance. // Tt requires an initial float64 value and a metric name for construction. // Optionally it can also take a couple of description strings that are used as // short and long descriptions respectively. // Internally it creates a PCP SingletonMetric with DoubleType, InstantSemantics // and CountUnit.
[ "NewPCPGauge", "creates", "a", "new", "PCPGauge", "instance", ".", "Tt", "requires", "an", "initial", "float64", "value", "and", "a", "metric", "name", "for", "construction", ".", "Optionally", "it", "can", "also", "take", "a", "couple", "of", "description", "strings", "that", "are", "used", "as", "short", "and", "long", "descriptions", "respectively", ".", "Internally", "it", "creates", "a", "PCP", "SingletonMetric", "with", "DoubleType", "InstantSemantics", "and", "CountUnit", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L775-L787
12,454
performancecopilot/speed
metrics.go
Val
func (g *PCPGauge) Val() float64 { g.mutex.RLock() defer g.mutex.RUnlock() return g.val.(float64) }
go
func (g *PCPGauge) Val() float64 { g.mutex.RLock() defer g.mutex.RUnlock() return g.val.(float64) }
[ "func", "(", "g", "*", "PCPGauge", ")", "Val", "(", ")", "float64", "{", "g", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "g", ".", "val", ".", "(", "float64", ")", "\n", "}" ]
// Val returns the current value of the Gauge.
[ "Val", "returns", "the", "current", "value", "of", "the", "Gauge", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L790-L794
12,455
performancecopilot/speed
metrics.go
Set
func (g *PCPGauge) Set(val float64) error { g.mutex.Lock() defer g.mutex.Unlock() return g.set(val) }
go
func (g *PCPGauge) Set(val float64) error { g.mutex.Lock() defer g.mutex.Unlock() return g.set(val) }
[ "func", "(", "g", "*", "PCPGauge", ")", "Set", "(", "val", "float64", ")", "error", "{", "g", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "Unlock", "(", ")", "\n", "return", "g", ".", "set", "(", "val", ")", "\n", "}" ]
// Set sets the current value of the Gauge.
[ "Set", "sets", "the", "current", "value", "of", "the", "Gauge", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L797-L801
12,456
performancecopilot/speed
metrics.go
MustSet
func (g *PCPGauge) MustSet(val float64) { if err := g.Set(val); err != nil { panic(err) } }
go
func (g *PCPGauge) MustSet(val float64) { if err := g.Set(val); err != nil { panic(err) } }
[ "func", "(", "g", "*", "PCPGauge", ")", "MustSet", "(", "val", "float64", ")", "{", "if", "err", ":=", "g", ".", "Set", "(", "val", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// MustSet will panic if Set fails.
[ "MustSet", "will", "panic", "if", "Set", "fails", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L804-L808
12,457
performancecopilot/speed
metrics.go
Inc
func (g *PCPGauge) Inc(val float64) error { g.mutex.Lock() defer g.mutex.Unlock() if val == 0 { return nil } v := g.val.(float64) return g.set(v + val) }
go
func (g *PCPGauge) Inc(val float64) error { g.mutex.Lock() defer g.mutex.Unlock() if val == 0 { return nil } v := g.val.(float64) return g.set(v + val) }
[ "func", "(", "g", "*", "PCPGauge", ")", "Inc", "(", "val", "float64", ")", "error", "{", "g", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "if", "val", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "v", ":=", "g", ".", "val", ".", "(", "float64", ")", "\n", "return", "g", ".", "set", "(", "v", "+", "val", ")", "\n", "}" ]
// Inc adds a value to the existing Gauge value.
[ "Inc", "adds", "a", "value", "to", "the", "existing", "Gauge", "value", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L811-L821
12,458
performancecopilot/speed
metrics.go
MustInc
func (g *PCPGauge) MustInc(val float64) { if err := g.Inc(val); err != nil { panic(err) } }
go
func (g *PCPGauge) MustInc(val float64) { if err := g.Inc(val); err != nil { panic(err) } }
[ "func", "(", "g", "*", "PCPGauge", ")", "MustInc", "(", "val", "float64", ")", "{", "if", "err", ":=", "g", ".", "Inc", "(", "val", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// MustInc will panic if Inc fails.
[ "MustInc", "will", "panic", "if", "Inc", "fails", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L824-L828
12,459
performancecopilot/speed
metrics.go
MustDec
func (g *PCPGauge) MustDec(val float64) { if err := g.Dec(val); err != nil { panic(err) } }
go
func (g *PCPGauge) MustDec(val float64) { if err := g.Dec(val); err != nil { panic(err) } }
[ "func", "(", "g", "*", "PCPGauge", ")", "MustDec", "(", "val", "float64", ")", "{", "if", "err", ":=", "g", ".", "Dec", "(", "val", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// MustDec will panic if Dec fails.
[ "MustDec", "will", "panic", "if", "Dec", "fails", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L836-L840
12,460
performancecopilot/speed
metrics.go
NewPCPTimer
func NewPCPTimer(name string, unit TimeUnit, desc ...string) (*PCPTimer, error) { d, err := newpcpMetricDesc(name, DoubleType, DiscreteSemantics, unit, desc...) if err != nil { return nil, err } sm, err := newpcpSingletonMetric(float64(0), d) if err != nil { return nil, err } return &PCPTimer{sm, sync.Mutex{}, false, time.Time{}}, nil }
go
func NewPCPTimer(name string, unit TimeUnit, desc ...string) (*PCPTimer, error) { d, err := newpcpMetricDesc(name, DoubleType, DiscreteSemantics, unit, desc...) if err != nil { return nil, err } sm, err := newpcpSingletonMetric(float64(0), d) if err != nil { return nil, err } return &PCPTimer{sm, sync.Mutex{}, false, time.Time{}}, nil }
[ "func", "NewPCPTimer", "(", "name", "string", ",", "unit", "TimeUnit", ",", "desc", "...", "string", ")", "(", "*", "PCPTimer", ",", "error", ")", "{", "d", ",", "err", ":=", "newpcpMetricDesc", "(", "name", ",", "DoubleType", ",", "DiscreteSemantics", ",", "unit", ",", "desc", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "sm", ",", "err", ":=", "newpcpSingletonMetric", "(", "float64", "(", "0", ")", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "PCPTimer", "{", "sm", ",", "sync", ".", "Mutex", "{", "}", ",", "false", ",", "time", ".", "Time", "{", "}", "}", ",", "nil", "\n", "}" ]
// NewPCPTimer creates a new PCPTimer instance of the specified unit. // It requires a metric name and a TimeUnit for construction. // It can optionally take a couple of description strings. // Internally it uses a PCP SingletonMetric.
[ "NewPCPTimer", "creates", "a", "new", "PCPTimer", "instance", "of", "the", "specified", "unit", ".", "It", "requires", "a", "metric", "name", "and", "a", "TimeUnit", "for", "construction", ".", "It", "can", "optionally", "take", "a", "couple", "of", "description", "strings", ".", "Internally", "it", "uses", "a", "PCP", "SingletonMetric", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L870-L882
12,461
performancecopilot/speed
metrics.go
Reset
func (t *PCPTimer) Reset() error { t.mutex.Lock() defer t.mutex.Unlock() if t.started { return errors.New("trying to reset an already started timer") } return t.set(float64(0)) }
go
func (t *PCPTimer) Reset() error { t.mutex.Lock() defer t.mutex.Unlock() if t.started { return errors.New("trying to reset an already started timer") } return t.set(float64(0)) }
[ "func", "(", "t", "*", "PCPTimer", ")", "Reset", "(", ")", "error", "{", "t", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "t", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "if", "t", ".", "started", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "t", ".", "set", "(", "float64", "(", "0", ")", ")", "\n", "}" ]
// Reset resets the timer to 0
[ "Reset", "resets", "the", "timer", "to", "0" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L885-L894
12,462
performancecopilot/speed
metrics.go
Start
func (t *PCPTimer) Start() error { t.mutex.Lock() defer t.mutex.Unlock() if t.started { return errors.New("trying to start an already started timer") } t.since = time.Now() t.started = true return nil }
go
func (t *PCPTimer) Start() error { t.mutex.Lock() defer t.mutex.Unlock() if t.started { return errors.New("trying to start an already started timer") } t.since = time.Now() t.started = true return nil }
[ "func", "(", "t", "*", "PCPTimer", ")", "Start", "(", ")", "error", "{", "t", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "t", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "if", "t", ".", "started", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "t", ".", "since", "=", "time", ".", "Now", "(", ")", "\n", "t", ".", "started", "=", "true", "\n", "return", "nil", "\n", "}" ]
// Start signals the timer to start monitoring.
[ "Start", "signals", "the", "timer", "to", "start", "monitoring", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L897-L908
12,463
performancecopilot/speed
metrics.go
Stop
func (t *PCPTimer) Stop() (float64, error) { t.mutex.Lock() defer t.mutex.Unlock() if !t.started { return 0, errors.New("trying to stop a stopped timer") } d := time.Since(t.since) var inc float64 switch t.pcpMetricDesc.Unit() { case NanosecondUnit: inc = float64(d.Nanoseconds()) case MicrosecondUnit: inc = float64(d.Nanoseconds()) * 1e-3 case MillisecondUnit: inc = float64(d.Nanoseconds()) * 1e-6 case SecondUnit: inc = d.Seconds() case MinuteUnit: inc = d.Minutes() case HourUnit: inc = d.Hours() } v := t.val.(float64) err := t.set(v + inc) if err != nil { return -1, err } t.started = false return v + inc, nil }
go
func (t *PCPTimer) Stop() (float64, error) { t.mutex.Lock() defer t.mutex.Unlock() if !t.started { return 0, errors.New("trying to stop a stopped timer") } d := time.Since(t.since) var inc float64 switch t.pcpMetricDesc.Unit() { case NanosecondUnit: inc = float64(d.Nanoseconds()) case MicrosecondUnit: inc = float64(d.Nanoseconds()) * 1e-3 case MillisecondUnit: inc = float64(d.Nanoseconds()) * 1e-6 case SecondUnit: inc = d.Seconds() case MinuteUnit: inc = d.Minutes() case HourUnit: inc = d.Hours() } v := t.val.(float64) err := t.set(v + inc) if err != nil { return -1, err } t.started = false return v + inc, nil }
[ "func", "(", "t", "*", "PCPTimer", ")", "Stop", "(", ")", "(", "float64", ",", "error", ")", "{", "t", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "t", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "if", "!", "t", ".", "started", "{", "return", "0", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "d", ":=", "time", ".", "Since", "(", "t", ".", "since", ")", "\n\n", "var", "inc", "float64", "\n", "switch", "t", ".", "pcpMetricDesc", ".", "Unit", "(", ")", "{", "case", "NanosecondUnit", ":", "inc", "=", "float64", "(", "d", ".", "Nanoseconds", "(", ")", ")", "\n", "case", "MicrosecondUnit", ":", "inc", "=", "float64", "(", "d", ".", "Nanoseconds", "(", ")", ")", "*", "1e-3", "\n", "case", "MillisecondUnit", ":", "inc", "=", "float64", "(", "d", ".", "Nanoseconds", "(", ")", ")", "*", "1e-6", "\n", "case", "SecondUnit", ":", "inc", "=", "d", ".", "Seconds", "(", ")", "\n", "case", "MinuteUnit", ":", "inc", "=", "d", ".", "Minutes", "(", ")", "\n", "case", "HourUnit", ":", "inc", "=", "d", ".", "Hours", "(", ")", "\n", "}", "\n\n", "v", ":=", "t", ".", "val", ".", "(", "float64", ")", "\n\n", "err", ":=", "t", ".", "set", "(", "v", "+", "inc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "t", ".", "started", "=", "false", "\n", "return", "v", "+", "inc", ",", "nil", "\n", "}" ]
// Stop signals the timer to end monitoring and return elapsed time so far.
[ "Stop", "signals", "the", "timer", "to", "end", "monitoring", "and", "return", "elapsed", "time", "so", "far", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L911-L946
12,464
performancecopilot/speed
metrics.go
newpcpInstanceMetric
func newpcpInstanceMetric(vals Instances, indom *PCPInstanceDomain, desc *pcpMetricDesc) (*pcpInstanceMetric, error) { if len(vals) != indom.InstanceCount() { return nil, errors.New("values for all instances in the instance domain only should be passed") } mvals := make(map[string]*instanceValue) for name := range indom.instances { val, present := vals[name] if !present { return nil, errors.Errorf("Instance %v not initialized", name) } if !desc.t.IsCompatible(val) { return nil, errors.Errorf("value %v is incompatible with type %v for Instance %v", val, desc.t, name) } val = desc.t.resolve(val) mvals[name] = newinstanceValue(val) } return &pcpInstanceMetric{desc, indom, mvals}, nil }
go
func newpcpInstanceMetric(vals Instances, indom *PCPInstanceDomain, desc *pcpMetricDesc) (*pcpInstanceMetric, error) { if len(vals) != indom.InstanceCount() { return nil, errors.New("values for all instances in the instance domain only should be passed") } mvals := make(map[string]*instanceValue) for name := range indom.instances { val, present := vals[name] if !present { return nil, errors.Errorf("Instance %v not initialized", name) } if !desc.t.IsCompatible(val) { return nil, errors.Errorf("value %v is incompatible with type %v for Instance %v", val, desc.t, name) } val = desc.t.resolve(val) mvals[name] = newinstanceValue(val) } return &pcpInstanceMetric{desc, indom, mvals}, nil }
[ "func", "newpcpInstanceMetric", "(", "vals", "Instances", ",", "indom", "*", "PCPInstanceDomain", ",", "desc", "*", "pcpMetricDesc", ")", "(", "*", "pcpInstanceMetric", ",", "error", ")", "{", "if", "len", "(", "vals", ")", "!=", "indom", ".", "InstanceCount", "(", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "mvals", ":=", "make", "(", "map", "[", "string", "]", "*", "instanceValue", ")", "\n\n", "for", "name", ":=", "range", "indom", ".", "instances", "{", "val", ",", "present", ":=", "vals", "[", "name", "]", "\n", "if", "!", "present", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n\n", "if", "!", "desc", ".", "t", ".", "IsCompatible", "(", "val", ")", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "val", ",", "desc", ".", "t", ",", "name", ")", "\n", "}", "\n\n", "val", "=", "desc", ".", "t", ".", "resolve", "(", "val", ")", "\n", "mvals", "[", "name", "]", "=", "newinstanceValue", "(", "val", ")", "\n", "}", "\n\n", "return", "&", "pcpInstanceMetric", "{", "desc", ",", "indom", ",", "mvals", "}", ",", "nil", "\n", "}" ]
// newpcpInstanceMetric creates a new instance of PCPSingletonMetric.
[ "newpcpInstanceMetric", "creates", "a", "new", "instance", "of", "PCPSingletonMetric", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L968-L990
12,465
performancecopilot/speed
metrics.go
setInstance
func (m *pcpInstanceMetric) setInstance(val interface{}, instance string) error { if !m.t.IsCompatible(val) { return errors.New("the value is incompatible with this metrics MetricType") } if !m.indom.HasInstance(instance) { return errors.Errorf("%v is not an instance of this metric", instance) } val = m.t.resolve(val) if m.vals[instance].val != val { if m.vals[instance].update != nil { err := m.vals[instance].update(val) if err != nil { return err } } m.vals[instance].val = val } return nil }
go
func (m *pcpInstanceMetric) setInstance(val interface{}, instance string) error { if !m.t.IsCompatible(val) { return errors.New("the value is incompatible with this metrics MetricType") } if !m.indom.HasInstance(instance) { return errors.Errorf("%v is not an instance of this metric", instance) } val = m.t.resolve(val) if m.vals[instance].val != val { if m.vals[instance].update != nil { err := m.vals[instance].update(val) if err != nil { return err } } m.vals[instance].val = val } return nil }
[ "func", "(", "m", "*", "pcpInstanceMetric", ")", "setInstance", "(", "val", "interface", "{", "}", ",", "instance", "string", ")", "error", "{", "if", "!", "m", ".", "t", ".", "IsCompatible", "(", "val", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "!", "m", ".", "indom", ".", "HasInstance", "(", "instance", ")", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "instance", ")", "\n", "}", "\n\n", "val", "=", "m", ".", "t", ".", "resolve", "(", "val", ")", "\n\n", "if", "m", ".", "vals", "[", "instance", "]", ".", "val", "!=", "val", "{", "if", "m", ".", "vals", "[", "instance", "]", ".", "update", "!=", "nil", "{", "err", ":=", "m", ".", "vals", "[", "instance", "]", ".", "update", "(", "val", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "m", ".", "vals", "[", "instance", "]", ".", "val", "=", "val", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// setInstance sets the value for a particular instance of the metric.
[ "setInstance", "sets", "the", "value", "for", "a", "particular", "instance", "of", "the", "metric", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1001-L1024
12,466
performancecopilot/speed
metrics.go
NewPCPInstanceMetric
func NewPCPInstanceMetric(vals Instances, name string, indom *PCPInstanceDomain, t MetricType, s MetricSemantics, u MetricUnit, desc ...string) (*PCPInstanceMetric, error) { d, err := newpcpMetricDesc(name, t, s, u, desc...) if err != nil { return nil, err } im, err := newpcpInstanceMetric(vals, indom, d) if err != nil { return nil, err } return &PCPInstanceMetric{im, sync.RWMutex{}}, nil }
go
func NewPCPInstanceMetric(vals Instances, name string, indom *PCPInstanceDomain, t MetricType, s MetricSemantics, u MetricUnit, desc ...string) (*PCPInstanceMetric, error) { d, err := newpcpMetricDesc(name, t, s, u, desc...) if err != nil { return nil, err } im, err := newpcpInstanceMetric(vals, indom, d) if err != nil { return nil, err } return &PCPInstanceMetric{im, sync.RWMutex{}}, nil }
[ "func", "NewPCPInstanceMetric", "(", "vals", "Instances", ",", "name", "string", ",", "indom", "*", "PCPInstanceDomain", ",", "t", "MetricType", ",", "s", "MetricSemantics", ",", "u", "MetricUnit", ",", "desc", "...", "string", ")", "(", "*", "PCPInstanceMetric", ",", "error", ")", "{", "d", ",", "err", ":=", "newpcpMetricDesc", "(", "name", ",", "t", ",", "s", ",", "u", ",", "desc", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "im", ",", "err", ":=", "newpcpInstanceMetric", "(", "vals", ",", "indom", ",", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "PCPInstanceMetric", "{", "im", ",", "sync", ".", "RWMutex", "{", "}", "}", ",", "nil", "\n", "}" ]
// NewPCPInstanceMetric creates a new instance of PCPSingletonMetric. // it takes 2 extra optional strings as short and long description parameters, // which on not being present are set to empty strings.
[ "NewPCPInstanceMetric", "creates", "a", "new", "instance", "of", "PCPSingletonMetric", ".", "it", "takes", "2", "extra", "optional", "strings", "as", "short", "and", "long", "description", "parameters", "which", "on", "not", "being", "present", "are", "set", "to", "empty", "strings", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1045-L1057
12,467
performancecopilot/speed
metrics.go
ValInstance
func (m *PCPInstanceMetric) ValInstance(instance string) (interface{}, error) { m.mutex.RLock() defer m.mutex.RUnlock() return m.valInstance(instance) }
go
func (m *PCPInstanceMetric) ValInstance(instance string) (interface{}, error) { m.mutex.RLock() defer m.mutex.RUnlock() return m.valInstance(instance) }
[ "func", "(", "m", "*", "PCPInstanceMetric", ")", "ValInstance", "(", "instance", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "m", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "m", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "return", "m", ".", "valInstance", "(", "instance", ")", "\n", "}" ]
// ValInstance returns the value for a particular instance of the metric.
[ "ValInstance", "returns", "the", "value", "for", "a", "particular", "instance", "of", "the", "metric", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1060-L1065
12,468
performancecopilot/speed
metrics.go
SetInstance
func (m *PCPInstanceMetric) SetInstance(val interface{}, instance string) error { m.mutex.Lock() defer m.mutex.Unlock() return m.setInstance(val, instance) }
go
func (m *PCPInstanceMetric) SetInstance(val interface{}, instance string) error { m.mutex.Lock() defer m.mutex.Unlock() return m.setInstance(val, instance) }
[ "func", "(", "m", "*", "PCPInstanceMetric", ")", "SetInstance", "(", "val", "interface", "{", "}", ",", "instance", "string", ")", "error", "{", "m", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "return", "m", ".", "setInstance", "(", "val", ",", "instance", ")", "\n", "}" ]
// SetInstance sets the value for a particular instance of the metric.
[ "SetInstance", "sets", "the", "value", "for", "a", "particular", "instance", "of", "the", "metric", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1068-L1073
12,469
performancecopilot/speed
metrics.go
MustSetInstance
func (m *PCPInstanceMetric) MustSetInstance(val interface{}, instance string) { if err := m.SetInstance(val, instance); err != nil { panic(err) } }
go
func (m *PCPInstanceMetric) MustSetInstance(val interface{}, instance string) { if err := m.SetInstance(val, instance); err != nil { panic(err) } }
[ "func", "(", "m", "*", "PCPInstanceMetric", ")", "MustSetInstance", "(", "val", "interface", "{", "}", ",", "instance", "string", ")", "{", "if", "err", ":=", "m", ".", "SetInstance", "(", "val", ",", "instance", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// MustSetInstance is a SetInstance that panics.
[ "MustSetInstance", "is", "a", "SetInstance", "that", "panics", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1076-L1080
12,470
performancecopilot/speed
metrics.go
NewPCPCounterVector
func NewPCPCounterVector(values map[string]int64, name string, desc ...string) (*PCPCounterVector, error) { vals := make(Instances) for k, v := range values { vals[k] = v } im, err := generateInstanceMetric(vals, name, vals.Keys(), Int64Type, CounterSemantics, OneUnit, desc...) if err != nil { return nil, err } return &PCPCounterVector{im, sync.RWMutex{}}, nil }
go
func NewPCPCounterVector(values map[string]int64, name string, desc ...string) (*PCPCounterVector, error) { vals := make(Instances) for k, v := range values { vals[k] = v } im, err := generateInstanceMetric(vals, name, vals.Keys(), Int64Type, CounterSemantics, OneUnit, desc...) if err != nil { return nil, err } return &PCPCounterVector{im, sync.RWMutex{}}, nil }
[ "func", "NewPCPCounterVector", "(", "values", "map", "[", "string", "]", "int64", ",", "name", "string", ",", "desc", "...", "string", ")", "(", "*", "PCPCounterVector", ",", "error", ")", "{", "vals", ":=", "make", "(", "Instances", ")", "\n", "for", "k", ",", "v", ":=", "range", "values", "{", "vals", "[", "k", "]", "=", "v", "\n", "}", "\n\n", "im", ",", "err", ":=", "generateInstanceMetric", "(", "vals", ",", "name", ",", "vals", ".", "Keys", "(", ")", ",", "Int64Type", ",", "CounterSemantics", ",", "OneUnit", ",", "desc", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "PCPCounterVector", "{", "im", ",", "sync", ".", "RWMutex", "{", "}", "}", ",", "nil", "\n", "}" ]
// NewPCPCounterVector creates a new instance of a PCPCounterVector. // it requires a metric name and a set of instance names and values as a map. // it can optionally accept a couple of strings as short and long descriptions // of the metric. // Internally it uses a PCP InstanceMetric with Int64Type, CounterSemantics and CountUnit.
[ "NewPCPCounterVector", "creates", "a", "new", "instance", "of", "a", "PCPCounterVector", ".", "it", "requires", "a", "metric", "name", "and", "a", "set", "of", "instance", "names", "and", "values", "as", "a", "map", ".", "it", "can", "optionally", "accept", "a", "couple", "of", "strings", "as", "short", "and", "long", "descriptions", "of", "the", "metric", ".", "Internally", "it", "uses", "a", "PCP", "InstanceMetric", "with", "Int64Type", "CounterSemantics", "and", "CountUnit", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1130-L1142
12,471
performancecopilot/speed
metrics.go
Val
func (c *PCPCounterVector) Val(instance string) (int64, error) { c.mutex.RLock() defer c.mutex.RUnlock() v, err := c.valInstance(instance) if err != nil { return 0, err } return v.(int64), nil }
go
func (c *PCPCounterVector) Val(instance string) (int64, error) { c.mutex.RLock() defer c.mutex.RUnlock() v, err := c.valInstance(instance) if err != nil { return 0, err } return v.(int64), nil }
[ "func", "(", "c", "*", "PCPCounterVector", ")", "Val", "(", "instance", "string", ")", "(", "int64", ",", "error", ")", "{", "c", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "v", ",", "err", ":=", "c", ".", "valInstance", "(", "instance", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "v", ".", "(", "int64", ")", ",", "nil", "\n", "}" ]
// Val returns the value of a particular instance of PCPCounterVector.
[ "Val", "returns", "the", "value", "of", "a", "particular", "instance", "of", "PCPCounterVector", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1145-L1155
12,472
performancecopilot/speed
metrics.go
Set
func (c *PCPCounterVector) Set(val int64, instance string) error { c.mutex.Lock() defer c.mutex.Unlock() v, err := c.valInstance(instance) if err != nil { return err } if val < v.(int64) { return errors.Errorf("cannot set instance %s to a lesser value %v", instance, val) } return c.setInstance(val, instance) }
go
func (c *PCPCounterVector) Set(val int64, instance string) error { c.mutex.Lock() defer c.mutex.Unlock() v, err := c.valInstance(instance) if err != nil { return err } if val < v.(int64) { return errors.Errorf("cannot set instance %s to a lesser value %v", instance, val) } return c.setInstance(val, instance) }
[ "func", "(", "c", "*", "PCPCounterVector", ")", "Set", "(", "val", "int64", ",", "instance", "string", ")", "error", "{", "c", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "v", ",", "err", ":=", "c", ".", "valInstance", "(", "instance", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "val", "<", "v", ".", "(", "int64", ")", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "instance", ",", "val", ")", "\n", "}", "\n\n", "return", "c", ".", "setInstance", "(", "val", ",", "instance", ")", "\n", "}" ]
// Set sets the value of a particular instance of PCPCounterVector.
[ "Set", "sets", "the", "value", "of", "a", "particular", "instance", "of", "PCPCounterVector", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1158-L1172
12,473
performancecopilot/speed
metrics.go
MustSet
func (c *PCPCounterVector) MustSet(val int64, instance string) { if err := c.Set(val, instance); err != nil { panic(err) } }
go
func (c *PCPCounterVector) MustSet(val int64, instance string) { if err := c.Set(val, instance); err != nil { panic(err) } }
[ "func", "(", "c", "*", "PCPCounterVector", ")", "MustSet", "(", "val", "int64", ",", "instance", "string", ")", "{", "if", "err", ":=", "c", ".", "Set", "(", "val", ",", "instance", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// MustSet panics if Set fails.
[ "MustSet", "panics", "if", "Set", "fails", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1175-L1179
12,474
performancecopilot/speed
metrics.go
SetAll
func (c *PCPCounterVector) SetAll(val int64) { for ins := range c.indom.instances { c.MustSet(val, ins) } }
go
func (c *PCPCounterVector) SetAll(val int64) { for ins := range c.indom.instances { c.MustSet(val, ins) } }
[ "func", "(", "c", "*", "PCPCounterVector", ")", "SetAll", "(", "val", "int64", ")", "{", "for", "ins", ":=", "range", "c", ".", "indom", ".", "instances", "{", "c", ".", "MustSet", "(", "val", ",", "ins", ")", "\n", "}", "\n", "}" ]
// SetAll sets all instances to the same value and panics on an error.
[ "SetAll", "sets", "all", "instances", "to", "the", "same", "value", "and", "panics", "on", "an", "error", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1182-L1186
12,475
performancecopilot/speed
metrics.go
Inc
func (c *PCPCounterVector) Inc(inc int64, instance string) error { c.mutex.Lock() defer c.mutex.Unlock() if inc < 0 { return errors.New("increment cannot be negative") } if inc == 0 { return nil } v, err := c.valInstance(instance) if err != nil { return err } return c.setInstance(v.(int64)+inc, instance) }
go
func (c *PCPCounterVector) Inc(inc int64, instance string) error { c.mutex.Lock() defer c.mutex.Unlock() if inc < 0 { return errors.New("increment cannot be negative") } if inc == 0 { return nil } v, err := c.valInstance(instance) if err != nil { return err } return c.setInstance(v.(int64)+inc, instance) }
[ "func", "(", "c", "*", "PCPCounterVector", ")", "Inc", "(", "inc", "int64", ",", "instance", "string", ")", "error", "{", "c", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "if", "inc", "<", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "inc", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "v", ",", "err", ":=", "c", ".", "valInstance", "(", "instance", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "c", ".", "setInstance", "(", "v", ".", "(", "int64", ")", "+", "inc", ",", "instance", ")", "\n", "}" ]
// Inc increments the value of a particular instance of PCPCounterVector.
[ "Inc", "increments", "the", "value", "of", "a", "particular", "instance", "of", "PCPCounterVector", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1189-L1207
12,476
performancecopilot/speed
metrics.go
MustInc
func (c *PCPCounterVector) MustInc(inc int64, instance string) { if err := c.Inc(inc, instance); err != nil { panic(err) } }
go
func (c *PCPCounterVector) MustInc(inc int64, instance string) { if err := c.Inc(inc, instance); err != nil { panic(err) } }
[ "func", "(", "c", "*", "PCPCounterVector", ")", "MustInc", "(", "inc", "int64", ",", "instance", "string", ")", "{", "if", "err", ":=", "c", ".", "Inc", "(", "inc", ",", "instance", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// MustInc panics if Inc fails.
[ "MustInc", "panics", "if", "Inc", "fails", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1210-L1214
12,477
performancecopilot/speed
metrics.go
IncAll
func (c *PCPCounterVector) IncAll(val int64) { for ins := range c.indom.instances { c.MustInc(val, ins) } }
go
func (c *PCPCounterVector) IncAll(val int64) { for ins := range c.indom.instances { c.MustInc(val, ins) } }
[ "func", "(", "c", "*", "PCPCounterVector", ")", "IncAll", "(", "val", "int64", ")", "{", "for", "ins", ":=", "range", "c", ".", "indom", ".", "instances", "{", "c", ".", "MustInc", "(", "val", ",", "ins", ")", "\n", "}", "\n", "}" ]
// IncAll increments all instances by the same value and panics on an error.
[ "IncAll", "increments", "all", "instances", "by", "the", "same", "value", "and", "panics", "on", "an", "error", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1217-L1221
12,478
performancecopilot/speed
metrics.go
NewPCPGaugeVector
func NewPCPGaugeVector(values map[string]float64, name string, desc ...string) (*PCPGaugeVector, error) { vals := make(Instances) for k, v := range values { vals[k] = v } im, err := generateInstanceMetric(vals, name, vals.Keys(), DoubleType, InstantSemantics, OneUnit, desc...) if err != nil { return nil, err } return &PCPGaugeVector{im, sync.RWMutex{}}, nil }
go
func NewPCPGaugeVector(values map[string]float64, name string, desc ...string) (*PCPGaugeVector, error) { vals := make(Instances) for k, v := range values { vals[k] = v } im, err := generateInstanceMetric(vals, name, vals.Keys(), DoubleType, InstantSemantics, OneUnit, desc...) if err != nil { return nil, err } return &PCPGaugeVector{im, sync.RWMutex{}}, nil }
[ "func", "NewPCPGaugeVector", "(", "values", "map", "[", "string", "]", "float64", ",", "name", "string", ",", "desc", "...", "string", ")", "(", "*", "PCPGaugeVector", ",", "error", ")", "{", "vals", ":=", "make", "(", "Instances", ")", "\n", "for", "k", ",", "v", ":=", "range", "values", "{", "vals", "[", "k", "]", "=", "v", "\n", "}", "\n\n", "im", ",", "err", ":=", "generateInstanceMetric", "(", "vals", ",", "name", ",", "vals", ".", "Keys", "(", ")", ",", "DoubleType", ",", "InstantSemantics", ",", "OneUnit", ",", "desc", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "PCPGaugeVector", "{", "im", ",", "sync", ".", "RWMutex", "{", "}", "}", ",", "nil", "\n", "}" ]
// NewPCPGaugeVector creates a new instance of a PCPGaugeVector. // It requires a name and map of instance names to their values. // Optionally, it can also accept a couple of strings providing more details // about the metric.
[ "NewPCPGaugeVector", "creates", "a", "new", "instance", "of", "a", "PCPGaugeVector", ".", "It", "requires", "a", "name", "and", "map", "of", "instance", "names", "to", "their", "values", ".", "Optionally", "it", "can", "also", "accept", "a", "couple", "of", "strings", "providing", "more", "details", "about", "the", "metric", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1262-L1274
12,479
performancecopilot/speed
metrics.go
Val
func (g *PCPGaugeVector) Val(instance string) (float64, error) { g.mutex.RLock() defer g.mutex.RUnlock() val, err := g.valInstance(instance) if err != nil { return 0, err } return val.(float64), nil }
go
func (g *PCPGaugeVector) Val(instance string) (float64, error) { g.mutex.RLock() defer g.mutex.RUnlock() val, err := g.valInstance(instance) if err != nil { return 0, err } return val.(float64), nil }
[ "func", "(", "g", "*", "PCPGaugeVector", ")", "Val", "(", "instance", "string", ")", "(", "float64", ",", "error", ")", "{", "g", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "val", ",", "err", ":=", "g", ".", "valInstance", "(", "instance", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "val", ".", "(", "float64", ")", ",", "nil", "\n", "}" ]
// Val returns the value of a particular instance of PCPGaugeVector
[ "Val", "returns", "the", "value", "of", "a", "particular", "instance", "of", "PCPGaugeVector" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1277-L1287
12,480
performancecopilot/speed
metrics.go
Set
func (g *PCPGaugeVector) Set(val float64, instance string) error { g.mutex.Lock() defer g.mutex.Unlock() return g.setInstance(val, instance) }
go
func (g *PCPGaugeVector) Set(val float64, instance string) error { g.mutex.Lock() defer g.mutex.Unlock() return g.setInstance(val, instance) }
[ "func", "(", "g", "*", "PCPGaugeVector", ")", "Set", "(", "val", "float64", ",", "instance", "string", ")", "error", "{", "g", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "Unlock", "(", ")", "\n", "return", "g", ".", "setInstance", "(", "val", ",", "instance", ")", "\n", "}" ]
// Set sets the value of a particular instance of PCPGaugeVector
[ "Set", "sets", "the", "value", "of", "a", "particular", "instance", "of", "PCPGaugeVector" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1290-L1294
12,481
performancecopilot/speed
metrics.go
MustSet
func (g *PCPGaugeVector) MustSet(val float64, instance string) { if err := g.Set(val, instance); err != nil { panic(err) } }
go
func (g *PCPGaugeVector) MustSet(val float64, instance string) { if err := g.Set(val, instance); err != nil { panic(err) } }
[ "func", "(", "g", "*", "PCPGaugeVector", ")", "MustSet", "(", "val", "float64", ",", "instance", "string", ")", "{", "if", "err", ":=", "g", ".", "Set", "(", "val", ",", "instance", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// MustSet panics if Set fails
[ "MustSet", "panics", "if", "Set", "fails" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1297-L1301
12,482
performancecopilot/speed
metrics.go
SetAll
func (g *PCPGaugeVector) SetAll(val float64) { for ins := range g.indom.instances { g.MustSet(val, ins) } }
go
func (g *PCPGaugeVector) SetAll(val float64) { for ins := range g.indom.instances { g.MustSet(val, ins) } }
[ "func", "(", "g", "*", "PCPGaugeVector", ")", "SetAll", "(", "val", "float64", ")", "{", "for", "ins", ":=", "range", "g", ".", "indom", ".", "instances", "{", "g", ".", "MustSet", "(", "val", ",", "ins", ")", "\n", "}", "\n", "}" ]
// SetAll sets all instances to the same value and panics on an error
[ "SetAll", "sets", "all", "instances", "to", "the", "same", "value", "and", "panics", "on", "an", "error" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1304-L1308
12,483
performancecopilot/speed
metrics.go
Inc
func (g *PCPGaugeVector) Inc(inc float64, instance string) error { g.mutex.Lock() defer g.mutex.Unlock() v, err := g.valInstance(instance) if err != nil { return err } return g.setInstance(v.(float64)+inc, instance) }
go
func (g *PCPGaugeVector) Inc(inc float64, instance string) error { g.mutex.Lock() defer g.mutex.Unlock() v, err := g.valInstance(instance) if err != nil { return err } return g.setInstance(v.(float64)+inc, instance) }
[ "func", "(", "g", "*", "PCPGaugeVector", ")", "Inc", "(", "inc", "float64", ",", "instance", "string", ")", "error", "{", "g", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "g", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "v", ",", "err", ":=", "g", ".", "valInstance", "(", "instance", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "g", ".", "setInstance", "(", "v", ".", "(", "float64", ")", "+", "inc", ",", "instance", ")", "\n", "}" ]
// Inc increments the value of a particular instance of PCPGaugeVector
[ "Inc", "increments", "the", "value", "of", "a", "particular", "instance", "of", "PCPGaugeVector" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1311-L1321
12,484
performancecopilot/speed
metrics.go
MustInc
func (g *PCPGaugeVector) MustInc(inc float64, instance string) { if err := g.Inc(inc, instance); err != nil { panic(err) } }
go
func (g *PCPGaugeVector) MustInc(inc float64, instance string) { if err := g.Inc(inc, instance); err != nil { panic(err) } }
[ "func", "(", "g", "*", "PCPGaugeVector", ")", "MustInc", "(", "inc", "float64", ",", "instance", "string", ")", "{", "if", "err", ":=", "g", ".", "Inc", "(", "inc", ",", "instance", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// MustInc panics if Inc fails
[ "MustInc", "panics", "if", "Inc", "fails" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1324-L1328
12,485
performancecopilot/speed
metrics.go
IncAll
func (g *PCPGaugeVector) IncAll(val float64) { for ins := range g.indom.instances { g.MustInc(val, ins) } }
go
func (g *PCPGaugeVector) IncAll(val float64) { for ins := range g.indom.instances { g.MustInc(val, ins) } }
[ "func", "(", "g", "*", "PCPGaugeVector", ")", "IncAll", "(", "val", "float64", ")", "{", "for", "ins", ":=", "range", "g", ".", "indom", ".", "instances", "{", "g", ".", "MustInc", "(", "val", ",", "ins", ")", "\n", "}", "\n", "}" ]
// IncAll increments all instances by the same value and panics on an error
[ "IncAll", "increments", "all", "instances", "by", "the", "same", "value", "and", "panics", "on", "an", "error" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1331-L1335
12,486
performancecopilot/speed
metrics.go
Min
func (h *PCPHistogram) Min() int64 { h.mutex.RLock() defer h.mutex.RUnlock() return int64(h.vals["min"].val.(float64)) }
go
func (h *PCPHistogram) Min() int64 { h.mutex.RLock() defer h.mutex.RUnlock() return int64(h.vals["min"].val.(float64)) }
[ "func", "(", "h", "*", "PCPHistogram", ")", "Min", "(", ")", "int64", "{", "h", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "h", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "int64", "(", "h", ".", "vals", "[", "\"", "\"", "]", ".", "val", ".", "(", "float64", ")", ")", "\n", "}" ]
// Min returns the minimum recorded value so far.
[ "Min", "returns", "the", "minimum", "recorded", "value", "so", "far", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1461-L1465
12,487
performancecopilot/speed
metrics.go
Record
func (h *PCPHistogram) Record(val int64) error { h.mutex.Lock() defer h.mutex.Unlock() err := h.h.RecordValue(val) if err != nil { return err } return h.update() }
go
func (h *PCPHistogram) Record(val int64) error { h.mutex.Lock() defer h.mutex.Unlock() err := h.h.RecordValue(val) if err != nil { return err } return h.update() }
[ "func", "(", "h", "*", "PCPHistogram", ")", "Record", "(", "val", "int64", ")", "error", "{", "h", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "err", ":=", "h", ".", "h", ".", "RecordValue", "(", "val", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "h", ".", "update", "(", ")", "\n", "}" ]
// Record records a new value.
[ "Record", "records", "a", "new", "value", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1501-L1511
12,488
performancecopilot/speed
metrics.go
MustRecord
func (h *PCPHistogram) MustRecord(val int64) { if err := h.Record(val); err != nil { panic(err) } }
go
func (h *PCPHistogram) MustRecord(val int64) { if err := h.Record(val); err != nil { panic(err) } }
[ "func", "(", "h", "*", "PCPHistogram", ")", "MustRecord", "(", "val", "int64", ")", "{", "if", "err", ":=", "h", ".", "Record", "(", "val", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// MustRecord panics if Record fails.
[ "MustRecord", "panics", "if", "Record", "fails", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1514-L1518
12,489
performancecopilot/speed
metrics.go
RecordN
func (h *PCPHistogram) RecordN(val, n int64) error { h.mutex.Lock() defer h.mutex.Unlock() err := h.h.RecordValues(val, n) if err != nil { return err } return h.update() }
go
func (h *PCPHistogram) RecordN(val, n int64) error { h.mutex.Lock() defer h.mutex.Unlock() err := h.h.RecordValues(val, n) if err != nil { return err } return h.update() }
[ "func", "(", "h", "*", "PCPHistogram", ")", "RecordN", "(", "val", ",", "n", "int64", ")", "error", "{", "h", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "err", ":=", "h", ".", "h", ".", "RecordValues", "(", "val", ",", "n", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "h", ".", "update", "(", ")", "\n", "}" ]
// RecordN records multiple instances of the same value.
[ "RecordN", "records", "multiple", "instances", "of", "the", "same", "value", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1521-L1531
12,490
performancecopilot/speed
metrics.go
MustRecordN
func (h *PCPHistogram) MustRecordN(val, n int64) { if err := h.RecordN(val, n); err != nil { panic(err) } }
go
func (h *PCPHistogram) MustRecordN(val, n int64) { if err := h.RecordN(val, n); err != nil { panic(err) } }
[ "func", "(", "h", "*", "PCPHistogram", ")", "MustRecordN", "(", "val", ",", "n", "int64", ")", "{", "if", "err", ":=", "h", ".", "RecordN", "(", "val", ",", "n", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// MustRecordN panics if RecordN fails.
[ "MustRecordN", "panics", "if", "RecordN", "fails", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1534-L1538
12,491
performancecopilot/speed
metrics.go
Variance
func (h *PCPHistogram) Variance() float64 { h.mutex.RLock() defer h.mutex.RUnlock() return h.vals["variance"].val.(float64) }
go
func (h *PCPHistogram) Variance() float64 { h.mutex.RLock() defer h.mutex.RUnlock() return h.vals["variance"].val.(float64) }
[ "func", "(", "h", "*", "PCPHistogram", ")", "Variance", "(", ")", "float64", "{", "h", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "h", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "h", ".", "vals", "[", "\"", "\"", "]", ".", "val", ".", "(", "float64", ")", "\n", "}" ]
// Variance returns the variance of all values recorded so far.
[ "Variance", "returns", "the", "variance", "of", "all", "values", "recorded", "so", "far", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1555-L1559
12,492
performancecopilot/speed
metrics.go
Buckets
func (h *PCPHistogram) Buckets() []*HistogramBucket { b := h.h.Distribution() buckets := make([]*HistogramBucket, len(b)) for i := 0; i < len(b); i++ { buckets[i] = &HistogramBucket{b[i].From, b[i].To, b[i].Count} } return buckets }
go
func (h *PCPHistogram) Buckets() []*HistogramBucket { b := h.h.Distribution() buckets := make([]*HistogramBucket, len(b)) for i := 0; i < len(b); i++ { buckets[i] = &HistogramBucket{b[i].From, b[i].To, b[i].Count} } return buckets }
[ "func", "(", "h", "*", "PCPHistogram", ")", "Buckets", "(", ")", "[", "]", "*", "HistogramBucket", "{", "b", ":=", "h", ".", "h", ".", "Distribution", "(", ")", "\n", "buckets", ":=", "make", "(", "[", "]", "*", "HistogramBucket", ",", "len", "(", "b", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "b", ")", ";", "i", "++", "{", "buckets", "[", "i", "]", "=", "&", "HistogramBucket", "{", "b", "[", "i", "]", ".", "From", ",", "b", "[", "i", "]", ".", "To", ",", "b", "[", "i", "]", ".", "Count", "}", "\n", "}", "\n", "return", "buckets", "\n", "}" ]
// Buckets returns a list of histogram buckets.
[ "Buckets", "returns", "a", "list", "of", "histogram", "buckets", "." ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/metrics.go#L1570-L1577
12,493
performancecopilot/speed
examples/acme/main.go
NewProductBuilder
func NewProductBuilder(name string, client speed.Client) *ProductBuilder { completed, err := speed.NewPCPCounter(0, "products."+name+".count") if err != nil { log.Fatal("Could not create completed, error: ", err) } totalTime, err := speed.NewPCPGauge(0, "products."+name+".time") if err != nil { log.Fatal("Could not create totalTime, error: ", err) } client.MustRegister(completed) client.MustRegister(totalTime) return &ProductBuilder{ name: name, bound: 500, completed: completed, totalTime: totalTime, } }
go
func NewProductBuilder(name string, client speed.Client) *ProductBuilder { completed, err := speed.NewPCPCounter(0, "products."+name+".count") if err != nil { log.Fatal("Could not create completed, error: ", err) } totalTime, err := speed.NewPCPGauge(0, "products."+name+".time") if err != nil { log.Fatal("Could not create totalTime, error: ", err) } client.MustRegister(completed) client.MustRegister(totalTime) return &ProductBuilder{ name: name, bound: 500, completed: completed, totalTime: totalTime, } }
[ "func", "NewProductBuilder", "(", "name", "string", ",", "client", "speed", ".", "Client", ")", "*", "ProductBuilder", "{", "completed", ",", "err", ":=", "speed", ".", "NewPCPCounter", "(", "0", ",", "\"", "\"", "+", "name", "+", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "totalTime", ",", "err", ":=", "speed", ".", "NewPCPGauge", "(", "0", ",", "\"", "\"", "+", "name", "+", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "client", ".", "MustRegister", "(", "completed", ")", "\n", "client", ".", "MustRegister", "(", "totalTime", ")", "\n\n", "return", "&", "ProductBuilder", "{", "name", ":", "name", ",", "bound", ":", "500", ",", "completed", ":", "completed", ",", "totalTime", ":", "totalTime", ",", "}", "\n", "}" ]
// NewProductBuilder creates a new instance of ProductBuilder
[ "NewProductBuilder", "creates", "a", "new", "instance", "of", "ProductBuilder" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/examples/acme/main.go#L122-L142
12,494
performancecopilot/speed
examples/acme/main.go
Build
func (p *ProductBuilder) Build() { elapsed := rand.Intn(p.bound) time.Sleep(time.Duration(elapsed) * time.Millisecond) p.totalTime.MustInc(float64(elapsed)) p.completed.Up() }
go
func (p *ProductBuilder) Build() { elapsed := rand.Intn(p.bound) time.Sleep(time.Duration(elapsed) * time.Millisecond) p.totalTime.MustInc(float64(elapsed)) p.completed.Up() }
[ "func", "(", "p", "*", "ProductBuilder", ")", "Build", "(", ")", "{", "elapsed", ":=", "rand", ".", "Intn", "(", "p", ".", "bound", ")", "\n\n", "time", ".", "Sleep", "(", "time", ".", "Duration", "(", "elapsed", ")", "*", "time", ".", "Millisecond", ")", "\n\n", "p", ".", "totalTime", ".", "MustInc", "(", "float64", "(", "elapsed", ")", ")", "\n", "p", ".", "completed", ".", "Up", "(", ")", "\n", "}" ]
// Build sleeps for a random time, then adds that value to totalTime
[ "Build", "sleeps", "for", "a", "random", "time", "then", "adds", "that", "value", "to", "totalTime" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/examples/acme/main.go#L150-L157
12,495
performancecopilot/speed
examples/acme/main.go
Start
func (p *ProductBuilder) Start() { for { p.Build() fmt.Printf("Built %d %s\n", p.completed.Val(), p.name) } }
go
func (p *ProductBuilder) Start() { for { p.Build() fmt.Printf("Built %d %s\n", p.completed.Val(), p.name) } }
[ "func", "(", "p", "*", "ProductBuilder", ")", "Start", "(", ")", "{", "for", "{", "p", ".", "Build", "(", ")", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "p", ".", "completed", ".", "Val", "(", ")", ",", "p", ".", "name", ")", "\n", "}", "\n", "}" ]
// Start starts an infinite loop calling Build and logging the value of completed
[ "Start", "starts", "an", "infinite", "loop", "calling", "Build", "and", "logging", "the", "value", "of", "completed" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/examples/acme/main.go#L160-L165
12,496
performancecopilot/speed
registry.go
NewPCPRegistry
func NewPCPRegistry() *PCPRegistry { return &PCPRegistry{ instanceDomains: make(map[string]*PCPInstanceDomain), metrics: make(map[string]PCPMetric), } }
go
func NewPCPRegistry() *PCPRegistry { return &PCPRegistry{ instanceDomains: make(map[string]*PCPInstanceDomain), metrics: make(map[string]PCPMetric), } }
[ "func", "NewPCPRegistry", "(", ")", "*", "PCPRegistry", "{", "return", "&", "PCPRegistry", "{", "instanceDomains", ":", "make", "(", "map", "[", "string", "]", "*", "PCPInstanceDomain", ")", ",", "metrics", ":", "make", "(", "map", "[", "string", "]", "PCPMetric", ")", ",", "}", "\n", "}" ]
// NewPCPRegistry creates a new PCPRegistry object
[ "NewPCPRegistry", "creates", "a", "new", "PCPRegistry", "object" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/registry.go#L73-L78
12,497
performancecopilot/speed
registry.go
InstanceCount
func (r *PCPRegistry) InstanceCount() int { r.indomlock.RLock() defer r.indomlock.RUnlock() return r.instanceCount }
go
func (r *PCPRegistry) InstanceCount() int { r.indomlock.RLock() defer r.indomlock.RUnlock() return r.instanceCount }
[ "func", "(", "r", "*", "PCPRegistry", ")", "InstanceCount", "(", ")", "int", "{", "r", ".", "indomlock", ".", "RLock", "(", ")", "\n", "defer", "r", ".", "indomlock", ".", "RUnlock", "(", ")", "\n\n", "return", "r", ".", "instanceCount", "\n", "}" ]
// InstanceCount returns the number of instances across all indoms in the registry
[ "InstanceCount", "returns", "the", "number", "of", "instances", "across", "all", "indoms", "in", "the", "registry" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/registry.go#L81-L86
12,498
performancecopilot/speed
registry.go
InstanceDomainCount
func (r *PCPRegistry) InstanceDomainCount() int { r.indomlock.RLock() defer r.indomlock.RUnlock() return len(r.instanceDomains) }
go
func (r *PCPRegistry) InstanceDomainCount() int { r.indomlock.RLock() defer r.indomlock.RUnlock() return len(r.instanceDomains) }
[ "func", "(", "r", "*", "PCPRegistry", ")", "InstanceDomainCount", "(", ")", "int", "{", "r", ".", "indomlock", ".", "RLock", "(", ")", "\n", "defer", "r", ".", "indomlock", ".", "RUnlock", "(", ")", "\n\n", "return", "len", "(", "r", ".", "instanceDomains", ")", "\n", "}" ]
// InstanceDomainCount returns the number of instance domains in the registry
[ "InstanceDomainCount", "returns", "the", "number", "of", "instance", "domains", "in", "the", "registry" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/registry.go#L89-L94
12,499
performancecopilot/speed
registry.go
MetricCount
func (r *PCPRegistry) MetricCount() int { r.metricslock.RLock() defer r.metricslock.RUnlock() return len(r.metrics) }
go
func (r *PCPRegistry) MetricCount() int { r.metricslock.RLock() defer r.metricslock.RUnlock() return len(r.metrics) }
[ "func", "(", "r", "*", "PCPRegistry", ")", "MetricCount", "(", ")", "int", "{", "r", ".", "metricslock", ".", "RLock", "(", ")", "\n", "defer", "r", ".", "metricslock", ".", "RUnlock", "(", ")", "\n\n", "return", "len", "(", "r", ".", "metrics", ")", "\n", "}" ]
// MetricCount returns the number of metrics in the registry
[ "MetricCount", "returns", "the", "number", "of", "metrics", "in", "the", "registry" ]
22ca883d94397b1f6c7a2ab155d9972af6b26813
https://github.com/performancecopilot/speed/blob/22ca883d94397b1f6c7a2ab155d9972af6b26813/registry.go#L97-L102