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
partition
stringclasses
1 value
google/pprof
internal/symbolizer/symbolizer.go
Symbolize
func (s *Symbolizer) Symbolize(mode string, sources plugin.MappingSources, p *profile.Profile) error { remote, local, fast, force, demanglerMode := true, true, false, false, "" for _, o := range strings.Split(strings.ToLower(mode), ":") { switch o { case "": continue case "none", "no": return nil case "local": remote, local = false, true case "fastlocal": remote, local, fast = false, true, true case "remote": remote, local = true, false case "force": force = true default: switch d := strings.TrimPrefix(o, "demangle="); d { case "full", "none", "templates": demanglerMode = d force = true continue case "default": continue } s.UI.PrintErr("ignoring unrecognized symbolization option: " + mode) s.UI.PrintErr("expecting -symbolize=[local|fastlocal|remote|none][:force][:demangle=[none|full|templates|default]") } } var err error if local { // Symbolize locally using binutils. if err = localSymbolize(p, fast, force, s.Obj, s.UI); err != nil { s.UI.PrintErr("local symbolization: " + err.Error()) } } if remote { post := func(source, post string) ([]byte, error) { return postURL(source, post, s.Transport) } if err = symbolzSymbolize(p, force, sources, post, s.UI); err != nil { return err // Ran out of options. } } demangleFunction(p, force, demanglerMode) return nil }
go
func (s *Symbolizer) Symbolize(mode string, sources plugin.MappingSources, p *profile.Profile) error { remote, local, fast, force, demanglerMode := true, true, false, false, "" for _, o := range strings.Split(strings.ToLower(mode), ":") { switch o { case "": continue case "none", "no": return nil case "local": remote, local = false, true case "fastlocal": remote, local, fast = false, true, true case "remote": remote, local = true, false case "force": force = true default: switch d := strings.TrimPrefix(o, "demangle="); d { case "full", "none", "templates": demanglerMode = d force = true continue case "default": continue } s.UI.PrintErr("ignoring unrecognized symbolization option: " + mode) s.UI.PrintErr("expecting -symbolize=[local|fastlocal|remote|none][:force][:demangle=[none|full|templates|default]") } } var err error if local { // Symbolize locally using binutils. if err = localSymbolize(p, fast, force, s.Obj, s.UI); err != nil { s.UI.PrintErr("local symbolization: " + err.Error()) } } if remote { post := func(source, post string) ([]byte, error) { return postURL(source, post, s.Transport) } if err = symbolzSymbolize(p, force, sources, post, s.UI); err != nil { return err // Ran out of options. } } demangleFunction(p, force, demanglerMode) return nil }
[ "func", "(", "s", "*", "Symbolizer", ")", "Symbolize", "(", "mode", "string", ",", "sources", "plugin", ".", "MappingSources", ",", "p", "*", "profile", ".", "Profile", ")", "error", "{", "remote", ",", "local", ",", "fast", ",", "force", ",", "demanglerMode", ":=", "true", ",", "true", ",", "false", ",", "false", ",", "\"", "\"", "\n", "for", "_", ",", "o", ":=", "range", "strings", ".", "Split", "(", "strings", ".", "ToLower", "(", "mode", ")", ",", "\"", "\"", ")", "{", "switch", "o", "{", "case", "\"", "\"", ":", "continue", "\n", "case", "\"", "\"", ",", "\"", "\"", ":", "return", "nil", "\n", "case", "\"", "\"", ":", "remote", ",", "local", "=", "false", ",", "true", "\n", "case", "\"", "\"", ":", "remote", ",", "local", ",", "fast", "=", "false", ",", "true", ",", "true", "\n", "case", "\"", "\"", ":", "remote", ",", "local", "=", "true", ",", "false", "\n", "case", "\"", "\"", ":", "force", "=", "true", "\n", "default", ":", "switch", "d", ":=", "strings", ".", "TrimPrefix", "(", "o", ",", "\"", "\"", ")", ";", "d", "{", "case", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ":", "demanglerMode", "=", "d", "\n", "force", "=", "true", "\n", "continue", "\n", "case", "\"", "\"", ":", "continue", "\n", "}", "\n", "s", ".", "UI", ".", "PrintErr", "(", "\"", "\"", "+", "mode", ")", "\n", "s", ".", "UI", ".", "PrintErr", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "var", "err", "error", "\n", "if", "local", "{", "// Symbolize locally using binutils.", "if", "err", "=", "localSymbolize", "(", "p", ",", "fast", ",", "force", ",", "s", ".", "Obj", ",", "s", ".", "UI", ")", ";", "err", "!=", "nil", "{", "s", ".", "UI", ".", "PrintErr", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "\n", "if", "remote", "{", "post", ":=", "func", "(", "source", ",", "post", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "postURL", "(", "source", ",", "post", ",", "s", ".", "Transport", ")", "\n", "}", "\n", "if", "err", "=", "symbolzSymbolize", "(", "p", ",", "force", ",", "sources", ",", "post", ",", "s", ".", "UI", ")", ";", "err", "!=", "nil", "{", "return", "err", "// Ran out of options.", "\n", "}", "\n", "}", "\n\n", "demangleFunction", "(", "p", ",", "force", ",", "demanglerMode", ")", "\n", "return", "nil", "\n", "}" ]
// Symbolize attempts to symbolize profile p. First uses binutils on // local binaries; if the source is a URL it attempts to get any // missed entries using symbolz.
[ "Symbolize", "attempts", "to", "symbolize", "profile", "p", ".", "First", "uses", "binutils", "on", "local", "binaries", ";", "if", "the", "source", "is", "a", "URL", "it", "attempts", "to", "get", "any", "missed", "entries", "using", "symbolz", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/symbolizer/symbolizer.go#L50-L98
train
google/pprof
internal/symbolizer/symbolizer.go
postURL
func postURL(source, post string, tr http.RoundTripper) ([]byte, error) { client := &http.Client{ Transport: tr, } resp, err := client.Post(source, "application/octet-stream", strings.NewReader(post)) if err != nil { return nil, fmt.Errorf("http post %s: %v", source, err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("http post %s: %v", source, statusCodeError(resp)) } return ioutil.ReadAll(resp.Body) }
go
func postURL(source, post string, tr http.RoundTripper) ([]byte, error) { client := &http.Client{ Transport: tr, } resp, err := client.Post(source, "application/octet-stream", strings.NewReader(post)) if err != nil { return nil, fmt.Errorf("http post %s: %v", source, err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("http post %s: %v", source, statusCodeError(resp)) } return ioutil.ReadAll(resp.Body) }
[ "func", "postURL", "(", "source", ",", "post", "string", ",", "tr", "http", ".", "RoundTripper", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "client", ":=", "&", "http", ".", "Client", "{", "Transport", ":", "tr", ",", "}", "\n", "resp", ",", "err", ":=", "client", ".", "Post", "(", "source", ",", "\"", "\"", ",", "strings", ".", "NewReader", "(", "post", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "source", ",", "err", ")", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "if", "resp", ".", "StatusCode", "!=", "http", ".", "StatusOK", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "source", ",", "statusCodeError", "(", "resp", ")", ")", "\n", "}", "\n", "return", "ioutil", ".", "ReadAll", "(", "resp", ".", "Body", ")", "\n", "}" ]
// postURL issues a POST to a URL over HTTP.
[ "postURL", "issues", "a", "POST", "to", "a", "URL", "over", "HTTP", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/symbolizer/symbolizer.go#L101-L114
train
google/pprof
internal/symbolizer/symbolizer.go
doLocalSymbolize
func doLocalSymbolize(prof *profile.Profile, fast, force bool, obj plugin.ObjTool, ui plugin.UI) error { if fast { if bu, ok := obj.(*binutils.Binutils); ok { bu.SetFastSymbolization(true) } } mt, err := newMapping(prof, obj, ui, force) if err != nil { return err } defer mt.close() functions := make(map[profile.Function]*profile.Function) for _, l := range mt.prof.Location { m := l.Mapping segment := mt.segments[m] if segment == nil { // Nothing to do. continue } stack, err := segment.SourceLine(l.Address) if err != nil || len(stack) == 0 { // No answers from addr2line. continue } l.Line = make([]profile.Line, len(stack)) l.IsFolded = false for i, frame := range stack { if frame.Func != "" { m.HasFunctions = true } if frame.File != "" { m.HasFilenames = true } if frame.Line != 0 { m.HasLineNumbers = true } f := &profile.Function{ Name: frame.Func, SystemName: frame.Func, Filename: frame.File, } if fp := functions[*f]; fp != nil { f = fp } else { functions[*f] = f f.ID = uint64(len(mt.prof.Function)) + 1 mt.prof.Function = append(mt.prof.Function, f) } l.Line[i] = profile.Line{ Function: f, Line: int64(frame.Line), } } if len(stack) > 0 { m.HasInlineFrames = true } } return nil }
go
func doLocalSymbolize(prof *profile.Profile, fast, force bool, obj plugin.ObjTool, ui plugin.UI) error { if fast { if bu, ok := obj.(*binutils.Binutils); ok { bu.SetFastSymbolization(true) } } mt, err := newMapping(prof, obj, ui, force) if err != nil { return err } defer mt.close() functions := make(map[profile.Function]*profile.Function) for _, l := range mt.prof.Location { m := l.Mapping segment := mt.segments[m] if segment == nil { // Nothing to do. continue } stack, err := segment.SourceLine(l.Address) if err != nil || len(stack) == 0 { // No answers from addr2line. continue } l.Line = make([]profile.Line, len(stack)) l.IsFolded = false for i, frame := range stack { if frame.Func != "" { m.HasFunctions = true } if frame.File != "" { m.HasFilenames = true } if frame.Line != 0 { m.HasLineNumbers = true } f := &profile.Function{ Name: frame.Func, SystemName: frame.Func, Filename: frame.File, } if fp := functions[*f]; fp != nil { f = fp } else { functions[*f] = f f.ID = uint64(len(mt.prof.Function)) + 1 mt.prof.Function = append(mt.prof.Function, f) } l.Line[i] = profile.Line{ Function: f, Line: int64(frame.Line), } } if len(stack) > 0 { m.HasInlineFrames = true } } return nil }
[ "func", "doLocalSymbolize", "(", "prof", "*", "profile", ".", "Profile", ",", "fast", ",", "force", "bool", ",", "obj", "plugin", ".", "ObjTool", ",", "ui", "plugin", ".", "UI", ")", "error", "{", "if", "fast", "{", "if", "bu", ",", "ok", ":=", "obj", ".", "(", "*", "binutils", ".", "Binutils", ")", ";", "ok", "{", "bu", ".", "SetFastSymbolization", "(", "true", ")", "\n", "}", "\n", "}", "\n\n", "mt", ",", "err", ":=", "newMapping", "(", "prof", ",", "obj", ",", "ui", ",", "force", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "mt", ".", "close", "(", ")", "\n\n", "functions", ":=", "make", "(", "map", "[", "profile", ".", "Function", "]", "*", "profile", ".", "Function", ")", "\n", "for", "_", ",", "l", ":=", "range", "mt", ".", "prof", ".", "Location", "{", "m", ":=", "l", ".", "Mapping", "\n", "segment", ":=", "mt", ".", "segments", "[", "m", "]", "\n", "if", "segment", "==", "nil", "{", "// Nothing to do.", "continue", "\n", "}", "\n\n", "stack", ",", "err", ":=", "segment", ".", "SourceLine", "(", "l", ".", "Address", ")", "\n", "if", "err", "!=", "nil", "||", "len", "(", "stack", ")", "==", "0", "{", "// No answers from addr2line.", "continue", "\n", "}", "\n\n", "l", ".", "Line", "=", "make", "(", "[", "]", "profile", ".", "Line", ",", "len", "(", "stack", ")", ")", "\n", "l", ".", "IsFolded", "=", "false", "\n", "for", "i", ",", "frame", ":=", "range", "stack", "{", "if", "frame", ".", "Func", "!=", "\"", "\"", "{", "m", ".", "HasFunctions", "=", "true", "\n", "}", "\n", "if", "frame", ".", "File", "!=", "\"", "\"", "{", "m", ".", "HasFilenames", "=", "true", "\n", "}", "\n", "if", "frame", ".", "Line", "!=", "0", "{", "m", ".", "HasLineNumbers", "=", "true", "\n", "}", "\n", "f", ":=", "&", "profile", ".", "Function", "{", "Name", ":", "frame", ".", "Func", ",", "SystemName", ":", "frame", ".", "Func", ",", "Filename", ":", "frame", ".", "File", ",", "}", "\n", "if", "fp", ":=", "functions", "[", "*", "f", "]", ";", "fp", "!=", "nil", "{", "f", "=", "fp", "\n", "}", "else", "{", "functions", "[", "*", "f", "]", "=", "f", "\n", "f", ".", "ID", "=", "uint64", "(", "len", "(", "mt", ".", "prof", ".", "Function", ")", ")", "+", "1", "\n", "mt", ".", "prof", ".", "Function", "=", "append", "(", "mt", ".", "prof", ".", "Function", ",", "f", ")", "\n", "}", "\n", "l", ".", "Line", "[", "i", "]", "=", "profile", ".", "Line", "{", "Function", ":", "f", ",", "Line", ":", "int64", "(", "frame", ".", "Line", ")", ",", "}", "\n", "}", "\n\n", "if", "len", "(", "stack", ")", ">", "0", "{", "m", ".", "HasInlineFrames", "=", "true", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// doLocalSymbolize adds symbol and line number information to all locations // in a profile. mode enables some options to control // symbolization.
[ "doLocalSymbolize", "adds", "symbol", "and", "line", "number", "information", "to", "all", "locations", "in", "a", "profile", ".", "mode", "enables", "some", "options", "to", "control", "symbolization", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/symbolizer/symbolizer.go#L129-L193
train
google/pprof
internal/symbolizer/symbolizer.go
Demangle
func Demangle(prof *profile.Profile, force bool, demanglerMode string) { if force { // Remove the current demangled names to force demangling for _, f := range prof.Function { if f.Name != "" && f.SystemName != "" { f.Name = f.SystemName } } } var options []demangle.Option switch demanglerMode { case "": // demangled, simplified: no parameters, no templates, no return type options = []demangle.Option{demangle.NoParams, demangle.NoTemplateParams} case "templates": // demangled, simplified: no parameters, no return type options = []demangle.Option{demangle.NoParams} case "full": options = []demangle.Option{demangle.NoClones} case "none": // no demangling return } // Copy the options because they may be updated by the call. o := make([]demangle.Option, len(options)) for _, fn := range prof.Function { if fn.Name != "" && fn.SystemName != fn.Name { continue // Already demangled. } copy(o, options) if demangled := demangle.Filter(fn.SystemName, o...); demangled != fn.SystemName { fn.Name = demangled continue } // Could not demangle. Apply heuristics in case the name is // already demangled. name := fn.SystemName if looksLikeDemangledCPlusPlus(name) { if demanglerMode == "" || demanglerMode == "templates" { name = removeMatching(name, '(', ')') } if demanglerMode == "" { name = removeMatching(name, '<', '>') } } fn.Name = name } }
go
func Demangle(prof *profile.Profile, force bool, demanglerMode string) { if force { // Remove the current demangled names to force demangling for _, f := range prof.Function { if f.Name != "" && f.SystemName != "" { f.Name = f.SystemName } } } var options []demangle.Option switch demanglerMode { case "": // demangled, simplified: no parameters, no templates, no return type options = []demangle.Option{demangle.NoParams, demangle.NoTemplateParams} case "templates": // demangled, simplified: no parameters, no return type options = []demangle.Option{demangle.NoParams} case "full": options = []demangle.Option{demangle.NoClones} case "none": // no demangling return } // Copy the options because they may be updated by the call. o := make([]demangle.Option, len(options)) for _, fn := range prof.Function { if fn.Name != "" && fn.SystemName != fn.Name { continue // Already demangled. } copy(o, options) if demangled := demangle.Filter(fn.SystemName, o...); demangled != fn.SystemName { fn.Name = demangled continue } // Could not demangle. Apply heuristics in case the name is // already demangled. name := fn.SystemName if looksLikeDemangledCPlusPlus(name) { if demanglerMode == "" || demanglerMode == "templates" { name = removeMatching(name, '(', ')') } if demanglerMode == "" { name = removeMatching(name, '<', '>') } } fn.Name = name } }
[ "func", "Demangle", "(", "prof", "*", "profile", ".", "Profile", ",", "force", "bool", ",", "demanglerMode", "string", ")", "{", "if", "force", "{", "// Remove the current demangled names to force demangling", "for", "_", ",", "f", ":=", "range", "prof", ".", "Function", "{", "if", "f", ".", "Name", "!=", "\"", "\"", "&&", "f", ".", "SystemName", "!=", "\"", "\"", "{", "f", ".", "Name", "=", "f", ".", "SystemName", "\n", "}", "\n", "}", "\n", "}", "\n\n", "var", "options", "[", "]", "demangle", ".", "Option", "\n", "switch", "demanglerMode", "{", "case", "\"", "\"", ":", "// demangled, simplified: no parameters, no templates, no return type", "options", "=", "[", "]", "demangle", ".", "Option", "{", "demangle", ".", "NoParams", ",", "demangle", ".", "NoTemplateParams", "}", "\n", "case", "\"", "\"", ":", "// demangled, simplified: no parameters, no return type", "options", "=", "[", "]", "demangle", ".", "Option", "{", "demangle", ".", "NoParams", "}", "\n", "case", "\"", "\"", ":", "options", "=", "[", "]", "demangle", ".", "Option", "{", "demangle", ".", "NoClones", "}", "\n", "case", "\"", "\"", ":", "// no demangling", "return", "\n", "}", "\n\n", "// Copy the options because they may be updated by the call.", "o", ":=", "make", "(", "[", "]", "demangle", ".", "Option", ",", "len", "(", "options", ")", ")", "\n", "for", "_", ",", "fn", ":=", "range", "prof", ".", "Function", "{", "if", "fn", ".", "Name", "!=", "\"", "\"", "&&", "fn", ".", "SystemName", "!=", "fn", ".", "Name", "{", "continue", "// Already demangled.", "\n", "}", "\n", "copy", "(", "o", ",", "options", ")", "\n", "if", "demangled", ":=", "demangle", ".", "Filter", "(", "fn", ".", "SystemName", ",", "o", "...", ")", ";", "demangled", "!=", "fn", ".", "SystemName", "{", "fn", ".", "Name", "=", "demangled", "\n", "continue", "\n", "}", "\n", "// Could not demangle. Apply heuristics in case the name is", "// already demangled.", "name", ":=", "fn", ".", "SystemName", "\n", "if", "looksLikeDemangledCPlusPlus", "(", "name", ")", "{", "if", "demanglerMode", "==", "\"", "\"", "||", "demanglerMode", "==", "\"", "\"", "{", "name", "=", "removeMatching", "(", "name", ",", "'('", ",", "')'", ")", "\n", "}", "\n", "if", "demanglerMode", "==", "\"", "\"", "{", "name", "=", "removeMatching", "(", "name", ",", "'<'", ",", "'>'", ")", "\n", "}", "\n", "}", "\n", "fn", ".", "Name", "=", "name", "\n", "}", "\n", "}" ]
// Demangle updates the function names in a profile with demangled C++ // names, simplified according to demanglerMode. If force is set, // overwrite any names that appear already demangled.
[ "Demangle", "updates", "the", "function", "names", "in", "a", "profile", "with", "demangled", "C", "++", "names", "simplified", "according", "to", "demanglerMode", ".", "If", "force", "is", "set", "overwrite", "any", "names", "that", "appear", "already", "demangled", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/symbolizer/symbolizer.go#L198-L244
train
google/pprof
internal/symbolizer/symbolizer.go
looksLikeDemangledCPlusPlus
func looksLikeDemangledCPlusPlus(demangled string) bool { if strings.Contains(demangled, ".<") { // Skip java names of the form "class.<init>" return false } return strings.ContainsAny(demangled, "<>[]") || strings.Contains(demangled, "::") }
go
func looksLikeDemangledCPlusPlus(demangled string) bool { if strings.Contains(demangled, ".<") { // Skip java names of the form "class.<init>" return false } return strings.ContainsAny(demangled, "<>[]") || strings.Contains(demangled, "::") }
[ "func", "looksLikeDemangledCPlusPlus", "(", "demangled", "string", ")", "bool", "{", "if", "strings", ".", "Contains", "(", "demangled", ",", "\"", "\"", ")", "{", "// Skip java names of the form \"class.<init>\"", "return", "false", "\n", "}", "\n", "return", "strings", ".", "ContainsAny", "(", "demangled", ",", "\"", "\"", ")", "||", "strings", ".", "Contains", "(", "demangled", ",", "\"", "\"", ")", "\n", "}" ]
// looksLikeDemangledCPlusPlus is a heuristic to decide if a name is // the result of demangling C++. If so, further heuristics will be // applied to simplify the name.
[ "looksLikeDemangledCPlusPlus", "is", "a", "heuristic", "to", "decide", "if", "a", "name", "is", "the", "result", "of", "demangling", "C", "++", ".", "If", "so", "further", "heuristics", "will", "be", "applied", "to", "simplify", "the", "name", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/symbolizer/symbolizer.go#L249-L254
train
google/pprof
internal/symbolizer/symbolizer.go
removeMatching
func removeMatching(name string, start, end byte) string { s := string(start) + string(end) var nesting, first, current int for index := strings.IndexAny(name[current:], s); index != -1; index = strings.IndexAny(name[current:], s) { switch current += index; name[current] { case start: nesting++ if nesting == 1 { first = current } case end: nesting-- switch { case nesting < 0: return name // Mismatch, abort case nesting == 0: name = name[:first] + name[current+1:] current = first - 1 } } current++ } return name }
go
func removeMatching(name string, start, end byte) string { s := string(start) + string(end) var nesting, first, current int for index := strings.IndexAny(name[current:], s); index != -1; index = strings.IndexAny(name[current:], s) { switch current += index; name[current] { case start: nesting++ if nesting == 1 { first = current } case end: nesting-- switch { case nesting < 0: return name // Mismatch, abort case nesting == 0: name = name[:first] + name[current+1:] current = first - 1 } } current++ } return name }
[ "func", "removeMatching", "(", "name", "string", ",", "start", ",", "end", "byte", ")", "string", "{", "s", ":=", "string", "(", "start", ")", "+", "string", "(", "end", ")", "\n", "var", "nesting", ",", "first", ",", "current", "int", "\n", "for", "index", ":=", "strings", ".", "IndexAny", "(", "name", "[", "current", ":", "]", ",", "s", ")", ";", "index", "!=", "-", "1", ";", "index", "=", "strings", ".", "IndexAny", "(", "name", "[", "current", ":", "]", ",", "s", ")", "{", "switch", "current", "+=", "index", ";", "name", "[", "current", "]", "{", "case", "start", ":", "nesting", "++", "\n", "if", "nesting", "==", "1", "{", "first", "=", "current", "\n", "}", "\n", "case", "end", ":", "nesting", "--", "\n", "switch", "{", "case", "nesting", "<", "0", ":", "return", "name", "// Mismatch, abort", "\n", "case", "nesting", "==", "0", ":", "name", "=", "name", "[", ":", "first", "]", "+", "name", "[", "current", "+", "1", ":", "]", "\n", "current", "=", "first", "-", "1", "\n", "}", "\n", "}", "\n", "current", "++", "\n", "}", "\n", "return", "name", "\n", "}" ]
// removeMatching removes nested instances of start..end from name.
[ "removeMatching", "removes", "nested", "instances", "of", "start", "..", "end", "from", "name", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/symbolizer/symbolizer.go#L257-L280
train
google/pprof
internal/driver/commands.go
help
func (c *command) help(name string) string { message := c.description + "\n" if c.usage != "" { message += " Usage:\n" lines := strings.Split(c.usage, "\n") for _, line := range lines { message += fmt.Sprintf(" %s\n", line) } } return message + "\n" }
go
func (c *command) help(name string) string { message := c.description + "\n" if c.usage != "" { message += " Usage:\n" lines := strings.Split(c.usage, "\n") for _, line := range lines { message += fmt.Sprintf(" %s\n", line) } } return message + "\n" }
[ "func", "(", "c", "*", "command", ")", "help", "(", "name", "string", ")", "string", "{", "message", ":=", "c", ".", "description", "+", "\"", "\\n", "\"", "\n", "if", "c", ".", "usage", "!=", "\"", "\"", "{", "message", "+=", "\"", "\\n", "\"", "\n", "lines", ":=", "strings", ".", "Split", "(", "c", ".", "usage", ",", "\"", "\\n", "\"", ")", "\n", "for", "_", ",", "line", ":=", "range", "lines", "{", "message", "+=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "line", ")", "\n", "}", "\n", "}", "\n", "return", "message", "+", "\"", "\\n", "\"", "\n", "}" ]
// help returns a help string for a command.
[ "help", "returns", "a", "help", "string", "for", "a", "command", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/commands.go#L50-L60
train
google/pprof
internal/driver/commands.go
AddCommand
func AddCommand(cmd string, format int, post PostProcessor, desc, usage string) { pprofCommands[cmd] = &command{format, post, nil, false, desc, usage} }
go
func AddCommand(cmd string, format int, post PostProcessor, desc, usage string) { pprofCommands[cmd] = &command{format, post, nil, false, desc, usage} }
[ "func", "AddCommand", "(", "cmd", "string", ",", "format", "int", ",", "post", "PostProcessor", ",", "desc", ",", "usage", "string", ")", "{", "pprofCommands", "[", "cmd", "]", "=", "&", "command", "{", "format", ",", "post", ",", "nil", ",", "false", ",", "desc", ",", "usage", "}", "\n", "}" ]
// AddCommand adds an additional command to the set of commands // accepted by pprof. This enables extensions to add new commands for // specialized visualization formats. If the command specified already // exists, it is overwritten.
[ "AddCommand", "adds", "an", "additional", "command", "to", "the", "set", "of", "commands", "accepted", "by", "pprof", ".", "This", "enables", "extensions", "to", "add", "new", "commands", "for", "specialized", "visualization", "formats", ".", "If", "the", "command", "specified", "already", "exists", "it", "is", "overwritten", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/commands.go#L66-L68
train
google/pprof
internal/driver/commands.go
SetVariableDefault
func SetVariableDefault(variable, value string) { if v := pprofVariables[variable]; v != nil { v.value = value } }
go
func SetVariableDefault(variable, value string) { if v := pprofVariables[variable]; v != nil { v.value = value } }
[ "func", "SetVariableDefault", "(", "variable", ",", "value", "string", ")", "{", "if", "v", ":=", "pprofVariables", "[", "variable", "]", ";", "v", "!=", "nil", "{", "v", ".", "value", "=", "value", "\n", "}", "\n", "}" ]
// SetVariableDefault sets the default value for a pprof // variable. This enables extensions to set their own defaults.
[ "SetVariableDefault", "sets", "the", "default", "value", "for", "a", "pprof", "variable", ".", "This", "enables", "extensions", "to", "set", "their", "own", "defaults", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/commands.go#L72-L76
train
google/pprof
internal/driver/commands.go
usage
func usage(commandLine bool) string { var prefix string if commandLine { prefix = "-" } fmtHelp := func(c, d string) string { return fmt.Sprintf(" %-16s %s", c, strings.SplitN(d, "\n", 2)[0]) } var commands []string for name, cmd := range pprofCommands { commands = append(commands, fmtHelp(prefix+name, cmd.description)) } sort.Strings(commands) var help string if commandLine { help = " Output formats (select at most one):\n" } else { help = " Commands:\n" commands = append(commands, fmtHelp("o/options", "List options and their current values")) commands = append(commands, fmtHelp("quit/exit/^D", "Exit pprof")) } help = help + strings.Join(commands, "\n") + "\n\n" + " Options:\n" // Print help for variables after sorting them. // Collect radio variables by their group name to print them together. radioOptions := make(map[string][]string) var variables []string for name, vr := range pprofVariables { if vr.group != "" { radioOptions[vr.group] = append(radioOptions[vr.group], name) continue } variables = append(variables, fmtHelp(prefix+name, vr.help)) } sort.Strings(variables) help = help + strings.Join(variables, "\n") + "\n\n" + " Option groups (only set one per group):\n" var radioStrings []string for radio, ops := range radioOptions { sort.Strings(ops) s := []string{fmtHelp(radio, "")} for _, op := range ops { s = append(s, " "+fmtHelp(prefix+op, pprofVariables[op].help)) } radioStrings = append(radioStrings, strings.Join(s, "\n")) } sort.Strings(radioStrings) return help + strings.Join(radioStrings, "\n") }
go
func usage(commandLine bool) string { var prefix string if commandLine { prefix = "-" } fmtHelp := func(c, d string) string { return fmt.Sprintf(" %-16s %s", c, strings.SplitN(d, "\n", 2)[0]) } var commands []string for name, cmd := range pprofCommands { commands = append(commands, fmtHelp(prefix+name, cmd.description)) } sort.Strings(commands) var help string if commandLine { help = " Output formats (select at most one):\n" } else { help = " Commands:\n" commands = append(commands, fmtHelp("o/options", "List options and their current values")) commands = append(commands, fmtHelp("quit/exit/^D", "Exit pprof")) } help = help + strings.Join(commands, "\n") + "\n\n" + " Options:\n" // Print help for variables after sorting them. // Collect radio variables by their group name to print them together. radioOptions := make(map[string][]string) var variables []string for name, vr := range pprofVariables { if vr.group != "" { radioOptions[vr.group] = append(radioOptions[vr.group], name) continue } variables = append(variables, fmtHelp(prefix+name, vr.help)) } sort.Strings(variables) help = help + strings.Join(variables, "\n") + "\n\n" + " Option groups (only set one per group):\n" var radioStrings []string for radio, ops := range radioOptions { sort.Strings(ops) s := []string{fmtHelp(radio, "")} for _, op := range ops { s = append(s, " "+fmtHelp(prefix+op, pprofVariables[op].help)) } radioStrings = append(radioStrings, strings.Join(s, "\n")) } sort.Strings(radioStrings) return help + strings.Join(radioStrings, "\n") }
[ "func", "usage", "(", "commandLine", "bool", ")", "string", "{", "var", "prefix", "string", "\n", "if", "commandLine", "{", "prefix", "=", "\"", "\"", "\n", "}", "\n", "fmtHelp", ":=", "func", "(", "c", ",", "d", "string", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ",", "strings", ".", "SplitN", "(", "d", ",", "\"", "\\n", "\"", ",", "2", ")", "[", "0", "]", ")", "\n", "}", "\n\n", "var", "commands", "[", "]", "string", "\n", "for", "name", ",", "cmd", ":=", "range", "pprofCommands", "{", "commands", "=", "append", "(", "commands", ",", "fmtHelp", "(", "prefix", "+", "name", ",", "cmd", ".", "description", ")", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "commands", ")", "\n\n", "var", "help", "string", "\n", "if", "commandLine", "{", "help", "=", "\"", "\\n", "\"", "\n", "}", "else", "{", "help", "=", "\"", "\\n", "\"", "\n", "commands", "=", "append", "(", "commands", ",", "fmtHelp", "(", "\"", "\"", ",", "\"", "\"", ")", ")", "\n", "commands", "=", "append", "(", "commands", ",", "fmtHelp", "(", "\"", "\"", ",", "\"", "\"", ")", ")", "\n", "}", "\n\n", "help", "=", "help", "+", "strings", ".", "Join", "(", "commands", ",", "\"", "\\n", "\"", ")", "+", "\"", "\\n", "\\n", "\"", "+", "\"", "\\n", "\"", "\n\n", "// Print help for variables after sorting them.", "// Collect radio variables by their group name to print them together.", "radioOptions", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "var", "variables", "[", "]", "string", "\n", "for", "name", ",", "vr", ":=", "range", "pprofVariables", "{", "if", "vr", ".", "group", "!=", "\"", "\"", "{", "radioOptions", "[", "vr", ".", "group", "]", "=", "append", "(", "radioOptions", "[", "vr", ".", "group", "]", ",", "name", ")", "\n", "continue", "\n", "}", "\n", "variables", "=", "append", "(", "variables", ",", "fmtHelp", "(", "prefix", "+", "name", ",", "vr", ".", "help", ")", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "variables", ")", "\n\n", "help", "=", "help", "+", "strings", ".", "Join", "(", "variables", ",", "\"", "\\n", "\"", ")", "+", "\"", "\\n", "\\n", "\"", "+", "\"", "\\n", "\"", "\n\n", "var", "radioStrings", "[", "]", "string", "\n", "for", "radio", ",", "ops", ":=", "range", "radioOptions", "{", "sort", ".", "Strings", "(", "ops", ")", "\n", "s", ":=", "[", "]", "string", "{", "fmtHelp", "(", "radio", ",", "\"", "\"", ")", "}", "\n", "for", "_", ",", "op", ":=", "range", "ops", "{", "s", "=", "append", "(", "s", ",", "\"", "\"", "+", "fmtHelp", "(", "prefix", "+", "op", ",", "pprofVariables", "[", "op", "]", ".", "help", ")", ")", "\n", "}", "\n\n", "radioStrings", "=", "append", "(", "radioStrings", ",", "strings", ".", "Join", "(", "s", ",", "\"", "\\n", "\"", ")", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "radioStrings", ")", "\n", "return", "help", "+", "strings", ".", "Join", "(", "radioStrings", ",", "\"", "\\n", "\"", ")", "\n", "}" ]
// usage returns a string describing the pprof commands and variables. // if commandLine is set, the output reflect cli usage.
[ "usage", "returns", "a", "string", "describing", "the", "pprof", "commands", "and", "variables", ".", "if", "commandLine", "is", "set", "the", "output", "reflect", "cli", "usage", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/commands.go#L251-L306
train
google/pprof
internal/driver/commands.go
browsers
func browsers() []string { var cmds []string if userBrowser := os.Getenv("BROWSER"); userBrowser != "" { cmds = append(cmds, userBrowser) } switch runtime.GOOS { case "darwin": cmds = append(cmds, "/usr/bin/open") case "windows": cmds = append(cmds, "cmd /c start") default: // Commands opening browsers are prioritized over xdg-open, so browser() // command can be used on linux to open the .svg file generated by the -web // command (the .svg file includes embedded javascript so is best viewed in // a browser). cmds = append(cmds, []string{"chrome", "google-chrome", "chromium", "firefox", "sensible-browser"}...) if os.Getenv("DISPLAY") != "" { // xdg-open is only for use in a desktop environment. cmds = append(cmds, "xdg-open") } } return cmds }
go
func browsers() []string { var cmds []string if userBrowser := os.Getenv("BROWSER"); userBrowser != "" { cmds = append(cmds, userBrowser) } switch runtime.GOOS { case "darwin": cmds = append(cmds, "/usr/bin/open") case "windows": cmds = append(cmds, "cmd /c start") default: // Commands opening browsers are prioritized over xdg-open, so browser() // command can be used on linux to open the .svg file generated by the -web // command (the .svg file includes embedded javascript so is best viewed in // a browser). cmds = append(cmds, []string{"chrome", "google-chrome", "chromium", "firefox", "sensible-browser"}...) if os.Getenv("DISPLAY") != "" { // xdg-open is only for use in a desktop environment. cmds = append(cmds, "xdg-open") } } return cmds }
[ "func", "browsers", "(", ")", "[", "]", "string", "{", "var", "cmds", "[", "]", "string", "\n", "if", "userBrowser", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", ";", "userBrowser", "!=", "\"", "\"", "{", "cmds", "=", "append", "(", "cmds", ",", "userBrowser", ")", "\n", "}", "\n", "switch", "runtime", ".", "GOOS", "{", "case", "\"", "\"", ":", "cmds", "=", "append", "(", "cmds", ",", "\"", "\"", ")", "\n", "case", "\"", "\"", ":", "cmds", "=", "append", "(", "cmds", ",", "\"", "\"", ")", "\n", "default", ":", "// Commands opening browsers are prioritized over xdg-open, so browser()", "// command can be used on linux to open the .svg file generated by the -web", "// command (the .svg file includes embedded javascript so is best viewed in", "// a browser).", "cmds", "=", "append", "(", "cmds", ",", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", "...", ")", "\n", "if", "os", ".", "Getenv", "(", "\"", "\"", ")", "!=", "\"", "\"", "{", "// xdg-open is only for use in a desktop environment.", "cmds", "=", "append", "(", "cmds", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "return", "cmds", "\n", "}" ]
// browsers returns a list of commands to attempt for web visualization.
[ "browsers", "returns", "a", "list", "of", "commands", "to", "attempt", "for", "web", "visualization", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/commands.go#L339-L361
train
google/pprof
internal/driver/commands.go
massageDotSVG
func massageDotSVG() PostProcessor { generateSVG := invokeDot("svg") return func(input io.Reader, output io.Writer, ui plugin.UI) error { baseSVG := new(bytes.Buffer) if err := generateSVG(input, baseSVG, ui); err != nil { return err } _, err := output.Write([]byte(massageSVG(baseSVG.String()))) return err } }
go
func massageDotSVG() PostProcessor { generateSVG := invokeDot("svg") return func(input io.Reader, output io.Writer, ui plugin.UI) error { baseSVG := new(bytes.Buffer) if err := generateSVG(input, baseSVG, ui); err != nil { return err } _, err := output.Write([]byte(massageSVG(baseSVG.String()))) return err } }
[ "func", "massageDotSVG", "(", ")", "PostProcessor", "{", "generateSVG", ":=", "invokeDot", "(", "\"", "\"", ")", "\n", "return", "func", "(", "input", "io", ".", "Reader", ",", "output", "io", ".", "Writer", ",", "ui", "plugin", ".", "UI", ")", "error", "{", "baseSVG", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "if", "err", ":=", "generateSVG", "(", "input", ",", "baseSVG", ",", "ui", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "err", ":=", "output", ".", "Write", "(", "[", "]", "byte", "(", "massageSVG", "(", "baseSVG", ".", "String", "(", ")", ")", ")", ")", "\n", "return", "err", "\n", "}", "\n", "}" ]
// massageDotSVG invokes the dot tool to generate an SVG image and alters // the image to have panning capabilities when viewed in a browser.
[ "massageDotSVG", "invokes", "the", "dot", "tool", "to", "generate", "an", "SVG", "image", "and", "alters", "the", "image", "to", "have", "panning", "capabilities", "when", "viewed", "in", "a", "browser", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/commands.go#L396-L406
train
google/pprof
internal/driver/commands.go
set
func (vars variables) set(name, value string) error { v := vars[name] if v == nil { return fmt.Errorf("no variable %s", name) } var err error switch v.kind { case boolKind: var b bool if b, err = stringToBool(value); err == nil { if v.group != "" && !b { err = fmt.Errorf("%q can only be set to true", name) } } case intKind: _, err = strconv.Atoi(value) case floatKind: _, err = strconv.ParseFloat(value, 64) case stringKind: // Remove quotes, particularly useful for empty values. if len(value) > 1 && strings.HasPrefix(value, `"`) && strings.HasSuffix(value, `"`) { value = value[1 : len(value)-1] } } if err != nil { return err } vars[name].value = value if group := vars[name].group; group != "" { for vname, vvar := range vars { if vvar.group == group && vname != name { vvar.value = "f" } } } return err }
go
func (vars variables) set(name, value string) error { v := vars[name] if v == nil { return fmt.Errorf("no variable %s", name) } var err error switch v.kind { case boolKind: var b bool if b, err = stringToBool(value); err == nil { if v.group != "" && !b { err = fmt.Errorf("%q can only be set to true", name) } } case intKind: _, err = strconv.Atoi(value) case floatKind: _, err = strconv.ParseFloat(value, 64) case stringKind: // Remove quotes, particularly useful for empty values. if len(value) > 1 && strings.HasPrefix(value, `"`) && strings.HasSuffix(value, `"`) { value = value[1 : len(value)-1] } } if err != nil { return err } vars[name].value = value if group := vars[name].group; group != "" { for vname, vvar := range vars { if vvar.group == group && vname != name { vvar.value = "f" } } } return err }
[ "func", "(", "vars", "variables", ")", "set", "(", "name", ",", "value", "string", ")", "error", "{", "v", ":=", "vars", "[", "name", "]", "\n", "if", "v", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "var", "err", "error", "\n", "switch", "v", ".", "kind", "{", "case", "boolKind", ":", "var", "b", "bool", "\n", "if", "b", ",", "err", "=", "stringToBool", "(", "value", ")", ";", "err", "==", "nil", "{", "if", "v", ".", "group", "!=", "\"", "\"", "&&", "!", "b", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "}", "\n", "case", "intKind", ":", "_", ",", "err", "=", "strconv", ".", "Atoi", "(", "value", ")", "\n", "case", "floatKind", ":", "_", ",", "err", "=", "strconv", ".", "ParseFloat", "(", "value", ",", "64", ")", "\n", "case", "stringKind", ":", "// Remove quotes, particularly useful for empty values.", "if", "len", "(", "value", ")", ">", "1", "&&", "strings", ".", "HasPrefix", "(", "value", ",", "`\"`", ")", "&&", "strings", ".", "HasSuffix", "(", "value", ",", "`\"`", ")", "{", "value", "=", "value", "[", "1", ":", "len", "(", "value", ")", "-", "1", "]", "\n", "}", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "vars", "[", "name", "]", ".", "value", "=", "value", "\n", "if", "group", ":=", "vars", "[", "name", "]", ".", "group", ";", "group", "!=", "\"", "\"", "{", "for", "vname", ",", "vvar", ":=", "range", "vars", "{", "if", "vvar", ".", "group", "==", "group", "&&", "vname", "!=", "name", "{", "vvar", ".", "value", "=", "\"", "\"", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
// set updates the value of a variable, checking that the value is // suitable for the variable Kind.
[ "set", "updates", "the", "value", "of", "a", "variable", "checking", "that", "the", "value", "is", "suitable", "for", "the", "variable", "Kind", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/commands.go#L469-L505
train
google/pprof
internal/driver/commands.go
boolValue
func (v *variable) boolValue() bool { b, err := stringToBool(v.value) if err != nil { panic("unexpected value " + v.value + " for bool ") } return b }
go
func (v *variable) boolValue() bool { b, err := stringToBool(v.value) if err != nil { panic("unexpected value " + v.value + " for bool ") } return b }
[ "func", "(", "v", "*", "variable", ")", "boolValue", "(", ")", "bool", "{", "b", ",", "err", ":=", "stringToBool", "(", "v", ".", "value", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "\"", "\"", "+", "v", ".", "value", "+", "\"", "\"", ")", "\n", "}", "\n", "return", "b", "\n", "}" ]
// boolValue returns the value of a boolean variable.
[ "boolValue", "returns", "the", "value", "of", "a", "boolean", "variable", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/commands.go#L508-L514
train
google/pprof
internal/driver/commands.go
intValue
func (v *variable) intValue() int { i, err := strconv.Atoi(v.value) if err != nil { panic("unexpected value " + v.value + " for int ") } return i }
go
func (v *variable) intValue() int { i, err := strconv.Atoi(v.value) if err != nil { panic("unexpected value " + v.value + " for int ") } return i }
[ "func", "(", "v", "*", "variable", ")", "intValue", "(", ")", "int", "{", "i", ",", "err", ":=", "strconv", ".", "Atoi", "(", "v", ".", "value", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "\"", "\"", "+", "v", ".", "value", "+", "\"", "\"", ")", "\n", "}", "\n", "return", "i", "\n", "}" ]
// intValue returns the value of an intKind variable.
[ "intValue", "returns", "the", "value", "of", "an", "intKind", "variable", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/commands.go#L517-L523
train
google/pprof
internal/driver/commands.go
floatValue
func (v *variable) floatValue() float64 { f, err := strconv.ParseFloat(v.value, 64) if err != nil { panic("unexpected value " + v.value + " for float ") } return f }
go
func (v *variable) floatValue() float64 { f, err := strconv.ParseFloat(v.value, 64) if err != nil { panic("unexpected value " + v.value + " for float ") } return f }
[ "func", "(", "v", "*", "variable", ")", "floatValue", "(", ")", "float64", "{", "f", ",", "err", ":=", "strconv", ".", "ParseFloat", "(", "v", ".", "value", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "\"", "\"", "+", "v", ".", "value", "+", "\"", "\"", ")", "\n", "}", "\n", "return", "f", "\n", "}" ]
// floatValue returns the value of a Float variable.
[ "floatValue", "returns", "the", "value", "of", "a", "Float", "variable", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/commands.go#L526-L532
train
google/pprof
internal/driver/commands.go
stringValue
func (v *variable) stringValue() string { switch v.kind { case boolKind: return fmt.Sprint(v.boolValue()) case intKind: return fmt.Sprint(v.intValue()) case floatKind: return fmt.Sprint(v.floatValue()) } return v.value }
go
func (v *variable) stringValue() string { switch v.kind { case boolKind: return fmt.Sprint(v.boolValue()) case intKind: return fmt.Sprint(v.intValue()) case floatKind: return fmt.Sprint(v.floatValue()) } return v.value }
[ "func", "(", "v", "*", "variable", ")", "stringValue", "(", ")", "string", "{", "switch", "v", ".", "kind", "{", "case", "boolKind", ":", "return", "fmt", ".", "Sprint", "(", "v", ".", "boolValue", "(", ")", ")", "\n", "case", "intKind", ":", "return", "fmt", ".", "Sprint", "(", "v", ".", "intValue", "(", ")", ")", "\n", "case", "floatKind", ":", "return", "fmt", ".", "Sprint", "(", "v", ".", "floatValue", "(", ")", ")", "\n", "}", "\n", "return", "v", ".", "value", "\n", "}" ]
// stringValue returns a canonical representation for a variable.
[ "stringValue", "returns", "a", "canonical", "representation", "for", "a", "variable", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/commands.go#L535-L545
train
google/pprof
internal/driver/commands.go
makeCopy
func (vars variables) makeCopy() variables { varscopy := make(variables, len(vars)) for n, v := range vars { vcopy := *v varscopy[n] = &vcopy } return varscopy }
go
func (vars variables) makeCopy() variables { varscopy := make(variables, len(vars)) for n, v := range vars { vcopy := *v varscopy[n] = &vcopy } return varscopy }
[ "func", "(", "vars", "variables", ")", "makeCopy", "(", ")", "variables", "{", "varscopy", ":=", "make", "(", "variables", ",", "len", "(", "vars", ")", ")", "\n", "for", "n", ",", "v", ":=", "range", "vars", "{", "vcopy", ":=", "*", "v", "\n", "varscopy", "[", "n", "]", "=", "&", "vcopy", "\n", "}", "\n", "return", "varscopy", "\n", "}" ]
// makeCopy returns a duplicate of a set of shell variables.
[ "makeCopy", "returns", "a", "duplicate", "of", "a", "set", "of", "shell", "variables", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/commands.go#L559-L566
train
google/pprof
internal/driver/fetch.go
chunkedGrab
func chunkedGrab(sources []profileSource, fetch plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI, tr http.RoundTripper) (*profile.Profile, plugin.MappingSources, bool, int, error) { const chunkSize = 64 var p *profile.Profile var msrc plugin.MappingSources var save bool var count int for start := 0; start < len(sources); start += chunkSize { end := start + chunkSize if end > len(sources) { end = len(sources) } chunkP, chunkMsrc, chunkSave, chunkCount, chunkErr := concurrentGrab(sources[start:end], fetch, obj, ui, tr) switch { case chunkErr != nil: return nil, nil, false, 0, chunkErr case chunkP == nil: continue case p == nil: p, msrc, save, count = chunkP, chunkMsrc, chunkSave, chunkCount default: p, msrc, chunkErr = combineProfiles([]*profile.Profile{p, chunkP}, []plugin.MappingSources{msrc, chunkMsrc}) if chunkErr != nil { return nil, nil, false, 0, chunkErr } if chunkSave { save = true } count += chunkCount } } return p, msrc, save, count, nil }
go
func chunkedGrab(sources []profileSource, fetch plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI, tr http.RoundTripper) (*profile.Profile, plugin.MappingSources, bool, int, error) { const chunkSize = 64 var p *profile.Profile var msrc plugin.MappingSources var save bool var count int for start := 0; start < len(sources); start += chunkSize { end := start + chunkSize if end > len(sources) { end = len(sources) } chunkP, chunkMsrc, chunkSave, chunkCount, chunkErr := concurrentGrab(sources[start:end], fetch, obj, ui, tr) switch { case chunkErr != nil: return nil, nil, false, 0, chunkErr case chunkP == nil: continue case p == nil: p, msrc, save, count = chunkP, chunkMsrc, chunkSave, chunkCount default: p, msrc, chunkErr = combineProfiles([]*profile.Profile{p, chunkP}, []plugin.MappingSources{msrc, chunkMsrc}) if chunkErr != nil { return nil, nil, false, 0, chunkErr } if chunkSave { save = true } count += chunkCount } } return p, msrc, save, count, nil }
[ "func", "chunkedGrab", "(", "sources", "[", "]", "profileSource", ",", "fetch", "plugin", ".", "Fetcher", ",", "obj", "plugin", ".", "ObjTool", ",", "ui", "plugin", ".", "UI", ",", "tr", "http", ".", "RoundTripper", ")", "(", "*", "profile", ".", "Profile", ",", "plugin", ".", "MappingSources", ",", "bool", ",", "int", ",", "error", ")", "{", "const", "chunkSize", "=", "64", "\n\n", "var", "p", "*", "profile", ".", "Profile", "\n", "var", "msrc", "plugin", ".", "MappingSources", "\n", "var", "save", "bool", "\n", "var", "count", "int", "\n\n", "for", "start", ":=", "0", ";", "start", "<", "len", "(", "sources", ")", ";", "start", "+=", "chunkSize", "{", "end", ":=", "start", "+", "chunkSize", "\n", "if", "end", ">", "len", "(", "sources", ")", "{", "end", "=", "len", "(", "sources", ")", "\n", "}", "\n", "chunkP", ",", "chunkMsrc", ",", "chunkSave", ",", "chunkCount", ",", "chunkErr", ":=", "concurrentGrab", "(", "sources", "[", "start", ":", "end", "]", ",", "fetch", ",", "obj", ",", "ui", ",", "tr", ")", "\n", "switch", "{", "case", "chunkErr", "!=", "nil", ":", "return", "nil", ",", "nil", ",", "false", ",", "0", ",", "chunkErr", "\n", "case", "chunkP", "==", "nil", ":", "continue", "\n", "case", "p", "==", "nil", ":", "p", ",", "msrc", ",", "save", ",", "count", "=", "chunkP", ",", "chunkMsrc", ",", "chunkSave", ",", "chunkCount", "\n", "default", ":", "p", ",", "msrc", ",", "chunkErr", "=", "combineProfiles", "(", "[", "]", "*", "profile", ".", "Profile", "{", "p", ",", "chunkP", "}", ",", "[", "]", "plugin", ".", "MappingSources", "{", "msrc", ",", "chunkMsrc", "}", ")", "\n", "if", "chunkErr", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "false", ",", "0", ",", "chunkErr", "\n", "}", "\n", "if", "chunkSave", "{", "save", "=", "true", "\n", "}", "\n", "count", "+=", "chunkCount", "\n", "}", "\n", "}", "\n\n", "return", "p", ",", "msrc", ",", "save", ",", "count", ",", "nil", "\n", "}" ]
// chunkedGrab fetches the profiles described in source and merges them into // a single profile. It fetches a chunk of profiles concurrently, with a maximum // chunk size to limit its memory usage.
[ "chunkedGrab", "fetches", "the", "profiles", "described", "in", "source", "and", "merges", "them", "into", "a", "single", "profile", ".", "It", "fetches", "a", "chunk", "of", "profiles", "concurrently", "with", "a", "maximum", "chunk", "size", "to", "limit", "its", "memory", "usage", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L169-L203
train
google/pprof
internal/driver/fetch.go
concurrentGrab
func concurrentGrab(sources []profileSource, fetch plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI, tr http.RoundTripper) (*profile.Profile, plugin.MappingSources, bool, int, error) { wg := sync.WaitGroup{} wg.Add(len(sources)) for i := range sources { go func(s *profileSource) { defer wg.Done() s.p, s.msrc, s.remote, s.err = grabProfile(s.source, s.addr, fetch, obj, ui, tr) }(&sources[i]) } wg.Wait() var save bool profiles := make([]*profile.Profile, 0, len(sources)) msrcs := make([]plugin.MappingSources, 0, len(sources)) for i := range sources { s := &sources[i] if err := s.err; err != nil { ui.PrintErr(s.addr + ": " + err.Error()) continue } save = save || s.remote profiles = append(profiles, s.p) msrcs = append(msrcs, s.msrc) *s = profileSource{} } if len(profiles) == 0 { return nil, nil, false, 0, nil } p, msrc, err := combineProfiles(profiles, msrcs) if err != nil { return nil, nil, false, 0, err } return p, msrc, save, len(profiles), nil }
go
func concurrentGrab(sources []profileSource, fetch plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI, tr http.RoundTripper) (*profile.Profile, plugin.MappingSources, bool, int, error) { wg := sync.WaitGroup{} wg.Add(len(sources)) for i := range sources { go func(s *profileSource) { defer wg.Done() s.p, s.msrc, s.remote, s.err = grabProfile(s.source, s.addr, fetch, obj, ui, tr) }(&sources[i]) } wg.Wait() var save bool profiles := make([]*profile.Profile, 0, len(sources)) msrcs := make([]plugin.MappingSources, 0, len(sources)) for i := range sources { s := &sources[i] if err := s.err; err != nil { ui.PrintErr(s.addr + ": " + err.Error()) continue } save = save || s.remote profiles = append(profiles, s.p) msrcs = append(msrcs, s.msrc) *s = profileSource{} } if len(profiles) == 0 { return nil, nil, false, 0, nil } p, msrc, err := combineProfiles(profiles, msrcs) if err != nil { return nil, nil, false, 0, err } return p, msrc, save, len(profiles), nil }
[ "func", "concurrentGrab", "(", "sources", "[", "]", "profileSource", ",", "fetch", "plugin", ".", "Fetcher", ",", "obj", "plugin", ".", "ObjTool", ",", "ui", "plugin", ".", "UI", ",", "tr", "http", ".", "RoundTripper", ")", "(", "*", "profile", ".", "Profile", ",", "plugin", ".", "MappingSources", ",", "bool", ",", "int", ",", "error", ")", "{", "wg", ":=", "sync", ".", "WaitGroup", "{", "}", "\n", "wg", ".", "Add", "(", "len", "(", "sources", ")", ")", "\n", "for", "i", ":=", "range", "sources", "{", "go", "func", "(", "s", "*", "profileSource", ")", "{", "defer", "wg", ".", "Done", "(", ")", "\n", "s", ".", "p", ",", "s", ".", "msrc", ",", "s", ".", "remote", ",", "s", ".", "err", "=", "grabProfile", "(", "s", ".", "source", ",", "s", ".", "addr", ",", "fetch", ",", "obj", ",", "ui", ",", "tr", ")", "\n", "}", "(", "&", "sources", "[", "i", "]", ")", "\n", "}", "\n", "wg", ".", "Wait", "(", ")", "\n\n", "var", "save", "bool", "\n", "profiles", ":=", "make", "(", "[", "]", "*", "profile", ".", "Profile", ",", "0", ",", "len", "(", "sources", ")", ")", "\n", "msrcs", ":=", "make", "(", "[", "]", "plugin", ".", "MappingSources", ",", "0", ",", "len", "(", "sources", ")", ")", "\n", "for", "i", ":=", "range", "sources", "{", "s", ":=", "&", "sources", "[", "i", "]", "\n", "if", "err", ":=", "s", ".", "err", ";", "err", "!=", "nil", "{", "ui", ".", "PrintErr", "(", "s", ".", "addr", "+", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "continue", "\n", "}", "\n", "save", "=", "save", "||", "s", ".", "remote", "\n", "profiles", "=", "append", "(", "profiles", ",", "s", ".", "p", ")", "\n", "msrcs", "=", "append", "(", "msrcs", ",", "s", ".", "msrc", ")", "\n", "*", "s", "=", "profileSource", "{", "}", "\n", "}", "\n\n", "if", "len", "(", "profiles", ")", "==", "0", "{", "return", "nil", ",", "nil", ",", "false", ",", "0", ",", "nil", "\n", "}", "\n\n", "p", ",", "msrc", ",", "err", ":=", "combineProfiles", "(", "profiles", ",", "msrcs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "false", ",", "0", ",", "err", "\n", "}", "\n", "return", "p", ",", "msrc", ",", "save", ",", "len", "(", "profiles", ")", ",", "nil", "\n", "}" ]
// concurrentGrab fetches multiple profiles concurrently
[ "concurrentGrab", "fetches", "multiple", "profiles", "concurrently" ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L206-L241
train
google/pprof
internal/driver/fetch.go
grabProfile
func grabProfile(s *source, source string, fetcher plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI, tr http.RoundTripper) (p *profile.Profile, msrc plugin.MappingSources, remote bool, err error) { var src string duration, timeout := time.Duration(s.Seconds)*time.Second, time.Duration(s.Timeout)*time.Second if fetcher != nil { p, src, err = fetcher.Fetch(source, duration, timeout) if err != nil { return } } if err != nil || p == nil { // Fetch the profile over HTTP or from a file. p, src, err = fetch(source, duration, timeout, ui, tr) if err != nil { return } } if err = p.CheckValid(); err != nil { return } // Update the binary locations from command line and paths. locateBinaries(p, s, obj, ui) // Collect the source URL for all mappings. if src != "" { msrc = collectMappingSources(p, src) remote = true if strings.HasPrefix(src, "http://"+testSourceAddress) { // Treat test inputs as local to avoid saving // testcase profiles during driver testing. remote = false } } return }
go
func grabProfile(s *source, source string, fetcher plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI, tr http.RoundTripper) (p *profile.Profile, msrc plugin.MappingSources, remote bool, err error) { var src string duration, timeout := time.Duration(s.Seconds)*time.Second, time.Duration(s.Timeout)*time.Second if fetcher != nil { p, src, err = fetcher.Fetch(source, duration, timeout) if err != nil { return } } if err != nil || p == nil { // Fetch the profile over HTTP or from a file. p, src, err = fetch(source, duration, timeout, ui, tr) if err != nil { return } } if err = p.CheckValid(); err != nil { return } // Update the binary locations from command line and paths. locateBinaries(p, s, obj, ui) // Collect the source URL for all mappings. if src != "" { msrc = collectMappingSources(p, src) remote = true if strings.HasPrefix(src, "http://"+testSourceAddress) { // Treat test inputs as local to avoid saving // testcase profiles during driver testing. remote = false } } return }
[ "func", "grabProfile", "(", "s", "*", "source", ",", "source", "string", ",", "fetcher", "plugin", ".", "Fetcher", ",", "obj", "plugin", ".", "ObjTool", ",", "ui", "plugin", ".", "UI", ",", "tr", "http", ".", "RoundTripper", ")", "(", "p", "*", "profile", ".", "Profile", ",", "msrc", "plugin", ".", "MappingSources", ",", "remote", "bool", ",", "err", "error", ")", "{", "var", "src", "string", "\n", "duration", ",", "timeout", ":=", "time", ".", "Duration", "(", "s", ".", "Seconds", ")", "*", "time", ".", "Second", ",", "time", ".", "Duration", "(", "s", ".", "Timeout", ")", "*", "time", ".", "Second", "\n", "if", "fetcher", "!=", "nil", "{", "p", ",", "src", ",", "err", "=", "fetcher", ".", "Fetch", "(", "source", ",", "duration", ",", "timeout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n", "if", "err", "!=", "nil", "||", "p", "==", "nil", "{", "// Fetch the profile over HTTP or from a file.", "p", ",", "src", ",", "err", "=", "fetch", "(", "source", ",", "duration", ",", "timeout", ",", "ui", ",", "tr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n\n", "if", "err", "=", "p", ".", "CheckValid", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "// Update the binary locations from command line and paths.", "locateBinaries", "(", "p", ",", "s", ",", "obj", ",", "ui", ")", "\n\n", "// Collect the source URL for all mappings.", "if", "src", "!=", "\"", "\"", "{", "msrc", "=", "collectMappingSources", "(", "p", ",", "src", ")", "\n", "remote", "=", "true", "\n", "if", "strings", ".", "HasPrefix", "(", "src", ",", "\"", "\"", "+", "testSourceAddress", ")", "{", "// Treat test inputs as local to avoid saving", "// testcase profiles during driver testing.", "remote", "=", "false", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// grabProfile fetches a profile. Returns the profile, sources for the // profile mappings, a bool indicating if the profile was fetched // remotely, and an error.
[ "grabProfile", "fetches", "a", "profile", ".", "Returns", "the", "profile", "sources", "for", "the", "profile", "mappings", "a", "bool", "indicating", "if", "the", "profile", "was", "fetched", "remotely", "and", "an", "error", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L312-L347
train
google/pprof
internal/driver/fetch.go
collectMappingSources
func collectMappingSources(p *profile.Profile, source string) plugin.MappingSources { ms := plugin.MappingSources{} for _, m := range p.Mapping { src := struct { Source string Start uint64 }{ source, m.Start, } key := m.BuildID if key == "" { key = m.File } if key == "" { // If there is no build id or source file, use the source as the // mapping file. This will enable remote symbolization for this // mapping, in particular for Go profiles on the legacy format. // The source is reset back to empty string by unsourceMapping // which is called after symbolization is finished. m.File = source key = source } ms[key] = append(ms[key], src) } return ms }
go
func collectMappingSources(p *profile.Profile, source string) plugin.MappingSources { ms := plugin.MappingSources{} for _, m := range p.Mapping { src := struct { Source string Start uint64 }{ source, m.Start, } key := m.BuildID if key == "" { key = m.File } if key == "" { // If there is no build id or source file, use the source as the // mapping file. This will enable remote symbolization for this // mapping, in particular for Go profiles on the legacy format. // The source is reset back to empty string by unsourceMapping // which is called after symbolization is finished. m.File = source key = source } ms[key] = append(ms[key], src) } return ms }
[ "func", "collectMappingSources", "(", "p", "*", "profile", ".", "Profile", ",", "source", "string", ")", "plugin", ".", "MappingSources", "{", "ms", ":=", "plugin", ".", "MappingSources", "{", "}", "\n", "for", "_", ",", "m", ":=", "range", "p", ".", "Mapping", "{", "src", ":=", "struct", "{", "Source", "string", "\n", "Start", "uint64", "\n", "}", "{", "source", ",", "m", ".", "Start", ",", "}", "\n", "key", ":=", "m", ".", "BuildID", "\n", "if", "key", "==", "\"", "\"", "{", "key", "=", "m", ".", "File", "\n", "}", "\n", "if", "key", "==", "\"", "\"", "{", "// If there is no build id or source file, use the source as the", "// mapping file. This will enable remote symbolization for this", "// mapping, in particular for Go profiles on the legacy format.", "// The source is reset back to empty string by unsourceMapping", "// which is called after symbolization is finished.", "m", ".", "File", "=", "source", "\n", "key", "=", "source", "\n", "}", "\n", "ms", "[", "key", "]", "=", "append", "(", "ms", "[", "key", "]", ",", "src", ")", "\n", "}", "\n", "return", "ms", "\n", "}" ]
// collectMappingSources saves the mapping sources of a profile.
[ "collectMappingSources", "saves", "the", "mapping", "sources", "of", "a", "profile", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L350-L375
train
google/pprof
internal/driver/fetch.go
unsourceMappings
func unsourceMappings(p *profile.Profile) { for _, m := range p.Mapping { if m.BuildID == "" { if u, err := url.Parse(m.File); err == nil && u.IsAbs() { m.File = "" } } } }
go
func unsourceMappings(p *profile.Profile) { for _, m := range p.Mapping { if m.BuildID == "" { if u, err := url.Parse(m.File); err == nil && u.IsAbs() { m.File = "" } } } }
[ "func", "unsourceMappings", "(", "p", "*", "profile", ".", "Profile", ")", "{", "for", "_", ",", "m", ":=", "range", "p", ".", "Mapping", "{", "if", "m", ".", "BuildID", "==", "\"", "\"", "{", "if", "u", ",", "err", ":=", "url", ".", "Parse", "(", "m", ".", "File", ")", ";", "err", "==", "nil", "&&", "u", ".", "IsAbs", "(", ")", "{", "m", ".", "File", "=", "\"", "\"", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// unsourceMappings iterates over the mappings in a profile and replaces file // set to the remote source URL by collectMappingSources back to empty string.
[ "unsourceMappings", "iterates", "over", "the", "mappings", "in", "a", "profile", "and", "replaces", "file", "set", "to", "the", "remote", "source", "URL", "by", "collectMappingSources", "back", "to", "empty", "string", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L379-L387
train
google/pprof
internal/driver/fetch.go
locateBinaries
func locateBinaries(p *profile.Profile, s *source, obj plugin.ObjTool, ui plugin.UI) { // Construct search path to examine searchPath := os.Getenv("PPROF_BINARY_PATH") if searchPath == "" { // Use $HOME/pprof/binaries as default directory for local symbolization binaries searchPath = filepath.Join(os.Getenv(homeEnv()), "pprof", "binaries") } mapping: for _, m := range p.Mapping { var baseName string if m.File != "" { baseName = filepath.Base(m.File) } for _, path := range filepath.SplitList(searchPath) { var fileNames []string if m.BuildID != "" { fileNames = []string{filepath.Join(path, m.BuildID, baseName)} if matches, err := filepath.Glob(filepath.Join(path, m.BuildID, "*")); err == nil { fileNames = append(fileNames, matches...) } fileNames = append(fileNames, filepath.Join(path, m.File, m.BuildID)) // perf path format } if m.File != "" { // Try both the basename and the full path, to support the same directory // structure as the perf symfs option. if baseName != "" { fileNames = append(fileNames, filepath.Join(path, baseName)) } fileNames = append(fileNames, filepath.Join(path, m.File)) } for _, name := range fileNames { if f, err := obj.Open(name, m.Start, m.Limit, m.Offset); err == nil { defer f.Close() fileBuildID := f.BuildID() if m.BuildID != "" && m.BuildID != fileBuildID { ui.PrintErr("Ignoring local file " + name + ": build-id mismatch (" + m.BuildID + " != " + fileBuildID + ")") } else { m.File = name continue mapping } } } } } if len(p.Mapping) == 0 { // If there are no mappings, add a fake mapping to attempt symbolization. // This is useful for some profiles generated by the golang runtime, which // do not include any mappings. Symbolization with a fake mapping will only // be successful against a non-PIE binary. m := &profile.Mapping{ID: 1} p.Mapping = []*profile.Mapping{m} for _, l := range p.Location { l.Mapping = m } } // Replace executable filename/buildID with the overrides from source. // Assumes the executable is the first Mapping entry. if execName, buildID := s.ExecName, s.BuildID; execName != "" || buildID != "" { m := p.Mapping[0] if execName != "" { m.File = execName } if buildID != "" { m.BuildID = buildID } } }
go
func locateBinaries(p *profile.Profile, s *source, obj plugin.ObjTool, ui plugin.UI) { // Construct search path to examine searchPath := os.Getenv("PPROF_BINARY_PATH") if searchPath == "" { // Use $HOME/pprof/binaries as default directory for local symbolization binaries searchPath = filepath.Join(os.Getenv(homeEnv()), "pprof", "binaries") } mapping: for _, m := range p.Mapping { var baseName string if m.File != "" { baseName = filepath.Base(m.File) } for _, path := range filepath.SplitList(searchPath) { var fileNames []string if m.BuildID != "" { fileNames = []string{filepath.Join(path, m.BuildID, baseName)} if matches, err := filepath.Glob(filepath.Join(path, m.BuildID, "*")); err == nil { fileNames = append(fileNames, matches...) } fileNames = append(fileNames, filepath.Join(path, m.File, m.BuildID)) // perf path format } if m.File != "" { // Try both the basename and the full path, to support the same directory // structure as the perf symfs option. if baseName != "" { fileNames = append(fileNames, filepath.Join(path, baseName)) } fileNames = append(fileNames, filepath.Join(path, m.File)) } for _, name := range fileNames { if f, err := obj.Open(name, m.Start, m.Limit, m.Offset); err == nil { defer f.Close() fileBuildID := f.BuildID() if m.BuildID != "" && m.BuildID != fileBuildID { ui.PrintErr("Ignoring local file " + name + ": build-id mismatch (" + m.BuildID + " != " + fileBuildID + ")") } else { m.File = name continue mapping } } } } } if len(p.Mapping) == 0 { // If there are no mappings, add a fake mapping to attempt symbolization. // This is useful for some profiles generated by the golang runtime, which // do not include any mappings. Symbolization with a fake mapping will only // be successful against a non-PIE binary. m := &profile.Mapping{ID: 1} p.Mapping = []*profile.Mapping{m} for _, l := range p.Location { l.Mapping = m } } // Replace executable filename/buildID with the overrides from source. // Assumes the executable is the first Mapping entry. if execName, buildID := s.ExecName, s.BuildID; execName != "" || buildID != "" { m := p.Mapping[0] if execName != "" { m.File = execName } if buildID != "" { m.BuildID = buildID } } }
[ "func", "locateBinaries", "(", "p", "*", "profile", ".", "Profile", ",", "s", "*", "source", ",", "obj", "plugin", ".", "ObjTool", ",", "ui", "plugin", ".", "UI", ")", "{", "// Construct search path to examine", "searchPath", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "searchPath", "==", "\"", "\"", "{", "// Use $HOME/pprof/binaries as default directory for local symbolization binaries", "searchPath", "=", "filepath", ".", "Join", "(", "os", ".", "Getenv", "(", "homeEnv", "(", ")", ")", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "\n", "mapping", ":", "for", "_", ",", "m", ":=", "range", "p", ".", "Mapping", "{", "var", "baseName", "string", "\n", "if", "m", ".", "File", "!=", "\"", "\"", "{", "baseName", "=", "filepath", ".", "Base", "(", "m", ".", "File", ")", "\n", "}", "\n\n", "for", "_", ",", "path", ":=", "range", "filepath", ".", "SplitList", "(", "searchPath", ")", "{", "var", "fileNames", "[", "]", "string", "\n", "if", "m", ".", "BuildID", "!=", "\"", "\"", "{", "fileNames", "=", "[", "]", "string", "{", "filepath", ".", "Join", "(", "path", ",", "m", ".", "BuildID", ",", "baseName", ")", "}", "\n", "if", "matches", ",", "err", ":=", "filepath", ".", "Glob", "(", "filepath", ".", "Join", "(", "path", ",", "m", ".", "BuildID", ",", "\"", "\"", ")", ")", ";", "err", "==", "nil", "{", "fileNames", "=", "append", "(", "fileNames", ",", "matches", "...", ")", "\n", "}", "\n", "fileNames", "=", "append", "(", "fileNames", ",", "filepath", ".", "Join", "(", "path", ",", "m", ".", "File", ",", "m", ".", "BuildID", ")", ")", "// perf path format", "\n", "}", "\n", "if", "m", ".", "File", "!=", "\"", "\"", "{", "// Try both the basename and the full path, to support the same directory", "// structure as the perf symfs option.", "if", "baseName", "!=", "\"", "\"", "{", "fileNames", "=", "append", "(", "fileNames", ",", "filepath", ".", "Join", "(", "path", ",", "baseName", ")", ")", "\n", "}", "\n", "fileNames", "=", "append", "(", "fileNames", ",", "filepath", ".", "Join", "(", "path", ",", "m", ".", "File", ")", ")", "\n", "}", "\n", "for", "_", ",", "name", ":=", "range", "fileNames", "{", "if", "f", ",", "err", ":=", "obj", ".", "Open", "(", "name", ",", "m", ".", "Start", ",", "m", ".", "Limit", ",", "m", ".", "Offset", ")", ";", "err", "==", "nil", "{", "defer", "f", ".", "Close", "(", ")", "\n", "fileBuildID", ":=", "f", ".", "BuildID", "(", ")", "\n", "if", "m", ".", "BuildID", "!=", "\"", "\"", "&&", "m", ".", "BuildID", "!=", "fileBuildID", "{", "ui", ".", "PrintErr", "(", "\"", "\"", "+", "name", "+", "\"", "\"", "+", "m", ".", "BuildID", "+", "\"", "\"", "+", "fileBuildID", "+", "\"", "\"", ")", "\n", "}", "else", "{", "m", ".", "File", "=", "name", "\n", "continue", "mapping", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "len", "(", "p", ".", "Mapping", ")", "==", "0", "{", "// If there are no mappings, add a fake mapping to attempt symbolization.", "// This is useful for some profiles generated by the golang runtime, which", "// do not include any mappings. Symbolization with a fake mapping will only", "// be successful against a non-PIE binary.", "m", ":=", "&", "profile", ".", "Mapping", "{", "ID", ":", "1", "}", "\n", "p", ".", "Mapping", "=", "[", "]", "*", "profile", ".", "Mapping", "{", "m", "}", "\n", "for", "_", ",", "l", ":=", "range", "p", ".", "Location", "{", "l", ".", "Mapping", "=", "m", "\n", "}", "\n", "}", "\n", "// Replace executable filename/buildID with the overrides from source.", "// Assumes the executable is the first Mapping entry.", "if", "execName", ",", "buildID", ":=", "s", ".", "ExecName", ",", "s", ".", "BuildID", ";", "execName", "!=", "\"", "\"", "||", "buildID", "!=", "\"", "\"", "{", "m", ":=", "p", ".", "Mapping", "[", "0", "]", "\n", "if", "execName", "!=", "\"", "\"", "{", "m", ".", "File", "=", "execName", "\n", "}", "\n", "if", "buildID", "!=", "\"", "\"", "{", "m", ".", "BuildID", "=", "buildID", "\n", "}", "\n", "}", "\n", "}" ]
// locateBinaries searches for binary files listed in the profile and, if found, // updates the profile accordingly.
[ "locateBinaries", "searches", "for", "binary", "files", "listed", "in", "the", "profile", "and", "if", "found", "updates", "the", "profile", "accordingly", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L391-L458
train
google/pprof
internal/driver/fetch.go
fetch
func fetch(source string, duration, timeout time.Duration, ui plugin.UI, tr http.RoundTripper) (p *profile.Profile, src string, err error) { var f io.ReadCloser if sourceURL, timeout := adjustURL(source, duration, timeout); sourceURL != "" { ui.Print("Fetching profile over HTTP from " + sourceURL) if duration > 0 { ui.Print(fmt.Sprintf("Please wait... (%v)", duration)) } f, err = fetchURL(sourceURL, timeout, tr) src = sourceURL } else if isPerfFile(source) { f, err = convertPerfData(source, ui) } else { f, err = os.Open(source) } if err == nil { defer f.Close() p, err = profile.Parse(f) } return }
go
func fetch(source string, duration, timeout time.Duration, ui plugin.UI, tr http.RoundTripper) (p *profile.Profile, src string, err error) { var f io.ReadCloser if sourceURL, timeout := adjustURL(source, duration, timeout); sourceURL != "" { ui.Print("Fetching profile over HTTP from " + sourceURL) if duration > 0 { ui.Print(fmt.Sprintf("Please wait... (%v)", duration)) } f, err = fetchURL(sourceURL, timeout, tr) src = sourceURL } else if isPerfFile(source) { f, err = convertPerfData(source, ui) } else { f, err = os.Open(source) } if err == nil { defer f.Close() p, err = profile.Parse(f) } return }
[ "func", "fetch", "(", "source", "string", ",", "duration", ",", "timeout", "time", ".", "Duration", ",", "ui", "plugin", ".", "UI", ",", "tr", "http", ".", "RoundTripper", ")", "(", "p", "*", "profile", ".", "Profile", ",", "src", "string", ",", "err", "error", ")", "{", "var", "f", "io", ".", "ReadCloser", "\n\n", "if", "sourceURL", ",", "timeout", ":=", "adjustURL", "(", "source", ",", "duration", ",", "timeout", ")", ";", "sourceURL", "!=", "\"", "\"", "{", "ui", ".", "Print", "(", "\"", "\"", "+", "sourceURL", ")", "\n", "if", "duration", ">", "0", "{", "ui", ".", "Print", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "duration", ")", ")", "\n", "}", "\n", "f", ",", "err", "=", "fetchURL", "(", "sourceURL", ",", "timeout", ",", "tr", ")", "\n", "src", "=", "sourceURL", "\n", "}", "else", "if", "isPerfFile", "(", "source", ")", "{", "f", ",", "err", "=", "convertPerfData", "(", "source", ",", "ui", ")", "\n", "}", "else", "{", "f", ",", "err", "=", "os", ".", "Open", "(", "source", ")", "\n", "}", "\n", "if", "err", "==", "nil", "{", "defer", "f", ".", "Close", "(", ")", "\n", "p", ",", "err", "=", "profile", ".", "Parse", "(", "f", ")", "\n", "}", "\n", "return", "\n", "}" ]
// fetch fetches a profile from source, within the timeout specified, // producing messages through the ui. It returns the profile and the // url of the actual source of the profile for remote profiles.
[ "fetch", "fetches", "a", "profile", "from", "source", "within", "the", "timeout", "specified", "producing", "messages", "through", "the", "ui", ".", "It", "returns", "the", "profile", "and", "the", "url", "of", "the", "actual", "source", "of", "the", "profile", "for", "remote", "profiles", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L463-L483
train
google/pprof
internal/driver/fetch.go
fetchURL
func fetchURL(source string, timeout time.Duration, tr http.RoundTripper) (io.ReadCloser, error) { client := &http.Client{ Transport: tr, Timeout: timeout + 5*time.Second, } resp, err := client.Get(source) if err != nil { return nil, fmt.Errorf("http fetch: %v", err) } if resp.StatusCode != http.StatusOK { defer resp.Body.Close() return nil, statusCodeError(resp) } return resp.Body, nil }
go
func fetchURL(source string, timeout time.Duration, tr http.RoundTripper) (io.ReadCloser, error) { client := &http.Client{ Transport: tr, Timeout: timeout + 5*time.Second, } resp, err := client.Get(source) if err != nil { return nil, fmt.Errorf("http fetch: %v", err) } if resp.StatusCode != http.StatusOK { defer resp.Body.Close() return nil, statusCodeError(resp) } return resp.Body, nil }
[ "func", "fetchURL", "(", "source", "string", ",", "timeout", "time", ".", "Duration", ",", "tr", "http", ".", "RoundTripper", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "client", ":=", "&", "http", ".", "Client", "{", "Transport", ":", "tr", ",", "Timeout", ":", "timeout", "+", "5", "*", "time", ".", "Second", ",", "}", "\n", "resp", ",", "err", ":=", "client", ".", "Get", "(", "source", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "resp", ".", "StatusCode", "!=", "http", ".", "StatusOK", "{", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "return", "nil", ",", "statusCodeError", "(", "resp", ")", "\n", "}", "\n\n", "return", "resp", ".", "Body", ",", "nil", "\n", "}" ]
// fetchURL fetches a profile from a URL using HTTP.
[ "fetchURL", "fetches", "a", "profile", "from", "a", "URL", "using", "HTTP", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L486-L501
train
google/pprof
internal/driver/fetch.go
isPerfFile
func isPerfFile(path string) bool { sourceFile, openErr := os.Open(path) if openErr != nil { return false } defer sourceFile.Close() // If the file is the output of a perf record command, it should begin // with the string PERFILE2. perfHeader := []byte("PERFILE2") actualHeader := make([]byte, len(perfHeader)) if _, readErr := sourceFile.Read(actualHeader); readErr != nil { return false } return bytes.Equal(actualHeader, perfHeader) }
go
func isPerfFile(path string) bool { sourceFile, openErr := os.Open(path) if openErr != nil { return false } defer sourceFile.Close() // If the file is the output of a perf record command, it should begin // with the string PERFILE2. perfHeader := []byte("PERFILE2") actualHeader := make([]byte, len(perfHeader)) if _, readErr := sourceFile.Read(actualHeader); readErr != nil { return false } return bytes.Equal(actualHeader, perfHeader) }
[ "func", "isPerfFile", "(", "path", "string", ")", "bool", "{", "sourceFile", ",", "openErr", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "openErr", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "defer", "sourceFile", ".", "Close", "(", ")", "\n\n", "// If the file is the output of a perf record command, it should begin", "// with the string PERFILE2.", "perfHeader", ":=", "[", "]", "byte", "(", "\"", "\"", ")", "\n", "actualHeader", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "perfHeader", ")", ")", "\n", "if", "_", ",", "readErr", ":=", "sourceFile", ".", "Read", "(", "actualHeader", ")", ";", "readErr", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "return", "bytes", ".", "Equal", "(", "actualHeader", ",", "perfHeader", ")", "\n", "}" ]
// isPerfFile checks if a file is in perf.data format. It also returns false // if it encounters an error during the check.
[ "isPerfFile", "checks", "if", "a", "file", "is", "in", "perf", ".", "data", "format", ".", "It", "also", "returns", "false", "if", "it", "encounters", "an", "error", "during", "the", "check", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L515-L530
train
google/pprof
internal/driver/fetch.go
convertPerfData
func convertPerfData(perfPath string, ui plugin.UI) (*os.File, error) { ui.Print(fmt.Sprintf( "Converting %s to a profile.proto... (May take a few minutes)", perfPath)) profile, err := newTempFile(os.TempDir(), "pprof_", ".pb.gz") if err != nil { return nil, err } deferDeleteTempFile(profile.Name()) cmd := exec.Command("perf_to_profile", "-i", perfPath, "-o", profile.Name(), "-f") cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr if err := cmd.Run(); err != nil { profile.Close() return nil, fmt.Errorf("failed to convert perf.data file. Try github.com/google/perf_data_converter: %v", err) } return profile, nil }
go
func convertPerfData(perfPath string, ui plugin.UI) (*os.File, error) { ui.Print(fmt.Sprintf( "Converting %s to a profile.proto... (May take a few minutes)", perfPath)) profile, err := newTempFile(os.TempDir(), "pprof_", ".pb.gz") if err != nil { return nil, err } deferDeleteTempFile(profile.Name()) cmd := exec.Command("perf_to_profile", "-i", perfPath, "-o", profile.Name(), "-f") cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr if err := cmd.Run(); err != nil { profile.Close() return nil, fmt.Errorf("failed to convert perf.data file. Try github.com/google/perf_data_converter: %v", err) } return profile, nil }
[ "func", "convertPerfData", "(", "perfPath", "string", ",", "ui", "plugin", ".", "UI", ")", "(", "*", "os", ".", "File", ",", "error", ")", "{", "ui", ".", "Print", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "perfPath", ")", ")", "\n", "profile", ",", "err", ":=", "newTempFile", "(", "os", ".", "TempDir", "(", ")", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "deferDeleteTempFile", "(", "profile", ".", "Name", "(", ")", ")", "\n", "cmd", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "perfPath", ",", "\"", "\"", ",", "profile", ".", "Name", "(", ")", ",", "\"", "\"", ")", "\n", "cmd", ".", "Stdout", ",", "cmd", ".", "Stderr", "=", "os", ".", "Stdout", ",", "os", ".", "Stderr", "\n", "if", "err", ":=", "cmd", ".", "Run", "(", ")", ";", "err", "!=", "nil", "{", "profile", ".", "Close", "(", ")", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "profile", ",", "nil", "\n", "}" ]
// convertPerfData converts the file at path which should be in perf.data format // using the perf_to_profile tool and returns the file containing the // profile.proto formatted data.
[ "convertPerfData", "converts", "the", "file", "at", "path", "which", "should", "be", "in", "perf", ".", "data", "format", "using", "the", "perf_to_profile", "tool", "and", "returns", "the", "file", "containing", "the", "profile", ".", "proto", "formatted", "data", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L535-L551
train
google/pprof
internal/driver/fetch.go
adjustURL
func adjustURL(source string, duration, timeout time.Duration) (string, time.Duration) { u, err := url.Parse(source) if err != nil || (u.Host == "" && u.Scheme != "" && u.Scheme != "file") { // Try adding http:// to catch sources of the form hostname:port/path. // url.Parse treats "hostname" as the scheme. u, err = url.Parse("http://" + source) } if err != nil || u.Host == "" { return "", 0 } // Apply duration/timeout overrides to URL. values := u.Query() if duration > 0 { values.Set("seconds", fmt.Sprint(int(duration.Seconds()))) } else { if urlSeconds := values.Get("seconds"); urlSeconds != "" { if us, err := strconv.ParseInt(urlSeconds, 10, 32); err == nil { duration = time.Duration(us) * time.Second } } } if timeout <= 0 { if duration > 0 { timeout = duration + duration/2 } else { timeout = 60 * time.Second } } u.RawQuery = values.Encode() return u.String(), timeout }
go
func adjustURL(source string, duration, timeout time.Duration) (string, time.Duration) { u, err := url.Parse(source) if err != nil || (u.Host == "" && u.Scheme != "" && u.Scheme != "file") { // Try adding http:// to catch sources of the form hostname:port/path. // url.Parse treats "hostname" as the scheme. u, err = url.Parse("http://" + source) } if err != nil || u.Host == "" { return "", 0 } // Apply duration/timeout overrides to URL. values := u.Query() if duration > 0 { values.Set("seconds", fmt.Sprint(int(duration.Seconds()))) } else { if urlSeconds := values.Get("seconds"); urlSeconds != "" { if us, err := strconv.ParseInt(urlSeconds, 10, 32); err == nil { duration = time.Duration(us) * time.Second } } } if timeout <= 0 { if duration > 0 { timeout = duration + duration/2 } else { timeout = 60 * time.Second } } u.RawQuery = values.Encode() return u.String(), timeout }
[ "func", "adjustURL", "(", "source", "string", ",", "duration", ",", "timeout", "time", ".", "Duration", ")", "(", "string", ",", "time", ".", "Duration", ")", "{", "u", ",", "err", ":=", "url", ".", "Parse", "(", "source", ")", "\n", "if", "err", "!=", "nil", "||", "(", "u", ".", "Host", "==", "\"", "\"", "&&", "u", ".", "Scheme", "!=", "\"", "\"", "&&", "u", ".", "Scheme", "!=", "\"", "\"", ")", "{", "// Try adding http:// to catch sources of the form hostname:port/path.", "// url.Parse treats \"hostname\" as the scheme.", "u", ",", "err", "=", "url", ".", "Parse", "(", "\"", "\"", "+", "source", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "||", "u", ".", "Host", "==", "\"", "\"", "{", "return", "\"", "\"", ",", "0", "\n", "}", "\n\n", "// Apply duration/timeout overrides to URL.", "values", ":=", "u", ".", "Query", "(", ")", "\n", "if", "duration", ">", "0", "{", "values", ".", "Set", "(", "\"", "\"", ",", "fmt", ".", "Sprint", "(", "int", "(", "duration", ".", "Seconds", "(", ")", ")", ")", ")", "\n", "}", "else", "{", "if", "urlSeconds", ":=", "values", ".", "Get", "(", "\"", "\"", ")", ";", "urlSeconds", "!=", "\"", "\"", "{", "if", "us", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "urlSeconds", ",", "10", ",", "32", ")", ";", "err", "==", "nil", "{", "duration", "=", "time", ".", "Duration", "(", "us", ")", "*", "time", ".", "Second", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "timeout", "<=", "0", "{", "if", "duration", ">", "0", "{", "timeout", "=", "duration", "+", "duration", "/", "2", "\n", "}", "else", "{", "timeout", "=", "60", "*", "time", ".", "Second", "\n", "}", "\n", "}", "\n", "u", ".", "RawQuery", "=", "values", ".", "Encode", "(", ")", "\n", "return", "u", ".", "String", "(", ")", ",", "timeout", "\n", "}" ]
// adjustURL validates if a profile source is a URL and returns an // cleaned up URL and the timeout to use for retrieval over HTTP. // If the source cannot be recognized as a URL it returns an empty string.
[ "adjustURL", "validates", "if", "a", "profile", "source", "is", "a", "URL", "and", "returns", "an", "cleaned", "up", "URL", "and", "the", "timeout", "to", "use", "for", "retrieval", "over", "HTTP", ".", "If", "the", "source", "cannot", "be", "recognized", "as", "a", "URL", "it", "returns", "an", "empty", "string", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L556-L587
train
google/pprof
internal/transport/transport.go
New
func New(flagset plugin.FlagSet) http.RoundTripper { if flagset == nil { return &transport{} } flagset.AddExtraUsage(extraUsage) return &transport{ cert: flagset.String("tls_cert", "", "TLS client certificate file for fetching profile and symbols"), key: flagset.String("tls_key", "", "TLS private key file for fetching profile and symbols"), ca: flagset.String("tls_ca", "", "TLS CA certs file for fetching profile and symbols"), } }
go
func New(flagset plugin.FlagSet) http.RoundTripper { if flagset == nil { return &transport{} } flagset.AddExtraUsage(extraUsage) return &transport{ cert: flagset.String("tls_cert", "", "TLS client certificate file for fetching profile and symbols"), key: flagset.String("tls_key", "", "TLS private key file for fetching profile and symbols"), ca: flagset.String("tls_ca", "", "TLS CA certs file for fetching profile and symbols"), } }
[ "func", "New", "(", "flagset", "plugin", ".", "FlagSet", ")", "http", ".", "RoundTripper", "{", "if", "flagset", "==", "nil", "{", "return", "&", "transport", "{", "}", "\n", "}", "\n", "flagset", ".", "AddExtraUsage", "(", "extraUsage", ")", "\n", "return", "&", "transport", "{", "cert", ":", "flagset", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ",", "key", ":", "flagset", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ",", "ca", ":", "flagset", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", ",", "}", "\n", "}" ]
// New returns a round tripper for making requests with the // specified cert, key, and ca. The flags tls_cert, tls_key, and tls_ca are // added to the flagset to allow a user to specify the cert, key, and ca. If // the flagset is nil, no flags will be added, and users will not be able to // use these flags.
[ "New", "returns", "a", "round", "tripper", "for", "making", "requests", "with", "the", "specified", "cert", "key", "and", "ca", ".", "The", "flags", "tls_cert", "tls_key", "and", "tls_ca", "are", "added", "to", "the", "flagset", "to", "allow", "a", "user", "to", "specify", "the", "cert", "key", "and", "ca", ".", "If", "the", "flagset", "is", "nil", "no", "flags", "will", "be", "added", "and", "users", "will", "not", "be", "able", "to", "use", "these", "flags", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/transport/transport.go#L49-L59
train
google/pprof
internal/transport/transport.go
initialize
func (tr *transport) initialize() error { var cert, key, ca string if tr.cert != nil { cert = *tr.cert } if tr.key != nil { key = *tr.key } if tr.ca != nil { ca = *tr.ca } if cert != "" && key != "" { tlsCert, err := tls.LoadX509KeyPair(cert, key) if err != nil { return fmt.Errorf("could not load certificate/key pair specified by -tls_cert and -tls_key: %v", err) } tr.certs = []tls.Certificate{tlsCert} } else if cert == "" && key != "" { return fmt.Errorf("-tls_key is specified, so -tls_cert must also be specified") } else if cert != "" && key == "" { return fmt.Errorf("-tls_cert is specified, so -tls_key must also be specified") } if ca != "" { caCertPool := x509.NewCertPool() caCert, err := ioutil.ReadFile(ca) if err != nil { return fmt.Errorf("could not load CA specified by -tls_ca: %v", err) } caCertPool.AppendCertsFromPEM(caCert) tr.caCertPool = caCertPool } return nil }
go
func (tr *transport) initialize() error { var cert, key, ca string if tr.cert != nil { cert = *tr.cert } if tr.key != nil { key = *tr.key } if tr.ca != nil { ca = *tr.ca } if cert != "" && key != "" { tlsCert, err := tls.LoadX509KeyPair(cert, key) if err != nil { return fmt.Errorf("could not load certificate/key pair specified by -tls_cert and -tls_key: %v", err) } tr.certs = []tls.Certificate{tlsCert} } else if cert == "" && key != "" { return fmt.Errorf("-tls_key is specified, so -tls_cert must also be specified") } else if cert != "" && key == "" { return fmt.Errorf("-tls_cert is specified, so -tls_key must also be specified") } if ca != "" { caCertPool := x509.NewCertPool() caCert, err := ioutil.ReadFile(ca) if err != nil { return fmt.Errorf("could not load CA specified by -tls_ca: %v", err) } caCertPool.AppendCertsFromPEM(caCert) tr.caCertPool = caCertPool } return nil }
[ "func", "(", "tr", "*", "transport", ")", "initialize", "(", ")", "error", "{", "var", "cert", ",", "key", ",", "ca", "string", "\n", "if", "tr", ".", "cert", "!=", "nil", "{", "cert", "=", "*", "tr", ".", "cert", "\n", "}", "\n", "if", "tr", ".", "key", "!=", "nil", "{", "key", "=", "*", "tr", ".", "key", "\n", "}", "\n", "if", "tr", ".", "ca", "!=", "nil", "{", "ca", "=", "*", "tr", ".", "ca", "\n", "}", "\n\n", "if", "cert", "!=", "\"", "\"", "&&", "key", "!=", "\"", "\"", "{", "tlsCert", ",", "err", ":=", "tls", ".", "LoadX509KeyPair", "(", "cert", ",", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "tr", ".", "certs", "=", "[", "]", "tls", ".", "Certificate", "{", "tlsCert", "}", "\n", "}", "else", "if", "cert", "==", "\"", "\"", "&&", "key", "!=", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "else", "if", "cert", "!=", "\"", "\"", "&&", "key", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "ca", "!=", "\"", "\"", "{", "caCertPool", ":=", "x509", ".", "NewCertPool", "(", ")", "\n", "caCert", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "ca", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "caCertPool", ".", "AppendCertsFromPEM", "(", "caCert", ")", "\n", "tr", ".", "caCertPool", "=", "caCertPool", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// initialize uses the cert, key, and ca to initialize the certs // to use these when making requests.
[ "initialize", "uses", "the", "cert", "key", "and", "ca", "to", "initialize", "the", "certs", "to", "use", "these", "when", "making", "requests", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/transport/transport.go#L63-L98
train
google/pprof
internal/driver/tempfile.go
newTempFile
func newTempFile(dir, prefix, suffix string) (*os.File, error) { for index := 1; index < 10000; index++ { path := filepath.Join(dir, fmt.Sprintf("%s%03d%s", prefix, index, suffix)) if _, err := os.Stat(path); err != nil { return os.Create(path) } } // Give up return nil, fmt.Errorf("could not create file of the form %s%03d%s", prefix, 1, suffix) }
go
func newTempFile(dir, prefix, suffix string) (*os.File, error) { for index := 1; index < 10000; index++ { path := filepath.Join(dir, fmt.Sprintf("%s%03d%s", prefix, index, suffix)) if _, err := os.Stat(path); err != nil { return os.Create(path) } } // Give up return nil, fmt.Errorf("could not create file of the form %s%03d%s", prefix, 1, suffix) }
[ "func", "newTempFile", "(", "dir", ",", "prefix", ",", "suffix", "string", ")", "(", "*", "os", ".", "File", ",", "error", ")", "{", "for", "index", ":=", "1", ";", "index", "<", "10000", ";", "index", "++", "{", "path", ":=", "filepath", ".", "Join", "(", "dir", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "prefix", ",", "index", ",", "suffix", ")", ")", "\n", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "path", ")", ";", "err", "!=", "nil", "{", "return", "os", ".", "Create", "(", "path", ")", "\n", "}", "\n", "}", "\n", "// Give up", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "prefix", ",", "1", ",", "suffix", ")", "\n", "}" ]
// newTempFile returns a new output file in dir with the provided prefix and suffix.
[ "newTempFile", "returns", "a", "new", "output", "file", "in", "dir", "with", "the", "provided", "prefix", "and", "suffix", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/tempfile.go#L25-L34
train
google/pprof
internal/driver/tempfile.go
cleanupTempFiles
func cleanupTempFiles() { tempFilesMu.Lock() for _, f := range tempFiles { os.Remove(f) } tempFiles = nil tempFilesMu.Unlock() }
go
func cleanupTempFiles() { tempFilesMu.Lock() for _, f := range tempFiles { os.Remove(f) } tempFiles = nil tempFilesMu.Unlock() }
[ "func", "cleanupTempFiles", "(", ")", "{", "tempFilesMu", ".", "Lock", "(", ")", "\n", "for", "_", ",", "f", ":=", "range", "tempFiles", "{", "os", ".", "Remove", "(", "f", ")", "\n", "}", "\n", "tempFiles", "=", "nil", "\n", "tempFilesMu", ".", "Unlock", "(", ")", "\n", "}" ]
// cleanupTempFiles removes any temporary files selected for deferred cleaning.
[ "cleanupTempFiles", "removes", "any", "temporary", "files", "selected", "for", "deferred", "cleaning", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/tempfile.go#L47-L54
train
google/pprof
internal/report/source.go
getSourceFromFile
func getSourceFromFile(file string, reader *sourceReader, fns graph.Nodes, start, end int) (graph.Nodes, string, error) { lineNodes := make(map[int]graph.Nodes) // Collect source coordinates from profile. const margin = 5 // Lines before first/after last sample. if start == 0 { if fns[0].Info.StartLine != 0 { start = fns[0].Info.StartLine } else { start = fns[0].Info.Lineno - margin } } else { start -= margin } if end == 0 { end = fns[0].Info.Lineno } end += margin for _, n := range fns { lineno := n.Info.Lineno nodeStart := n.Info.StartLine if nodeStart == 0 { nodeStart = lineno - margin } nodeEnd := lineno + margin if nodeStart < start { start = nodeStart } else if nodeEnd > end { end = nodeEnd } lineNodes[lineno] = append(lineNodes[lineno], n) } if start < 1 { start = 1 } var src graph.Nodes for lineno := start; lineno <= end; lineno++ { line, ok := reader.line(file, lineno) if !ok { break } flat, cum := lineNodes[lineno].Sum() src = append(src, &graph.Node{ Info: graph.NodeInfo{ Name: strings.TrimRight(line, "\n"), Lineno: lineno, }, Flat: flat, Cum: cum, }) } if err := reader.fileError(file); err != nil { return nil, file, err } return src, file, nil }
go
func getSourceFromFile(file string, reader *sourceReader, fns graph.Nodes, start, end int) (graph.Nodes, string, error) { lineNodes := make(map[int]graph.Nodes) // Collect source coordinates from profile. const margin = 5 // Lines before first/after last sample. if start == 0 { if fns[0].Info.StartLine != 0 { start = fns[0].Info.StartLine } else { start = fns[0].Info.Lineno - margin } } else { start -= margin } if end == 0 { end = fns[0].Info.Lineno } end += margin for _, n := range fns { lineno := n.Info.Lineno nodeStart := n.Info.StartLine if nodeStart == 0 { nodeStart = lineno - margin } nodeEnd := lineno + margin if nodeStart < start { start = nodeStart } else if nodeEnd > end { end = nodeEnd } lineNodes[lineno] = append(lineNodes[lineno], n) } if start < 1 { start = 1 } var src graph.Nodes for lineno := start; lineno <= end; lineno++ { line, ok := reader.line(file, lineno) if !ok { break } flat, cum := lineNodes[lineno].Sum() src = append(src, &graph.Node{ Info: graph.NodeInfo{ Name: strings.TrimRight(line, "\n"), Lineno: lineno, }, Flat: flat, Cum: cum, }) } if err := reader.fileError(file); err != nil { return nil, file, err } return src, file, nil }
[ "func", "getSourceFromFile", "(", "file", "string", ",", "reader", "*", "sourceReader", ",", "fns", "graph", ".", "Nodes", ",", "start", ",", "end", "int", ")", "(", "graph", ".", "Nodes", ",", "string", ",", "error", ")", "{", "lineNodes", ":=", "make", "(", "map", "[", "int", "]", "graph", ".", "Nodes", ")", "\n\n", "// Collect source coordinates from profile.", "const", "margin", "=", "5", "// Lines before first/after last sample.", "\n", "if", "start", "==", "0", "{", "if", "fns", "[", "0", "]", ".", "Info", ".", "StartLine", "!=", "0", "{", "start", "=", "fns", "[", "0", "]", ".", "Info", ".", "StartLine", "\n", "}", "else", "{", "start", "=", "fns", "[", "0", "]", ".", "Info", ".", "Lineno", "-", "margin", "\n", "}", "\n", "}", "else", "{", "start", "-=", "margin", "\n", "}", "\n", "if", "end", "==", "0", "{", "end", "=", "fns", "[", "0", "]", ".", "Info", ".", "Lineno", "\n", "}", "\n", "end", "+=", "margin", "\n", "for", "_", ",", "n", ":=", "range", "fns", "{", "lineno", ":=", "n", ".", "Info", ".", "Lineno", "\n", "nodeStart", ":=", "n", ".", "Info", ".", "StartLine", "\n", "if", "nodeStart", "==", "0", "{", "nodeStart", "=", "lineno", "-", "margin", "\n", "}", "\n", "nodeEnd", ":=", "lineno", "+", "margin", "\n", "if", "nodeStart", "<", "start", "{", "start", "=", "nodeStart", "\n", "}", "else", "if", "nodeEnd", ">", "end", "{", "end", "=", "nodeEnd", "\n", "}", "\n", "lineNodes", "[", "lineno", "]", "=", "append", "(", "lineNodes", "[", "lineno", "]", ",", "n", ")", "\n", "}", "\n", "if", "start", "<", "1", "{", "start", "=", "1", "\n", "}", "\n\n", "var", "src", "graph", ".", "Nodes", "\n", "for", "lineno", ":=", "start", ";", "lineno", "<=", "end", ";", "lineno", "++", "{", "line", ",", "ok", ":=", "reader", ".", "line", "(", "file", ",", "lineno", ")", "\n", "if", "!", "ok", "{", "break", "\n", "}", "\n", "flat", ",", "cum", ":=", "lineNodes", "[", "lineno", "]", ".", "Sum", "(", ")", "\n", "src", "=", "append", "(", "src", ",", "&", "graph", ".", "Node", "{", "Info", ":", "graph", ".", "NodeInfo", "{", "Name", ":", "strings", ".", "TrimRight", "(", "line", ",", "\"", "\\n", "\"", ")", ",", "Lineno", ":", "lineno", ",", "}", ",", "Flat", ":", "flat", ",", "Cum", ":", "cum", ",", "}", ")", "\n", "}", "\n", "if", "err", ":=", "reader", ".", "fileError", "(", "file", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "file", ",", "err", "\n", "}", "\n", "return", "src", ",", "file", ",", "nil", "\n", "}" ]
// getSourceFromFile collects the sources of a function from a source // file and annotates it with the samples in fns. Returns the sources // as nodes, using the info.name field to hold the source code.
[ "getSourceFromFile", "collects", "the", "sources", "of", "a", "function", "from", "a", "source", "file", "and", "annotates", "it", "with", "the", "samples", "in", "fns", ".", "Returns", "the", "sources", "as", "nodes", "using", "the", "info", ".", "name", "field", "to", "hold", "the", "source", "code", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/report/source.go#L427-L483
train
google/pprof
internal/report/source.go
openSourceFile
func openSourceFile(path, searchPath, trim string) (*os.File, error) { path = trimPath(path, trim, searchPath) // If file is still absolute, require file to exist. if filepath.IsAbs(path) { f, err := os.Open(path) return f, err } // Scan each component of the path. for _, dir := range filepath.SplitList(searchPath) { // Search up for every parent of each possible path. for { filename := filepath.Join(dir, path) if f, err := os.Open(filename); err == nil { return f, nil } parent := filepath.Dir(dir) if parent == dir { break } dir = parent } } return nil, fmt.Errorf("could not find file %s on path %s", path, searchPath) }
go
func openSourceFile(path, searchPath, trim string) (*os.File, error) { path = trimPath(path, trim, searchPath) // If file is still absolute, require file to exist. if filepath.IsAbs(path) { f, err := os.Open(path) return f, err } // Scan each component of the path. for _, dir := range filepath.SplitList(searchPath) { // Search up for every parent of each possible path. for { filename := filepath.Join(dir, path) if f, err := os.Open(filename); err == nil { return f, nil } parent := filepath.Dir(dir) if parent == dir { break } dir = parent } } return nil, fmt.Errorf("could not find file %s on path %s", path, searchPath) }
[ "func", "openSourceFile", "(", "path", ",", "searchPath", ",", "trim", "string", ")", "(", "*", "os", ".", "File", ",", "error", ")", "{", "path", "=", "trimPath", "(", "path", ",", "trim", ",", "searchPath", ")", "\n", "// If file is still absolute, require file to exist.", "if", "filepath", ".", "IsAbs", "(", "path", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "return", "f", ",", "err", "\n", "}", "\n", "// Scan each component of the path.", "for", "_", ",", "dir", ":=", "range", "filepath", ".", "SplitList", "(", "searchPath", ")", "{", "// Search up for every parent of each possible path.", "for", "{", "filename", ":=", "filepath", ".", "Join", "(", "dir", ",", "path", ")", "\n", "if", "f", ",", "err", ":=", "os", ".", "Open", "(", "filename", ")", ";", "err", "==", "nil", "{", "return", "f", ",", "nil", "\n", "}", "\n", "parent", ":=", "filepath", ".", "Dir", "(", "dir", ")", "\n", "if", "parent", "==", "dir", "{", "break", "\n", "}", "\n", "dir", "=", "parent", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "path", ",", "searchPath", ")", "\n", "}" ]
// openSourceFile opens a source file from a name encoded in a profile. File // names in a profile after can be relative paths, so search them in each of // the paths in searchPath and their parents. In case the profile contains // absolute paths, additional paths may be configured to trim from the source // paths in the profile. This effectively turns the path into a relative path // searching it using searchPath as usual).
[ "openSourceFile", "opens", "a", "source", "file", "from", "a", "name", "encoded", "in", "a", "profile", ".", "File", "names", "in", "a", "profile", "after", "can", "be", "relative", "paths", "so", "search", "them", "in", "each", "of", "the", "paths", "in", "searchPath", "and", "their", "parents", ".", "In", "case", "the", "profile", "contains", "absolute", "paths", "additional", "paths", "may", "be", "configured", "to", "trim", "from", "the", "source", "paths", "in", "the", "profile", ".", "This", "effectively", "turns", "the", "path", "into", "a", "relative", "path", "searching", "it", "using", "searchPath", "as", "usual", ")", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/report/source.go#L578-L602
train
google/pprof
internal/report/source_html.go
AddSourceTemplates
func AddSourceTemplates(t *template.Template) { template.Must(t.Parse(`{{define "weblistcss"}}` + weblistPageCSS + `{{end}}`)) template.Must(t.Parse(`{{define "weblistjs"}}` + weblistPageScript + `{{end}}`)) }
go
func AddSourceTemplates(t *template.Template) { template.Must(t.Parse(`{{define "weblistcss"}}` + weblistPageCSS + `{{end}}`)) template.Must(t.Parse(`{{define "weblistjs"}}` + weblistPageScript + `{{end}}`)) }
[ "func", "AddSourceTemplates", "(", "t", "*", "template", ".", "Template", ")", "{", "template", ".", "Must", "(", "t", ".", "Parse", "(", "`{{define \"weblistcss\"}}`", "+", "weblistPageCSS", "+", "`{{end}}`", ")", ")", "\n", "template", ".", "Must", "(", "t", ".", "Parse", "(", "`{{define \"weblistjs\"}}`", "+", "weblistPageScript", "+", "`{{end}}`", ")", ")", "\n", "}" ]
// AddSourceTemplates adds templates used by PrintWebList to t.
[ "AddSourceTemplates", "adds", "templates", "used", "by", "PrintWebList", "to", "t", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/report/source_html.go#L22-L25
train
google/pprof
profile/encode.go
padStringArray
func padStringArray(arr []string, l int) []string { if l <= len(arr) { return arr } return append(arr, make([]string, l-len(arr))...) }
go
func padStringArray(arr []string, l int) []string { if l <= len(arr) { return arr } return append(arr, make([]string, l-len(arr))...) }
[ "func", "padStringArray", "(", "arr", "[", "]", "string", ",", "l", "int", ")", "[", "]", "string", "{", "if", "l", "<=", "len", "(", "arr", ")", "{", "return", "arr", "\n", "}", "\n", "return", "append", "(", "arr", ",", "make", "(", "[", "]", "string", ",", "l", "-", "len", "(", "arr", ")", ")", "...", ")", "\n", "}" ]
// padStringArray pads arr with enough empty strings to make arr // length l when arr's length is less than l.
[ "padStringArray", "pads", "arr", "with", "enough", "empty", "strings", "to", "make", "arr", "length", "l", "when", "arr", "s", "length", "is", "less", "than", "l", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/encode.go#L372-L377
train
google/pprof
internal/binutils/addr2liner.go
newAddr2Liner
func newAddr2Liner(cmd, file string, base uint64) (*addr2Liner, error) { if cmd == "" { cmd = defaultAddr2line } j := &addr2LinerJob{ cmd: exec.Command(cmd, "-aif", "-e", file), } var err error if j.in, err = j.cmd.StdinPipe(); err != nil { return nil, err } outPipe, err := j.cmd.StdoutPipe() if err != nil { return nil, err } j.out = bufio.NewReader(outPipe) if err := j.cmd.Start(); err != nil { return nil, err } a := &addr2Liner{ rw: j, base: base, } return a, nil }
go
func newAddr2Liner(cmd, file string, base uint64) (*addr2Liner, error) { if cmd == "" { cmd = defaultAddr2line } j := &addr2LinerJob{ cmd: exec.Command(cmd, "-aif", "-e", file), } var err error if j.in, err = j.cmd.StdinPipe(); err != nil { return nil, err } outPipe, err := j.cmd.StdoutPipe() if err != nil { return nil, err } j.out = bufio.NewReader(outPipe) if err := j.cmd.Start(); err != nil { return nil, err } a := &addr2Liner{ rw: j, base: base, } return a, nil }
[ "func", "newAddr2Liner", "(", "cmd", ",", "file", "string", ",", "base", "uint64", ")", "(", "*", "addr2Liner", ",", "error", ")", "{", "if", "cmd", "==", "\"", "\"", "{", "cmd", "=", "defaultAddr2line", "\n", "}", "\n\n", "j", ":=", "&", "addr2LinerJob", "{", "cmd", ":", "exec", ".", "Command", "(", "cmd", ",", "\"", "\"", ",", "\"", "\"", ",", "file", ")", ",", "}", "\n\n", "var", "err", "error", "\n", "if", "j", ".", "in", ",", "err", "=", "j", ".", "cmd", ".", "StdinPipe", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "outPipe", ",", "err", ":=", "j", ".", "cmd", ".", "StdoutPipe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "j", ".", "out", "=", "bufio", ".", "NewReader", "(", "outPipe", ")", "\n", "if", "err", ":=", "j", ".", "cmd", ".", "Start", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "a", ":=", "&", "addr2Liner", "{", "rw", ":", "j", ",", "base", ":", "base", ",", "}", "\n\n", "return", "a", ",", "nil", "\n", "}" ]
// newAddr2liner starts the given addr2liner command reporting // information about the given executable file. If file is a shared // library, base should be the address at which it was mapped in the // program under consideration.
[ "newAddr2liner", "starts", "the", "given", "addr2liner", "command", "reporting", "information", "about", "the", "given", "executable", "file", ".", "If", "file", "is", "a", "shared", "library", "base", "should", "be", "the", "address", "at", "which", "it", "was", "mapped", "in", "the", "program", "under", "consideration", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/binutils/addr2liner.go#L86-L116
train
google/pprof
internal/binutils/addr2liner.go
readFrame
func (d *addr2Liner) readFrame() (plugin.Frame, bool) { funcname, err := d.readString() if err != nil { return plugin.Frame{}, true } if strings.HasPrefix(funcname, "0x") { // If addr2line returns a hex address we can assume it is the // sentinel. Read and ignore next two lines of output from // addr2line d.readString() d.readString() return plugin.Frame{}, true } fileline, err := d.readString() if err != nil { return plugin.Frame{}, true } linenumber := 0 if funcname == "??" { funcname = "" } if fileline == "??:0" { fileline = "" } else { if i := strings.LastIndex(fileline, ":"); i >= 0 { // Remove discriminator, if present if disc := strings.Index(fileline, " (discriminator"); disc > 0 { fileline = fileline[:disc] } // If we cannot parse a number after the last ":", keep it as // part of the filename. if line, err := strconv.Atoi(fileline[i+1:]); err == nil { linenumber = line fileline = fileline[:i] } } } return plugin.Frame{ Func: funcname, File: fileline, Line: linenumber}, false }
go
func (d *addr2Liner) readFrame() (plugin.Frame, bool) { funcname, err := d.readString() if err != nil { return plugin.Frame{}, true } if strings.HasPrefix(funcname, "0x") { // If addr2line returns a hex address we can assume it is the // sentinel. Read and ignore next two lines of output from // addr2line d.readString() d.readString() return plugin.Frame{}, true } fileline, err := d.readString() if err != nil { return plugin.Frame{}, true } linenumber := 0 if funcname == "??" { funcname = "" } if fileline == "??:0" { fileline = "" } else { if i := strings.LastIndex(fileline, ":"); i >= 0 { // Remove discriminator, if present if disc := strings.Index(fileline, " (discriminator"); disc > 0 { fileline = fileline[:disc] } // If we cannot parse a number after the last ":", keep it as // part of the filename. if line, err := strconv.Atoi(fileline[i+1:]); err == nil { linenumber = line fileline = fileline[:i] } } } return plugin.Frame{ Func: funcname, File: fileline, Line: linenumber}, false }
[ "func", "(", "d", "*", "addr2Liner", ")", "readFrame", "(", ")", "(", "plugin", ".", "Frame", ",", "bool", ")", "{", "funcname", ",", "err", ":=", "d", ".", "readString", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "plugin", ".", "Frame", "{", "}", ",", "true", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "funcname", ",", "\"", "\"", ")", "{", "// If addr2line returns a hex address we can assume it is the", "// sentinel. Read and ignore next two lines of output from", "// addr2line", "d", ".", "readString", "(", ")", "\n", "d", ".", "readString", "(", ")", "\n", "return", "plugin", ".", "Frame", "{", "}", ",", "true", "\n", "}", "\n\n", "fileline", ",", "err", ":=", "d", ".", "readString", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "plugin", ".", "Frame", "{", "}", ",", "true", "\n", "}", "\n\n", "linenumber", ":=", "0", "\n\n", "if", "funcname", "==", "\"", "\"", "{", "funcname", "=", "\"", "\"", "\n", "}", "\n\n", "if", "fileline", "==", "\"", "\"", "{", "fileline", "=", "\"", "\"", "\n", "}", "else", "{", "if", "i", ":=", "strings", ".", "LastIndex", "(", "fileline", ",", "\"", "\"", ")", ";", "i", ">=", "0", "{", "// Remove discriminator, if present", "if", "disc", ":=", "strings", ".", "Index", "(", "fileline", ",", "\"", "\"", ")", ";", "disc", ">", "0", "{", "fileline", "=", "fileline", "[", ":", "disc", "]", "\n", "}", "\n", "// If we cannot parse a number after the last \":\", keep it as", "// part of the filename.", "if", "line", ",", "err", ":=", "strconv", ".", "Atoi", "(", "fileline", "[", "i", "+", "1", ":", "]", ")", ";", "err", "==", "nil", "{", "linenumber", "=", "line", "\n", "fileline", "=", "fileline", "[", ":", "i", "]", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "plugin", ".", "Frame", "{", "Func", ":", "funcname", ",", "File", ":", "fileline", ",", "Line", ":", "linenumber", "}", ",", "false", "\n", "}" ]
// readFrame parses the addr2line output for a single address. It // returns a populated plugin.Frame and whether it has reached the end of the // data.
[ "readFrame", "parses", "the", "addr2line", "output", "for", "a", "single", "address", ".", "It", "returns", "a", "populated", "plugin", ".", "Frame", "and", "whether", "it", "has", "reached", "the", "end", "of", "the", "data", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/binutils/addr2liner.go#L129-L175
train
google/pprof
internal/driver/driver.go
identifyNumLabelUnits
func identifyNumLabelUnits(p *profile.Profile, ui plugin.UI) map[string]string { numLabelUnits, ignoredUnits := p.NumLabelUnits() // Print errors for tags with multiple units associated with // a single key. for k, units := range ignoredUnits { ui.PrintErr(fmt.Sprintf("For tag %s used unit %s, also encountered unit(s) %s", k, numLabelUnits[k], strings.Join(units, ", "))) } return numLabelUnits }
go
func identifyNumLabelUnits(p *profile.Profile, ui plugin.UI) map[string]string { numLabelUnits, ignoredUnits := p.NumLabelUnits() // Print errors for tags with multiple units associated with // a single key. for k, units := range ignoredUnits { ui.PrintErr(fmt.Sprintf("For tag %s used unit %s, also encountered unit(s) %s", k, numLabelUnits[k], strings.Join(units, ", "))) } return numLabelUnits }
[ "func", "identifyNumLabelUnits", "(", "p", "*", "profile", ".", "Profile", ",", "ui", "plugin", ".", "UI", ")", "map", "[", "string", "]", "string", "{", "numLabelUnits", ",", "ignoredUnits", ":=", "p", ".", "NumLabelUnits", "(", ")", "\n\n", "// Print errors for tags with multiple units associated with", "// a single key.", "for", "k", ",", "units", ":=", "range", "ignoredUnits", "{", "ui", ".", "PrintErr", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "numLabelUnits", "[", "k", "]", ",", "strings", ".", "Join", "(", "units", ",", "\"", "\"", ")", ")", ")", "\n", "}", "\n", "return", "numLabelUnits", "\n", "}" ]
// identifyNumLabelUnits returns a map of numeric label keys to the units // associated with those keys.
[ "identifyNumLabelUnits", "returns", "a", "map", "of", "numeric", "label", "keys", "to", "the", "units", "associated", "with", "those", "keys", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/driver.go#L295-L304
train
google/pprof
internal/binutils/disasm.go
disassemble
func disassemble(asm []byte) ([]plugin.Inst, error) { buf := bytes.NewBuffer(asm) function, file, line := "", "", 0 var assembly []plugin.Inst for { input, err := buf.ReadString('\n') if err != nil { if err != io.EOF { return nil, err } if input == "" { break } } if fields := objdumpAsmOutputRE.FindStringSubmatch(input); len(fields) == 3 { if address, err := strconv.ParseUint(fields[1], 16, 64); err == nil { assembly = append(assembly, plugin.Inst{ Addr: address, Text: fields[2], Function: function, File: file, Line: line, }) continue } } if fields := objdumpOutputFileLine.FindStringSubmatch(input); len(fields) == 3 { if l, err := strconv.ParseUint(fields[2], 10, 32); err == nil { file, line = fields[1], int(l) } continue } if fields := objdumpOutputFunction.FindStringSubmatch(input); len(fields) == 2 { function = fields[1] continue } // Reset on unrecognized lines. function, file, line = "", "", 0 } return assembly, nil }
go
func disassemble(asm []byte) ([]plugin.Inst, error) { buf := bytes.NewBuffer(asm) function, file, line := "", "", 0 var assembly []plugin.Inst for { input, err := buf.ReadString('\n') if err != nil { if err != io.EOF { return nil, err } if input == "" { break } } if fields := objdumpAsmOutputRE.FindStringSubmatch(input); len(fields) == 3 { if address, err := strconv.ParseUint(fields[1], 16, 64); err == nil { assembly = append(assembly, plugin.Inst{ Addr: address, Text: fields[2], Function: function, File: file, Line: line, }) continue } } if fields := objdumpOutputFileLine.FindStringSubmatch(input); len(fields) == 3 { if l, err := strconv.ParseUint(fields[2], 10, 32); err == nil { file, line = fields[1], int(l) } continue } if fields := objdumpOutputFunction.FindStringSubmatch(input); len(fields) == 2 { function = fields[1] continue } // Reset on unrecognized lines. function, file, line = "", "", 0 } return assembly, nil }
[ "func", "disassemble", "(", "asm", "[", "]", "byte", ")", "(", "[", "]", "plugin", ".", "Inst", ",", "error", ")", "{", "buf", ":=", "bytes", ".", "NewBuffer", "(", "asm", ")", "\n", "function", ",", "file", ",", "line", ":=", "\"", "\"", ",", "\"", "\"", ",", "0", "\n", "var", "assembly", "[", "]", "plugin", ".", "Inst", "\n", "for", "{", "input", ",", "err", ":=", "buf", ".", "ReadString", "(", "'\\n'", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "!=", "io", ".", "EOF", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "input", "==", "\"", "\"", "{", "break", "\n", "}", "\n", "}", "\n\n", "if", "fields", ":=", "objdumpAsmOutputRE", ".", "FindStringSubmatch", "(", "input", ")", ";", "len", "(", "fields", ")", "==", "3", "{", "if", "address", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "fields", "[", "1", "]", ",", "16", ",", "64", ")", ";", "err", "==", "nil", "{", "assembly", "=", "append", "(", "assembly", ",", "plugin", ".", "Inst", "{", "Addr", ":", "address", ",", "Text", ":", "fields", "[", "2", "]", ",", "Function", ":", "function", ",", "File", ":", "file", ",", "Line", ":", "line", ",", "}", ")", "\n", "continue", "\n", "}", "\n", "}", "\n", "if", "fields", ":=", "objdumpOutputFileLine", ".", "FindStringSubmatch", "(", "input", ")", ";", "len", "(", "fields", ")", "==", "3", "{", "if", "l", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "fields", "[", "2", "]", ",", "10", ",", "32", ")", ";", "err", "==", "nil", "{", "file", ",", "line", "=", "fields", "[", "1", "]", ",", "int", "(", "l", ")", "\n", "}", "\n", "continue", "\n", "}", "\n", "if", "fields", ":=", "objdumpOutputFunction", ".", "FindStringSubmatch", "(", "input", ")", ";", "len", "(", "fields", ")", "==", "2", "{", "function", "=", "fields", "[", "1", "]", "\n", "continue", "\n", "}", "\n", "// Reset on unrecognized lines.", "function", ",", "file", ",", "line", "=", "\"", "\"", ",", "\"", "\"", ",", "0", "\n", "}", "\n\n", "return", "assembly", ",", "nil", "\n", "}" ]
// disassemble parses the output of the objdump command and returns // the assembly instructions in a slice.
[ "disassemble", "parses", "the", "output", "of", "the", "objdump", "command", "and", "returns", "the", "assembly", "instructions", "in", "a", "slice", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/binutils/disasm.go#L109-L152
train
google/pprof
internal/binutils/disasm.go
nextSymbol
func nextSymbol(buf *bytes.Buffer) (uint64, string, error) { for { line, err := buf.ReadString('\n') if err != nil { if err != io.EOF || line == "" { return 0, "", err } } if fields := nmOutputRE.FindStringSubmatch(line); len(fields) == 4 { if address, err := strconv.ParseUint(fields[1], 16, 64); err == nil { return address, fields[3], nil } } } }
go
func nextSymbol(buf *bytes.Buffer) (uint64, string, error) { for { line, err := buf.ReadString('\n') if err != nil { if err != io.EOF || line == "" { return 0, "", err } } if fields := nmOutputRE.FindStringSubmatch(line); len(fields) == 4 { if address, err := strconv.ParseUint(fields[1], 16, 64); err == nil { return address, fields[3], nil } } } }
[ "func", "nextSymbol", "(", "buf", "*", "bytes", ".", "Buffer", ")", "(", "uint64", ",", "string", ",", "error", ")", "{", "for", "{", "line", ",", "err", ":=", "buf", ".", "ReadString", "(", "'\\n'", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "!=", "io", ".", "EOF", "||", "line", "==", "\"", "\"", "{", "return", "0", ",", "\"", "\"", ",", "err", "\n", "}", "\n", "}", "\n\n", "if", "fields", ":=", "nmOutputRE", ".", "FindStringSubmatch", "(", "line", ")", ";", "len", "(", "fields", ")", "==", "4", "{", "if", "address", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "fields", "[", "1", "]", ",", "16", ",", "64", ")", ";", "err", "==", "nil", "{", "return", "address", ",", "fields", "[", "3", "]", ",", "nil", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// nextSymbol parses the nm output to find the next symbol listed. // Skips over any output it cannot recognize.
[ "nextSymbol", "parses", "the", "nm", "output", "to", "find", "the", "next", "symbol", "listed", ".", "Skips", "over", "any", "output", "it", "cannot", "recognize", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/binutils/disasm.go#L156-L171
train
google/pprof
profile/filter.go
FilterSamplesByName
func (p *Profile) FilterSamplesByName(focus, ignore, hide, show *regexp.Regexp) (fm, im, hm, hnm bool) { focusOrIgnore := make(map[uint64]bool) hidden := make(map[uint64]bool) for _, l := range p.Location { if ignore != nil && l.matchesName(ignore) { im = true focusOrIgnore[l.ID] = false } else if focus == nil || l.matchesName(focus) { fm = true focusOrIgnore[l.ID] = true } if hide != nil && l.matchesName(hide) { hm = true l.Line = l.unmatchedLines(hide) if len(l.Line) == 0 { hidden[l.ID] = true } } if show != nil { l.Line = l.matchedLines(show) if len(l.Line) == 0 { hidden[l.ID] = true } else { hnm = true } } } s := make([]*Sample, 0, len(p.Sample)) for _, sample := range p.Sample { if focusedAndNotIgnored(sample.Location, focusOrIgnore) { if len(hidden) > 0 { var locs []*Location for _, loc := range sample.Location { if !hidden[loc.ID] { locs = append(locs, loc) } } if len(locs) == 0 { // Remove sample with no locations (by not adding it to s). continue } sample.Location = locs } s = append(s, sample) } } p.Sample = s return }
go
func (p *Profile) FilterSamplesByName(focus, ignore, hide, show *regexp.Regexp) (fm, im, hm, hnm bool) { focusOrIgnore := make(map[uint64]bool) hidden := make(map[uint64]bool) for _, l := range p.Location { if ignore != nil && l.matchesName(ignore) { im = true focusOrIgnore[l.ID] = false } else if focus == nil || l.matchesName(focus) { fm = true focusOrIgnore[l.ID] = true } if hide != nil && l.matchesName(hide) { hm = true l.Line = l.unmatchedLines(hide) if len(l.Line) == 0 { hidden[l.ID] = true } } if show != nil { l.Line = l.matchedLines(show) if len(l.Line) == 0 { hidden[l.ID] = true } else { hnm = true } } } s := make([]*Sample, 0, len(p.Sample)) for _, sample := range p.Sample { if focusedAndNotIgnored(sample.Location, focusOrIgnore) { if len(hidden) > 0 { var locs []*Location for _, loc := range sample.Location { if !hidden[loc.ID] { locs = append(locs, loc) } } if len(locs) == 0 { // Remove sample with no locations (by not adding it to s). continue } sample.Location = locs } s = append(s, sample) } } p.Sample = s return }
[ "func", "(", "p", "*", "Profile", ")", "FilterSamplesByName", "(", "focus", ",", "ignore", ",", "hide", ",", "show", "*", "regexp", ".", "Regexp", ")", "(", "fm", ",", "im", ",", "hm", ",", "hnm", "bool", ")", "{", "focusOrIgnore", ":=", "make", "(", "map", "[", "uint64", "]", "bool", ")", "\n", "hidden", ":=", "make", "(", "map", "[", "uint64", "]", "bool", ")", "\n", "for", "_", ",", "l", ":=", "range", "p", ".", "Location", "{", "if", "ignore", "!=", "nil", "&&", "l", ".", "matchesName", "(", "ignore", ")", "{", "im", "=", "true", "\n", "focusOrIgnore", "[", "l", ".", "ID", "]", "=", "false", "\n", "}", "else", "if", "focus", "==", "nil", "||", "l", ".", "matchesName", "(", "focus", ")", "{", "fm", "=", "true", "\n", "focusOrIgnore", "[", "l", ".", "ID", "]", "=", "true", "\n", "}", "\n\n", "if", "hide", "!=", "nil", "&&", "l", ".", "matchesName", "(", "hide", ")", "{", "hm", "=", "true", "\n", "l", ".", "Line", "=", "l", ".", "unmatchedLines", "(", "hide", ")", "\n", "if", "len", "(", "l", ".", "Line", ")", "==", "0", "{", "hidden", "[", "l", ".", "ID", "]", "=", "true", "\n", "}", "\n", "}", "\n", "if", "show", "!=", "nil", "{", "l", ".", "Line", "=", "l", ".", "matchedLines", "(", "show", ")", "\n", "if", "len", "(", "l", ".", "Line", ")", "==", "0", "{", "hidden", "[", "l", ".", "ID", "]", "=", "true", "\n", "}", "else", "{", "hnm", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n\n", "s", ":=", "make", "(", "[", "]", "*", "Sample", ",", "0", ",", "len", "(", "p", ".", "Sample", ")", ")", "\n", "for", "_", ",", "sample", ":=", "range", "p", ".", "Sample", "{", "if", "focusedAndNotIgnored", "(", "sample", ".", "Location", ",", "focusOrIgnore", ")", "{", "if", "len", "(", "hidden", ")", ">", "0", "{", "var", "locs", "[", "]", "*", "Location", "\n", "for", "_", ",", "loc", ":=", "range", "sample", ".", "Location", "{", "if", "!", "hidden", "[", "loc", ".", "ID", "]", "{", "locs", "=", "append", "(", "locs", ",", "loc", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "locs", ")", "==", "0", "{", "// Remove sample with no locations (by not adding it to s).", "continue", "\n", "}", "\n", "sample", ".", "Location", "=", "locs", "\n", "}", "\n", "s", "=", "append", "(", "s", ",", "sample", ")", "\n", "}", "\n", "}", "\n", "p", ".", "Sample", "=", "s", "\n\n", "return", "\n", "}" ]
// FilterSamplesByName filters the samples in a profile and only keeps // samples where at least one frame matches focus but none match ignore. // Returns true is the corresponding regexp matched at least one sample.
[ "FilterSamplesByName", "filters", "the", "samples", "in", "a", "profile", "and", "only", "keeps", "samples", "where", "at", "least", "one", "frame", "matches", "focus", "but", "none", "match", "ignore", ".", "Returns", "true", "is", "the", "corresponding", "regexp", "matched", "at", "least", "one", "sample", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/filter.go#L24-L75
train
google/pprof
profile/filter.go
filterShowFromLocation
func filterShowFromLocation(loc *Location, showFrom *regexp.Regexp) bool { if m := loc.Mapping; m != nil && showFrom.MatchString(m.File) { return true } if i := loc.lastMatchedLineIndex(showFrom); i >= 0 { loc.Line = loc.Line[:i+1] return true } return false }
go
func filterShowFromLocation(loc *Location, showFrom *regexp.Regexp) bool { if m := loc.Mapping; m != nil && showFrom.MatchString(m.File) { return true } if i := loc.lastMatchedLineIndex(showFrom); i >= 0 { loc.Line = loc.Line[:i+1] return true } return false }
[ "func", "filterShowFromLocation", "(", "loc", "*", "Location", ",", "showFrom", "*", "regexp", ".", "Regexp", ")", "bool", "{", "if", "m", ":=", "loc", ".", "Mapping", ";", "m", "!=", "nil", "&&", "showFrom", ".", "MatchString", "(", "m", ".", "File", ")", "{", "return", "true", "\n", "}", "\n", "if", "i", ":=", "loc", ".", "lastMatchedLineIndex", "(", "showFrom", ")", ";", "i", ">=", "0", "{", "loc", ".", "Line", "=", "loc", ".", "Line", "[", ":", "i", "+", "1", "]", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// filterShowFromLocation tests a showFrom regex against a location, removes // lines after the last match and returns whether a match was found. If the // mapping is matched, then all lines are kept.
[ "filterShowFromLocation", "tests", "a", "showFrom", "regex", "against", "a", "location", "removes", "lines", "after", "the", "last", "match", "and", "returns", "whether", "a", "match", "was", "found", ".", "If", "the", "mapping", "is", "matched", "then", "all", "lines", "are", "kept", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/filter.go#L118-L127
train
google/pprof
profile/filter.go
lastMatchedLineIndex
func (loc *Location) lastMatchedLineIndex(re *regexp.Regexp) int { for i := len(loc.Line) - 1; i >= 0; i-- { if fn := loc.Line[i].Function; fn != nil { if re.MatchString(fn.Name) || re.MatchString(fn.Filename) { return i } } } return -1 }
go
func (loc *Location) lastMatchedLineIndex(re *regexp.Regexp) int { for i := len(loc.Line) - 1; i >= 0; i-- { if fn := loc.Line[i].Function; fn != nil { if re.MatchString(fn.Name) || re.MatchString(fn.Filename) { return i } } } return -1 }
[ "func", "(", "loc", "*", "Location", ")", "lastMatchedLineIndex", "(", "re", "*", "regexp", ".", "Regexp", ")", "int", "{", "for", "i", ":=", "len", "(", "loc", ".", "Line", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "if", "fn", ":=", "loc", ".", "Line", "[", "i", "]", ".", "Function", ";", "fn", "!=", "nil", "{", "if", "re", ".", "MatchString", "(", "fn", ".", "Name", ")", "||", "re", ".", "MatchString", "(", "fn", ".", "Filename", ")", "{", "return", "i", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "-", "1", "\n", "}" ]
// lastMatchedLineIndex returns the index of the last line that matches a regex, // or -1 if no match is found.
[ "lastMatchedLineIndex", "returns", "the", "index", "of", "the", "last", "line", "that", "matches", "a", "regex", "or", "-", "1", "if", "no", "match", "is", "found", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/filter.go#L131-L140
train
google/pprof
profile/filter.go
FilterTagsByName
func (p *Profile) FilterTagsByName(show, hide *regexp.Regexp) (sm, hm bool) { matchRemove := func(name string) bool { matchShow := show == nil || show.MatchString(name) matchHide := hide != nil && hide.MatchString(name) if matchShow { sm = true } if matchHide { hm = true } return !matchShow || matchHide } for _, s := range p.Sample { for lab := range s.Label { if matchRemove(lab) { delete(s.Label, lab) } } for lab := range s.NumLabel { if matchRemove(lab) { delete(s.NumLabel, lab) } } } return }
go
func (p *Profile) FilterTagsByName(show, hide *regexp.Regexp) (sm, hm bool) { matchRemove := func(name string) bool { matchShow := show == nil || show.MatchString(name) matchHide := hide != nil && hide.MatchString(name) if matchShow { sm = true } if matchHide { hm = true } return !matchShow || matchHide } for _, s := range p.Sample { for lab := range s.Label { if matchRemove(lab) { delete(s.Label, lab) } } for lab := range s.NumLabel { if matchRemove(lab) { delete(s.NumLabel, lab) } } } return }
[ "func", "(", "p", "*", "Profile", ")", "FilterTagsByName", "(", "show", ",", "hide", "*", "regexp", ".", "Regexp", ")", "(", "sm", ",", "hm", "bool", ")", "{", "matchRemove", ":=", "func", "(", "name", "string", ")", "bool", "{", "matchShow", ":=", "show", "==", "nil", "||", "show", ".", "MatchString", "(", "name", ")", "\n", "matchHide", ":=", "hide", "!=", "nil", "&&", "hide", ".", "MatchString", "(", "name", ")", "\n\n", "if", "matchShow", "{", "sm", "=", "true", "\n", "}", "\n", "if", "matchHide", "{", "hm", "=", "true", "\n", "}", "\n", "return", "!", "matchShow", "||", "matchHide", "\n", "}", "\n", "for", "_", ",", "s", ":=", "range", "p", ".", "Sample", "{", "for", "lab", ":=", "range", "s", ".", "Label", "{", "if", "matchRemove", "(", "lab", ")", "{", "delete", "(", "s", ".", "Label", ",", "lab", ")", "\n", "}", "\n", "}", "\n", "for", "lab", ":=", "range", "s", ".", "NumLabel", "{", "if", "matchRemove", "(", "lab", ")", "{", "delete", "(", "s", ".", "NumLabel", ",", "lab", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// FilterTagsByName filters the tags in a profile and only keeps // tags that match show and not hide.
[ "FilterTagsByName", "filters", "the", "tags", "in", "a", "profile", "and", "only", "keeps", "tags", "that", "match", "show", "and", "not", "hide", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/filter.go#L144-L170
train
google/pprof
profile/filter.go
FilterSamplesByTag
func (p *Profile) FilterSamplesByTag(focus, ignore TagMatch) (fm, im bool) { samples := make([]*Sample, 0, len(p.Sample)) for _, s := range p.Sample { focused, ignored := true, false if focus != nil { focused = focus(s) } if ignore != nil { ignored = ignore(s) } fm = fm || focused im = im || ignored if focused && !ignored { samples = append(samples, s) } } p.Sample = samples return }
go
func (p *Profile) FilterSamplesByTag(focus, ignore TagMatch) (fm, im bool) { samples := make([]*Sample, 0, len(p.Sample)) for _, s := range p.Sample { focused, ignored := true, false if focus != nil { focused = focus(s) } if ignore != nil { ignored = ignore(s) } fm = fm || focused im = im || ignored if focused && !ignored { samples = append(samples, s) } } p.Sample = samples return }
[ "func", "(", "p", "*", "Profile", ")", "FilterSamplesByTag", "(", "focus", ",", "ignore", "TagMatch", ")", "(", "fm", ",", "im", "bool", ")", "{", "samples", ":=", "make", "(", "[", "]", "*", "Sample", ",", "0", ",", "len", "(", "p", ".", "Sample", ")", ")", "\n", "for", "_", ",", "s", ":=", "range", "p", ".", "Sample", "{", "focused", ",", "ignored", ":=", "true", ",", "false", "\n", "if", "focus", "!=", "nil", "{", "focused", "=", "focus", "(", "s", ")", "\n", "}", "\n", "if", "ignore", "!=", "nil", "{", "ignored", "=", "ignore", "(", "s", ")", "\n", "}", "\n", "fm", "=", "fm", "||", "focused", "\n", "im", "=", "im", "||", "ignored", "\n", "if", "focused", "&&", "!", "ignored", "{", "samples", "=", "append", "(", "samples", ",", "s", ")", "\n", "}", "\n", "}", "\n", "p", ".", "Sample", "=", "samples", "\n", "return", "\n", "}" ]
// FilterSamplesByTag removes all samples from the profile, except // those that match focus and do not match the ignore regular // expression.
[ "FilterSamplesByTag", "removes", "all", "samples", "from", "the", "profile", "except", "those", "that", "match", "focus", "and", "do", "not", "match", "the", "ignore", "regular", "expression", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/filter.go#L252-L270
train
google/pprof
profile/profile.go
ParseData
func ParseData(data []byte) (*Profile, error) { var p *Profile var err error if len(data) >= 2 && data[0] == 0x1f && data[1] == 0x8b { gz, err := gzip.NewReader(bytes.NewBuffer(data)) if err == nil { data, err = ioutil.ReadAll(gz) } if err != nil { return nil, fmt.Errorf("decompressing profile: %v", err) } } if p, err = ParseUncompressed(data); err != nil && err != errNoData && err != errConcatProfile { p, err = parseLegacy(data) } if err != nil { return nil, fmt.Errorf("parsing profile: %v", err) } if err := p.CheckValid(); err != nil { return nil, fmt.Errorf("malformed profile: %v", err) } return p, nil }
go
func ParseData(data []byte) (*Profile, error) { var p *Profile var err error if len(data) >= 2 && data[0] == 0x1f && data[1] == 0x8b { gz, err := gzip.NewReader(bytes.NewBuffer(data)) if err == nil { data, err = ioutil.ReadAll(gz) } if err != nil { return nil, fmt.Errorf("decompressing profile: %v", err) } } if p, err = ParseUncompressed(data); err != nil && err != errNoData && err != errConcatProfile { p, err = parseLegacy(data) } if err != nil { return nil, fmt.Errorf("parsing profile: %v", err) } if err := p.CheckValid(); err != nil { return nil, fmt.Errorf("malformed profile: %v", err) } return p, nil }
[ "func", "ParseData", "(", "data", "[", "]", "byte", ")", "(", "*", "Profile", ",", "error", ")", "{", "var", "p", "*", "Profile", "\n", "var", "err", "error", "\n", "if", "len", "(", "data", ")", ">=", "2", "&&", "data", "[", "0", "]", "==", "0x1f", "&&", "data", "[", "1", "]", "==", "0x8b", "{", "gz", ",", "err", ":=", "gzip", ".", "NewReader", "(", "bytes", ".", "NewBuffer", "(", "data", ")", ")", "\n", "if", "err", "==", "nil", "{", "data", ",", "err", "=", "ioutil", ".", "ReadAll", "(", "gz", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "p", ",", "err", "=", "ParseUncompressed", "(", "data", ")", ";", "err", "!=", "nil", "&&", "err", "!=", "errNoData", "&&", "err", "!=", "errConcatProfile", "{", "p", ",", "err", "=", "parseLegacy", "(", "data", ")", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "p", ".", "CheckValid", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "p", ",", "nil", "\n", "}" ]
// ParseData parses a profile from a buffer and checks for its // validity.
[ "ParseData", "parses", "a", "profile", "from", "a", "buffer", "and", "checks", "for", "its", "validity", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L155-L179
train
google/pprof
profile/profile.go
ParseUncompressed
func ParseUncompressed(data []byte) (*Profile, error) { if len(data) == 0 { return nil, errNoData } p := &Profile{} if err := unmarshal(data, p); err != nil { return nil, err } if err := p.postDecode(); err != nil { return nil, err } return p, nil }
go
func ParseUncompressed(data []byte) (*Profile, error) { if len(data) == 0 { return nil, errNoData } p := &Profile{} if err := unmarshal(data, p); err != nil { return nil, err } if err := p.postDecode(); err != nil { return nil, err } return p, nil }
[ "func", "ParseUncompressed", "(", "data", "[", "]", "byte", ")", "(", "*", "Profile", ",", "error", ")", "{", "if", "len", "(", "data", ")", "==", "0", "{", "return", "nil", ",", "errNoData", "\n", "}", "\n", "p", ":=", "&", "Profile", "{", "}", "\n", "if", "err", ":=", "unmarshal", "(", "data", ",", "p", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "p", ".", "postDecode", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "p", ",", "nil", "\n", "}" ]
// ParseUncompressed parses an uncompressed protobuf into a profile.
[ "ParseUncompressed", "parses", "an", "uncompressed", "protobuf", "into", "a", "profile", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L210-L224
train
google/pprof
profile/profile.go
massageMappings
func (p *Profile) massageMappings() { // Merge adjacent regions with matching names, checking that the offsets match if len(p.Mapping) > 1 { mappings := []*Mapping{p.Mapping[0]} for _, m := range p.Mapping[1:] { lm := mappings[len(mappings)-1] if adjacent(lm, m) { lm.Limit = m.Limit if m.File != "" { lm.File = m.File } if m.BuildID != "" { lm.BuildID = m.BuildID } p.updateLocationMapping(m, lm) continue } mappings = append(mappings, m) } p.Mapping = mappings } // Use heuristics to identify main binary and move it to the top of the list of mappings for i, m := range p.Mapping { file := strings.TrimSpace(strings.Replace(m.File, "(deleted)", "", -1)) if len(file) == 0 { continue } if len(libRx.FindStringSubmatch(file)) > 0 { continue } if file[0] == '[' { continue } // Swap what we guess is main to position 0. p.Mapping[0], p.Mapping[i] = p.Mapping[i], p.Mapping[0] break } // Keep the mapping IDs neatly sorted for i, m := range p.Mapping { m.ID = uint64(i + 1) } }
go
func (p *Profile) massageMappings() { // Merge adjacent regions with matching names, checking that the offsets match if len(p.Mapping) > 1 { mappings := []*Mapping{p.Mapping[0]} for _, m := range p.Mapping[1:] { lm := mappings[len(mappings)-1] if adjacent(lm, m) { lm.Limit = m.Limit if m.File != "" { lm.File = m.File } if m.BuildID != "" { lm.BuildID = m.BuildID } p.updateLocationMapping(m, lm) continue } mappings = append(mappings, m) } p.Mapping = mappings } // Use heuristics to identify main binary and move it to the top of the list of mappings for i, m := range p.Mapping { file := strings.TrimSpace(strings.Replace(m.File, "(deleted)", "", -1)) if len(file) == 0 { continue } if len(libRx.FindStringSubmatch(file)) > 0 { continue } if file[0] == '[' { continue } // Swap what we guess is main to position 0. p.Mapping[0], p.Mapping[i] = p.Mapping[i], p.Mapping[0] break } // Keep the mapping IDs neatly sorted for i, m := range p.Mapping { m.ID = uint64(i + 1) } }
[ "func", "(", "p", "*", "Profile", ")", "massageMappings", "(", ")", "{", "// Merge adjacent regions with matching names, checking that the offsets match", "if", "len", "(", "p", ".", "Mapping", ")", ">", "1", "{", "mappings", ":=", "[", "]", "*", "Mapping", "{", "p", ".", "Mapping", "[", "0", "]", "}", "\n", "for", "_", ",", "m", ":=", "range", "p", ".", "Mapping", "[", "1", ":", "]", "{", "lm", ":=", "mappings", "[", "len", "(", "mappings", ")", "-", "1", "]", "\n", "if", "adjacent", "(", "lm", ",", "m", ")", "{", "lm", ".", "Limit", "=", "m", ".", "Limit", "\n", "if", "m", ".", "File", "!=", "\"", "\"", "{", "lm", ".", "File", "=", "m", ".", "File", "\n", "}", "\n", "if", "m", ".", "BuildID", "!=", "\"", "\"", "{", "lm", ".", "BuildID", "=", "m", ".", "BuildID", "\n", "}", "\n", "p", ".", "updateLocationMapping", "(", "m", ",", "lm", ")", "\n", "continue", "\n", "}", "\n", "mappings", "=", "append", "(", "mappings", ",", "m", ")", "\n", "}", "\n", "p", ".", "Mapping", "=", "mappings", "\n", "}", "\n\n", "// Use heuristics to identify main binary and move it to the top of the list of mappings", "for", "i", ",", "m", ":=", "range", "p", ".", "Mapping", "{", "file", ":=", "strings", ".", "TrimSpace", "(", "strings", ".", "Replace", "(", "m", ".", "File", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", ")", "\n", "if", "len", "(", "file", ")", "==", "0", "{", "continue", "\n", "}", "\n", "if", "len", "(", "libRx", ".", "FindStringSubmatch", "(", "file", ")", ")", ">", "0", "{", "continue", "\n", "}", "\n", "if", "file", "[", "0", "]", "==", "'['", "{", "continue", "\n", "}", "\n", "// Swap what we guess is main to position 0.", "p", ".", "Mapping", "[", "0", "]", ",", "p", ".", "Mapping", "[", "i", "]", "=", "p", ".", "Mapping", "[", "i", "]", ",", "p", ".", "Mapping", "[", "0", "]", "\n", "break", "\n", "}", "\n\n", "// Keep the mapping IDs neatly sorted", "for", "i", ",", "m", ":=", "range", "p", ".", "Mapping", "{", "m", ".", "ID", "=", "uint64", "(", "i", "+", "1", ")", "\n", "}", "\n", "}" ]
// massageMappings applies heuristic-based changes to the profile // mappings to account for quirks of some environments.
[ "massageMappings", "applies", "heuristic", "-", "based", "changes", "to", "the", "profile", "mappings", "to", "account", "for", "quirks", "of", "some", "environments", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L230-L273
train
google/pprof
profile/profile.go
adjacent
func adjacent(m1, m2 *Mapping) bool { if m1.File != "" && m2.File != "" { if m1.File != m2.File { return false } } if m1.BuildID != "" && m2.BuildID != "" { if m1.BuildID != m2.BuildID { return false } } if m1.Limit != m2.Start { return false } if m1.Offset != 0 && m2.Offset != 0 { offset := m1.Offset + (m1.Limit - m1.Start) if offset != m2.Offset { return false } } return true }
go
func adjacent(m1, m2 *Mapping) bool { if m1.File != "" && m2.File != "" { if m1.File != m2.File { return false } } if m1.BuildID != "" && m2.BuildID != "" { if m1.BuildID != m2.BuildID { return false } } if m1.Limit != m2.Start { return false } if m1.Offset != 0 && m2.Offset != 0 { offset := m1.Offset + (m1.Limit - m1.Start) if offset != m2.Offset { return false } } return true }
[ "func", "adjacent", "(", "m1", ",", "m2", "*", "Mapping", ")", "bool", "{", "if", "m1", ".", "File", "!=", "\"", "\"", "&&", "m2", ".", "File", "!=", "\"", "\"", "{", "if", "m1", ".", "File", "!=", "m2", ".", "File", "{", "return", "false", "\n", "}", "\n", "}", "\n", "if", "m1", ".", "BuildID", "!=", "\"", "\"", "&&", "m2", ".", "BuildID", "!=", "\"", "\"", "{", "if", "m1", ".", "BuildID", "!=", "m2", ".", "BuildID", "{", "return", "false", "\n", "}", "\n", "}", "\n", "if", "m1", ".", "Limit", "!=", "m2", ".", "Start", "{", "return", "false", "\n", "}", "\n", "if", "m1", ".", "Offset", "!=", "0", "&&", "m2", ".", "Offset", "!=", "0", "{", "offset", ":=", "m1", ".", "Offset", "+", "(", "m1", ".", "Limit", "-", "m1", ".", "Start", ")", "\n", "if", "offset", "!=", "m2", ".", "Offset", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// adjacent returns whether two mapping entries represent the same // mapping that has been split into two. Check that their addresses are adjacent, // and if the offsets match, if they are available.
[ "adjacent", "returns", "whether", "two", "mapping", "entries", "represent", "the", "same", "mapping", "that", "has", "been", "split", "into", "two", ".", "Check", "that", "their", "addresses", "are", "adjacent", "and", "if", "the", "offsets", "match", "if", "they", "are", "available", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L278-L299
train
google/pprof
profile/profile.go
WriteUncompressed
func (p *Profile) WriteUncompressed(w io.Writer) error { _, err := w.Write(serialize(p)) return err }
go
func (p *Profile) WriteUncompressed(w io.Writer) error { _, err := w.Write(serialize(p)) return err }
[ "func", "(", "p", "*", "Profile", ")", "WriteUncompressed", "(", "w", "io", ".", "Writer", ")", "error", "{", "_", ",", "err", ":=", "w", ".", "Write", "(", "serialize", "(", "p", ")", ")", "\n", "return", "err", "\n", "}" ]
// WriteUncompressed writes the profile as a marshaled protobuf.
[ "WriteUncompressed", "writes", "the", "profile", "as", "a", "marshaled", "protobuf", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L326-L329
train
google/pprof
profile/profile.go
Aggregate
func (p *Profile) Aggregate(inlineFrame, function, filename, linenumber, address bool) error { for _, m := range p.Mapping { m.HasInlineFrames = m.HasInlineFrames && inlineFrame m.HasFunctions = m.HasFunctions && function m.HasFilenames = m.HasFilenames && filename m.HasLineNumbers = m.HasLineNumbers && linenumber } // Aggregate functions if !function || !filename { for _, f := range p.Function { if !function { f.Name = "" f.SystemName = "" } if !filename { f.Filename = "" } } } // Aggregate locations if !inlineFrame || !address || !linenumber { for _, l := range p.Location { if !inlineFrame && len(l.Line) > 1 { l.Line = l.Line[len(l.Line)-1:] } if !linenumber { for i := range l.Line { l.Line[i].Line = 0 } } if !address { l.Address = 0 } } } return p.CheckValid() }
go
func (p *Profile) Aggregate(inlineFrame, function, filename, linenumber, address bool) error { for _, m := range p.Mapping { m.HasInlineFrames = m.HasInlineFrames && inlineFrame m.HasFunctions = m.HasFunctions && function m.HasFilenames = m.HasFilenames && filename m.HasLineNumbers = m.HasLineNumbers && linenumber } // Aggregate functions if !function || !filename { for _, f := range p.Function { if !function { f.Name = "" f.SystemName = "" } if !filename { f.Filename = "" } } } // Aggregate locations if !inlineFrame || !address || !linenumber { for _, l := range p.Location { if !inlineFrame && len(l.Line) > 1 { l.Line = l.Line[len(l.Line)-1:] } if !linenumber { for i := range l.Line { l.Line[i].Line = 0 } } if !address { l.Address = 0 } } } return p.CheckValid() }
[ "func", "(", "p", "*", "Profile", ")", "Aggregate", "(", "inlineFrame", ",", "function", ",", "filename", ",", "linenumber", ",", "address", "bool", ")", "error", "{", "for", "_", ",", "m", ":=", "range", "p", ".", "Mapping", "{", "m", ".", "HasInlineFrames", "=", "m", ".", "HasInlineFrames", "&&", "inlineFrame", "\n", "m", ".", "HasFunctions", "=", "m", ".", "HasFunctions", "&&", "function", "\n", "m", ".", "HasFilenames", "=", "m", ".", "HasFilenames", "&&", "filename", "\n", "m", ".", "HasLineNumbers", "=", "m", ".", "HasLineNumbers", "&&", "linenumber", "\n", "}", "\n\n", "// Aggregate functions", "if", "!", "function", "||", "!", "filename", "{", "for", "_", ",", "f", ":=", "range", "p", ".", "Function", "{", "if", "!", "function", "{", "f", ".", "Name", "=", "\"", "\"", "\n", "f", ".", "SystemName", "=", "\"", "\"", "\n", "}", "\n", "if", "!", "filename", "{", "f", ".", "Filename", "=", "\"", "\"", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Aggregate locations", "if", "!", "inlineFrame", "||", "!", "address", "||", "!", "linenumber", "{", "for", "_", ",", "l", ":=", "range", "p", ".", "Location", "{", "if", "!", "inlineFrame", "&&", "len", "(", "l", ".", "Line", ")", ">", "1", "{", "l", ".", "Line", "=", "l", ".", "Line", "[", "len", "(", "l", ".", "Line", ")", "-", "1", ":", "]", "\n", "}", "\n", "if", "!", "linenumber", "{", "for", "i", ":=", "range", "l", ".", "Line", "{", "l", ".", "Line", "[", "i", "]", ".", "Line", "=", "0", "\n", "}", "\n", "}", "\n", "if", "!", "address", "{", "l", ".", "Address", "=", "0", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "p", ".", "CheckValid", "(", ")", "\n", "}" ]
// Aggregate merges the locations in the profile into equivalence // classes preserving the request attributes. It also updates the // samples to point to the merged locations.
[ "Aggregate", "merges", "the", "locations", "in", "the", "profile", "into", "equivalence", "classes", "preserving", "the", "request", "attributes", ".", "It", "also", "updates", "the", "samples", "to", "point", "to", "the", "merged", "locations", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L414-L453
train
google/pprof
profile/profile.go
NumLabelUnits
func (p *Profile) NumLabelUnits() (map[string]string, map[string][]string) { numLabelUnits := map[string]string{} ignoredUnits := map[string]map[string]bool{} encounteredKeys := map[string]bool{} // Determine units based on numeric tags for each sample. for _, s := range p.Sample { for k := range s.NumLabel { encounteredKeys[k] = true for _, unit := range s.NumUnit[k] { if unit == "" { continue } if wantUnit, ok := numLabelUnits[k]; !ok { numLabelUnits[k] = unit } else if wantUnit != unit { if v, ok := ignoredUnits[k]; ok { v[unit] = true } else { ignoredUnits[k] = map[string]bool{unit: true} } } } } } // Infer units for keys without any units associated with // numeric tag values. for key := range encounteredKeys { unit := numLabelUnits[key] if unit == "" { switch key { case "alignment", "request": numLabelUnits[key] = "bytes" default: numLabelUnits[key] = key } } } // Copy ignored units into more readable format unitsIgnored := make(map[string][]string, len(ignoredUnits)) for key, values := range ignoredUnits { units := make([]string, len(values)) i := 0 for unit := range values { units[i] = unit i++ } sort.Strings(units) unitsIgnored[key] = units } return numLabelUnits, unitsIgnored }
go
func (p *Profile) NumLabelUnits() (map[string]string, map[string][]string) { numLabelUnits := map[string]string{} ignoredUnits := map[string]map[string]bool{} encounteredKeys := map[string]bool{} // Determine units based on numeric tags for each sample. for _, s := range p.Sample { for k := range s.NumLabel { encounteredKeys[k] = true for _, unit := range s.NumUnit[k] { if unit == "" { continue } if wantUnit, ok := numLabelUnits[k]; !ok { numLabelUnits[k] = unit } else if wantUnit != unit { if v, ok := ignoredUnits[k]; ok { v[unit] = true } else { ignoredUnits[k] = map[string]bool{unit: true} } } } } } // Infer units for keys without any units associated with // numeric tag values. for key := range encounteredKeys { unit := numLabelUnits[key] if unit == "" { switch key { case "alignment", "request": numLabelUnits[key] = "bytes" default: numLabelUnits[key] = key } } } // Copy ignored units into more readable format unitsIgnored := make(map[string][]string, len(ignoredUnits)) for key, values := range ignoredUnits { units := make([]string, len(values)) i := 0 for unit := range values { units[i] = unit i++ } sort.Strings(units) unitsIgnored[key] = units } return numLabelUnits, unitsIgnored }
[ "func", "(", "p", "*", "Profile", ")", "NumLabelUnits", "(", ")", "(", "map", "[", "string", "]", "string", ",", "map", "[", "string", "]", "[", "]", "string", ")", "{", "numLabelUnits", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "ignoredUnits", ":=", "map", "[", "string", "]", "map", "[", "string", "]", "bool", "{", "}", "\n", "encounteredKeys", ":=", "map", "[", "string", "]", "bool", "{", "}", "\n\n", "// Determine units based on numeric tags for each sample.", "for", "_", ",", "s", ":=", "range", "p", ".", "Sample", "{", "for", "k", ":=", "range", "s", ".", "NumLabel", "{", "encounteredKeys", "[", "k", "]", "=", "true", "\n", "for", "_", ",", "unit", ":=", "range", "s", ".", "NumUnit", "[", "k", "]", "{", "if", "unit", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "if", "wantUnit", ",", "ok", ":=", "numLabelUnits", "[", "k", "]", ";", "!", "ok", "{", "numLabelUnits", "[", "k", "]", "=", "unit", "\n", "}", "else", "if", "wantUnit", "!=", "unit", "{", "if", "v", ",", "ok", ":=", "ignoredUnits", "[", "k", "]", ";", "ok", "{", "v", "[", "unit", "]", "=", "true", "\n", "}", "else", "{", "ignoredUnits", "[", "k", "]", "=", "map", "[", "string", "]", "bool", "{", "unit", ":", "true", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "// Infer units for keys without any units associated with", "// numeric tag values.", "for", "key", ":=", "range", "encounteredKeys", "{", "unit", ":=", "numLabelUnits", "[", "key", "]", "\n", "if", "unit", "==", "\"", "\"", "{", "switch", "key", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "numLabelUnits", "[", "key", "]", "=", "\"", "\"", "\n", "default", ":", "numLabelUnits", "[", "key", "]", "=", "key", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Copy ignored units into more readable format", "unitsIgnored", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ",", "len", "(", "ignoredUnits", ")", ")", "\n", "for", "key", ",", "values", ":=", "range", "ignoredUnits", "{", "units", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "values", ")", ")", "\n", "i", ":=", "0", "\n", "for", "unit", ":=", "range", "values", "{", "units", "[", "i", "]", "=", "unit", "\n", "i", "++", "\n", "}", "\n", "sort", ".", "Strings", "(", "units", ")", "\n", "unitsIgnored", "[", "key", "]", "=", "units", "\n", "}", "\n\n", "return", "numLabelUnits", ",", "unitsIgnored", "\n", "}" ]
// NumLabelUnits returns a map of numeric label keys to the units // associated with those keys and a map of those keys to any units // that were encountered but not used. // Unit for a given key is the first encountered unit for that key. If multiple // units are encountered for values paired with a particular key, then the first // unit encountered is used and all other units are returned in sorted order // in map of ignored units. // If no units are encountered for a particular key, the unit is then inferred // based on the key.
[ "NumLabelUnits", "returns", "a", "map", "of", "numeric", "label", "keys", "to", "the", "units", "associated", "with", "those", "keys", "and", "a", "map", "of", "those", "keys", "to", "any", "units", "that", "were", "encountered", "but", "not", "used", ".", "Unit", "for", "a", "given", "key", "is", "the", "first", "encountered", "unit", "for", "that", "key", ".", "If", "multiple", "units", "are", "encountered", "for", "values", "paired", "with", "a", "particular", "key", "then", "the", "first", "unit", "encountered", "is", "used", "and", "all", "other", "units", "are", "returned", "in", "sorted", "order", "in", "map", "of", "ignored", "units", ".", "If", "no", "units", "are", "encountered", "for", "a", "particular", "key", "the", "unit", "is", "then", "inferred", "based", "on", "the", "key", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L464-L517
train
google/pprof
profile/profile.go
String
func (p *Profile) String() string { ss := make([]string, 0, len(p.Comments)+len(p.Sample)+len(p.Mapping)+len(p.Location)) for _, c := range p.Comments { ss = append(ss, "Comment: "+c) } if pt := p.PeriodType; pt != nil { ss = append(ss, fmt.Sprintf("PeriodType: %s %s", pt.Type, pt.Unit)) } ss = append(ss, fmt.Sprintf("Period: %d", p.Period)) if p.TimeNanos != 0 { ss = append(ss, fmt.Sprintf("Time: %v", time.Unix(0, p.TimeNanos))) } if p.DurationNanos != 0 { ss = append(ss, fmt.Sprintf("Duration: %.4v", time.Duration(p.DurationNanos))) } ss = append(ss, "Samples:") var sh1 string for _, s := range p.SampleType { dflt := "" if s.Type == p.DefaultSampleType { dflt = "[dflt]" } sh1 = sh1 + fmt.Sprintf("%s/%s%s ", s.Type, s.Unit, dflt) } ss = append(ss, strings.TrimSpace(sh1)) for _, s := range p.Sample { ss = append(ss, s.string()) } ss = append(ss, "Locations") for _, l := range p.Location { ss = append(ss, l.string()) } ss = append(ss, "Mappings") for _, m := range p.Mapping { ss = append(ss, m.string()) } return strings.Join(ss, "\n") + "\n" }
go
func (p *Profile) String() string { ss := make([]string, 0, len(p.Comments)+len(p.Sample)+len(p.Mapping)+len(p.Location)) for _, c := range p.Comments { ss = append(ss, "Comment: "+c) } if pt := p.PeriodType; pt != nil { ss = append(ss, fmt.Sprintf("PeriodType: %s %s", pt.Type, pt.Unit)) } ss = append(ss, fmt.Sprintf("Period: %d", p.Period)) if p.TimeNanos != 0 { ss = append(ss, fmt.Sprintf("Time: %v", time.Unix(0, p.TimeNanos))) } if p.DurationNanos != 0 { ss = append(ss, fmt.Sprintf("Duration: %.4v", time.Duration(p.DurationNanos))) } ss = append(ss, "Samples:") var sh1 string for _, s := range p.SampleType { dflt := "" if s.Type == p.DefaultSampleType { dflt = "[dflt]" } sh1 = sh1 + fmt.Sprintf("%s/%s%s ", s.Type, s.Unit, dflt) } ss = append(ss, strings.TrimSpace(sh1)) for _, s := range p.Sample { ss = append(ss, s.string()) } ss = append(ss, "Locations") for _, l := range p.Location { ss = append(ss, l.string()) } ss = append(ss, "Mappings") for _, m := range p.Mapping { ss = append(ss, m.string()) } return strings.Join(ss, "\n") + "\n" }
[ "func", "(", "p", "*", "Profile", ")", "String", "(", ")", "string", "{", "ss", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "p", ".", "Comments", ")", "+", "len", "(", "p", ".", "Sample", ")", "+", "len", "(", "p", ".", "Mapping", ")", "+", "len", "(", "p", ".", "Location", ")", ")", "\n", "for", "_", ",", "c", ":=", "range", "p", ".", "Comments", "{", "ss", "=", "append", "(", "ss", ",", "\"", "\"", "+", "c", ")", "\n", "}", "\n", "if", "pt", ":=", "p", ".", "PeriodType", ";", "pt", "!=", "nil", "{", "ss", "=", "append", "(", "ss", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "pt", ".", "Type", ",", "pt", ".", "Unit", ")", ")", "\n", "}", "\n", "ss", "=", "append", "(", "ss", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "p", ".", "Period", ")", ")", "\n", "if", "p", ".", "TimeNanos", "!=", "0", "{", "ss", "=", "append", "(", "ss", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "time", ".", "Unix", "(", "0", ",", "p", ".", "TimeNanos", ")", ")", ")", "\n", "}", "\n", "if", "p", ".", "DurationNanos", "!=", "0", "{", "ss", "=", "append", "(", "ss", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "time", ".", "Duration", "(", "p", ".", "DurationNanos", ")", ")", ")", "\n", "}", "\n\n", "ss", "=", "append", "(", "ss", ",", "\"", "\"", ")", "\n", "var", "sh1", "string", "\n", "for", "_", ",", "s", ":=", "range", "p", ".", "SampleType", "{", "dflt", ":=", "\"", "\"", "\n", "if", "s", ".", "Type", "==", "p", ".", "DefaultSampleType", "{", "dflt", "=", "\"", "\"", "\n", "}", "\n", "sh1", "=", "sh1", "+", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "Type", ",", "s", ".", "Unit", ",", "dflt", ")", "\n", "}", "\n", "ss", "=", "append", "(", "ss", ",", "strings", ".", "TrimSpace", "(", "sh1", ")", ")", "\n", "for", "_", ",", "s", ":=", "range", "p", ".", "Sample", "{", "ss", "=", "append", "(", "ss", ",", "s", ".", "string", "(", ")", ")", "\n", "}", "\n\n", "ss", "=", "append", "(", "ss", ",", "\"", "\"", ")", "\n", "for", "_", ",", "l", ":=", "range", "p", ".", "Location", "{", "ss", "=", "append", "(", "ss", ",", "l", ".", "string", "(", ")", ")", "\n", "}", "\n\n", "ss", "=", "append", "(", "ss", ",", "\"", "\"", ")", "\n", "for", "_", ",", "m", ":=", "range", "p", ".", "Mapping", "{", "ss", "=", "append", "(", "ss", ",", "m", ".", "string", "(", ")", ")", "\n", "}", "\n\n", "return", "strings", ".", "Join", "(", "ss", ",", "\"", "\\n", "\"", ")", "+", "\"", "\\n", "\"", "\n", "}" ]
// String dumps a text representation of a profile. Intended mainly // for debugging purposes.
[ "String", "dumps", "a", "text", "representation", "of", "a", "profile", ".", "Intended", "mainly", "for", "debugging", "purposes", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L521-L562
train
google/pprof
profile/profile.go
string
func (m *Mapping) string() string { bits := "" if m.HasFunctions { bits = bits + "[FN]" } if m.HasFilenames { bits = bits + "[FL]" } if m.HasLineNumbers { bits = bits + "[LN]" } if m.HasInlineFrames { bits = bits + "[IN]" } return fmt.Sprintf("%d: %#x/%#x/%#x %s %s %s", m.ID, m.Start, m.Limit, m.Offset, m.File, m.BuildID, bits) }
go
func (m *Mapping) string() string { bits := "" if m.HasFunctions { bits = bits + "[FN]" } if m.HasFilenames { bits = bits + "[FL]" } if m.HasLineNumbers { bits = bits + "[LN]" } if m.HasInlineFrames { bits = bits + "[IN]" } return fmt.Sprintf("%d: %#x/%#x/%#x %s %s %s", m.ID, m.Start, m.Limit, m.Offset, m.File, m.BuildID, bits) }
[ "func", "(", "m", "*", "Mapping", ")", "string", "(", ")", "string", "{", "bits", ":=", "\"", "\"", "\n", "if", "m", ".", "HasFunctions", "{", "bits", "=", "bits", "+", "\"", "\"", "\n", "}", "\n", "if", "m", ".", "HasFilenames", "{", "bits", "=", "bits", "+", "\"", "\"", "\n", "}", "\n", "if", "m", ".", "HasLineNumbers", "{", "bits", "=", "bits", "+", "\"", "\"", "\n", "}", "\n", "if", "m", ".", "HasInlineFrames", "{", "bits", "=", "bits", "+", "\"", "\"", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "m", ".", "ID", ",", "m", ".", "Start", ",", "m", ".", "Limit", ",", "m", ".", "Offset", ",", "m", ".", "File", ",", "m", ".", "BuildID", ",", "bits", ")", "\n", "}" ]
// string dumps a text representation of a mapping. Intended mainly // for debugging purposes.
[ "string", "dumps", "a", "text", "representation", "of", "a", "mapping", ".", "Intended", "mainly", "for", "debugging", "purposes", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L566-L586
train
google/pprof
profile/profile.go
string
func (l *Location) string() string { ss := []string{} locStr := fmt.Sprintf("%6d: %#x ", l.ID, l.Address) if m := l.Mapping; m != nil { locStr = locStr + fmt.Sprintf("M=%d ", m.ID) } if l.IsFolded { locStr = locStr + "[F] " } if len(l.Line) == 0 { ss = append(ss, locStr) } for li := range l.Line { lnStr := "??" if fn := l.Line[li].Function; fn != nil { lnStr = fmt.Sprintf("%s %s:%d s=%d", fn.Name, fn.Filename, l.Line[li].Line, fn.StartLine) if fn.Name != fn.SystemName { lnStr = lnStr + "(" + fn.SystemName + ")" } } ss = append(ss, locStr+lnStr) // Do not print location details past the first line locStr = " " } return strings.Join(ss, "\n") }
go
func (l *Location) string() string { ss := []string{} locStr := fmt.Sprintf("%6d: %#x ", l.ID, l.Address) if m := l.Mapping; m != nil { locStr = locStr + fmt.Sprintf("M=%d ", m.ID) } if l.IsFolded { locStr = locStr + "[F] " } if len(l.Line) == 0 { ss = append(ss, locStr) } for li := range l.Line { lnStr := "??" if fn := l.Line[li].Function; fn != nil { lnStr = fmt.Sprintf("%s %s:%d s=%d", fn.Name, fn.Filename, l.Line[li].Line, fn.StartLine) if fn.Name != fn.SystemName { lnStr = lnStr + "(" + fn.SystemName + ")" } } ss = append(ss, locStr+lnStr) // Do not print location details past the first line locStr = " " } return strings.Join(ss, "\n") }
[ "func", "(", "l", "*", "Location", ")", "string", "(", ")", "string", "{", "ss", ":=", "[", "]", "string", "{", "}", "\n", "locStr", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "l", ".", "ID", ",", "l", ".", "Address", ")", "\n", "if", "m", ":=", "l", ".", "Mapping", ";", "m", "!=", "nil", "{", "locStr", "=", "locStr", "+", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "m", ".", "ID", ")", "\n", "}", "\n", "if", "l", ".", "IsFolded", "{", "locStr", "=", "locStr", "+", "\"", "\"", "\n", "}", "\n", "if", "len", "(", "l", ".", "Line", ")", "==", "0", "{", "ss", "=", "append", "(", "ss", ",", "locStr", ")", "\n", "}", "\n", "for", "li", ":=", "range", "l", ".", "Line", "{", "lnStr", ":=", "\"", "\"", "\n", "if", "fn", ":=", "l", ".", "Line", "[", "li", "]", ".", "Function", ";", "fn", "!=", "nil", "{", "lnStr", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "fn", ".", "Name", ",", "fn", ".", "Filename", ",", "l", ".", "Line", "[", "li", "]", ".", "Line", ",", "fn", ".", "StartLine", ")", "\n", "if", "fn", ".", "Name", "!=", "fn", ".", "SystemName", "{", "lnStr", "=", "lnStr", "+", "\"", "\"", "+", "fn", ".", "SystemName", "+", "\"", "\"", "\n", "}", "\n", "}", "\n", "ss", "=", "append", "(", "ss", ",", "locStr", "+", "lnStr", ")", "\n", "// Do not print location details past the first line", "locStr", "=", "\"", "\"", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "ss", ",", "\"", "\\n", "\"", ")", "\n", "}" ]
// string dumps a text representation of a location. Intended mainly // for debugging purposes.
[ "string", "dumps", "a", "text", "representation", "of", "a", "location", ".", "Intended", "mainly", "for", "debugging", "purposes", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L590-L619
train
google/pprof
profile/profile.go
string
func (s *Sample) string() string { ss := []string{} var sv string for _, v := range s.Value { sv = fmt.Sprintf("%s %10d", sv, v) } sv = sv + ": " for _, l := range s.Location { sv = sv + fmt.Sprintf("%d ", l.ID) } ss = append(ss, sv) const labelHeader = " " if len(s.Label) > 0 { ss = append(ss, labelHeader+labelsToString(s.Label)) } if len(s.NumLabel) > 0 { ss = append(ss, labelHeader+numLabelsToString(s.NumLabel, s.NumUnit)) } return strings.Join(ss, "\n") }
go
func (s *Sample) string() string { ss := []string{} var sv string for _, v := range s.Value { sv = fmt.Sprintf("%s %10d", sv, v) } sv = sv + ": " for _, l := range s.Location { sv = sv + fmt.Sprintf("%d ", l.ID) } ss = append(ss, sv) const labelHeader = " " if len(s.Label) > 0 { ss = append(ss, labelHeader+labelsToString(s.Label)) } if len(s.NumLabel) > 0 { ss = append(ss, labelHeader+numLabelsToString(s.NumLabel, s.NumUnit)) } return strings.Join(ss, "\n") }
[ "func", "(", "s", "*", "Sample", ")", "string", "(", ")", "string", "{", "ss", ":=", "[", "]", "string", "{", "}", "\n", "var", "sv", "string", "\n", "for", "_", ",", "v", ":=", "range", "s", ".", "Value", "{", "sv", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "sv", ",", "v", ")", "\n", "}", "\n", "sv", "=", "sv", "+", "\"", "\"", "\n", "for", "_", ",", "l", ":=", "range", "s", ".", "Location", "{", "sv", "=", "sv", "+", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "l", ".", "ID", ")", "\n", "}", "\n", "ss", "=", "append", "(", "ss", ",", "sv", ")", "\n", "const", "labelHeader", "=", "\"", "\"", "\n", "if", "len", "(", "s", ".", "Label", ")", ">", "0", "{", "ss", "=", "append", "(", "ss", ",", "labelHeader", "+", "labelsToString", "(", "s", ".", "Label", ")", ")", "\n", "}", "\n", "if", "len", "(", "s", ".", "NumLabel", ")", ">", "0", "{", "ss", "=", "append", "(", "ss", ",", "labelHeader", "+", "numLabelsToString", "(", "s", ".", "NumLabel", ",", "s", ".", "NumUnit", ")", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "ss", ",", "\"", "\\n", "\"", ")", "\n", "}" ]
// string dumps a text representation of a sample. Intended mainly // for debugging purposes.
[ "string", "dumps", "a", "text", "representation", "of", "a", "sample", ".", "Intended", "mainly", "for", "debugging", "purposes", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L623-L642
train
google/pprof
profile/profile.go
labelsToString
func labelsToString(labels map[string][]string) string { ls := []string{} for k, v := range labels { ls = append(ls, fmt.Sprintf("%s:%v", k, v)) } sort.Strings(ls) return strings.Join(ls, " ") }
go
func labelsToString(labels map[string][]string) string { ls := []string{} for k, v := range labels { ls = append(ls, fmt.Sprintf("%s:%v", k, v)) } sort.Strings(ls) return strings.Join(ls, " ") }
[ "func", "labelsToString", "(", "labels", "map", "[", "string", "]", "[", "]", "string", ")", "string", "{", "ls", ":=", "[", "]", "string", "{", "}", "\n", "for", "k", ",", "v", ":=", "range", "labels", "{", "ls", "=", "append", "(", "ls", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "v", ")", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "ls", ")", "\n", "return", "strings", ".", "Join", "(", "ls", ",", "\"", "\"", ")", "\n", "}" ]
// labelsToString returns a string representation of a // map representing labels.
[ "labelsToString", "returns", "a", "string", "representation", "of", "a", "map", "representing", "labels", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L646-L653
train
google/pprof
profile/profile.go
numLabelsToString
func numLabelsToString(numLabels map[string][]int64, numUnits map[string][]string) string { ls := []string{} for k, v := range numLabels { units := numUnits[k] var labelString string if len(units) == len(v) { values := make([]string, len(v)) for i, vv := range v { values[i] = fmt.Sprintf("%d %s", vv, units[i]) } labelString = fmt.Sprintf("%s:%v", k, values) } else { labelString = fmt.Sprintf("%s:%v", k, v) } ls = append(ls, labelString) } sort.Strings(ls) return strings.Join(ls, " ") }
go
func numLabelsToString(numLabels map[string][]int64, numUnits map[string][]string) string { ls := []string{} for k, v := range numLabels { units := numUnits[k] var labelString string if len(units) == len(v) { values := make([]string, len(v)) for i, vv := range v { values[i] = fmt.Sprintf("%d %s", vv, units[i]) } labelString = fmt.Sprintf("%s:%v", k, values) } else { labelString = fmt.Sprintf("%s:%v", k, v) } ls = append(ls, labelString) } sort.Strings(ls) return strings.Join(ls, " ") }
[ "func", "numLabelsToString", "(", "numLabels", "map", "[", "string", "]", "[", "]", "int64", ",", "numUnits", "map", "[", "string", "]", "[", "]", "string", ")", "string", "{", "ls", ":=", "[", "]", "string", "{", "}", "\n", "for", "k", ",", "v", ":=", "range", "numLabels", "{", "units", ":=", "numUnits", "[", "k", "]", "\n", "var", "labelString", "string", "\n", "if", "len", "(", "units", ")", "==", "len", "(", "v", ")", "{", "values", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "v", ")", ")", "\n", "for", "i", ",", "vv", ":=", "range", "v", "{", "values", "[", "i", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "vv", ",", "units", "[", "i", "]", ")", "\n", "}", "\n", "labelString", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "values", ")", "\n", "}", "else", "{", "labelString", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "v", ")", "\n", "}", "\n", "ls", "=", "append", "(", "ls", ",", "labelString", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "ls", ")", "\n", "return", "strings", ".", "Join", "(", "ls", ",", "\"", "\"", ")", "\n", "}" ]
// numLabelsToString returns a string representation of a map // representing numeric labels.
[ "numLabelsToString", "returns", "a", "string", "representation", "of", "a", "map", "representing", "numeric", "labels", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L657-L675
train
google/pprof
profile/profile.go
SetLabel
func (p *Profile) SetLabel(key string, value []string) { for _, sample := range p.Sample { if sample.Label == nil { sample.Label = map[string][]string{key: value} } else { sample.Label[key] = value } } }
go
func (p *Profile) SetLabel(key string, value []string) { for _, sample := range p.Sample { if sample.Label == nil { sample.Label = map[string][]string{key: value} } else { sample.Label[key] = value } } }
[ "func", "(", "p", "*", "Profile", ")", "SetLabel", "(", "key", "string", ",", "value", "[", "]", "string", ")", "{", "for", "_", ",", "sample", ":=", "range", "p", ".", "Sample", "{", "if", "sample", ".", "Label", "==", "nil", "{", "sample", ".", "Label", "=", "map", "[", "string", "]", "[", "]", "string", "{", "key", ":", "value", "}", "\n", "}", "else", "{", "sample", ".", "Label", "[", "key", "]", "=", "value", "\n", "}", "\n", "}", "\n", "}" ]
// SetLabel sets the specified key to the specified value for all samples in the // profile.
[ "SetLabel", "sets", "the", "specified", "key", "to", "the", "specified", "value", "for", "all", "samples", "in", "the", "profile", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L679-L687
train
google/pprof
profile/profile.go
RemoveLabel
func (p *Profile) RemoveLabel(key string) { for _, sample := range p.Sample { delete(sample.Label, key) } }
go
func (p *Profile) RemoveLabel(key string) { for _, sample := range p.Sample { delete(sample.Label, key) } }
[ "func", "(", "p", "*", "Profile", ")", "RemoveLabel", "(", "key", "string", ")", "{", "for", "_", ",", "sample", ":=", "range", "p", ".", "Sample", "{", "delete", "(", "sample", ".", "Label", ",", "key", ")", "\n", "}", "\n", "}" ]
// RemoveLabel removes all labels associated with the specified key for all // samples in the profile.
[ "RemoveLabel", "removes", "all", "labels", "associated", "with", "the", "specified", "key", "for", "all", "samples", "in", "the", "profile", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L691-L695
train
google/pprof
profile/profile.go
HasLabel
func (s *Sample) HasLabel(key, value string) bool { for _, v := range s.Label[key] { if v == value { return true } } return false }
go
func (s *Sample) HasLabel(key, value string) bool { for _, v := range s.Label[key] { if v == value { return true } } return false }
[ "func", "(", "s", "*", "Sample", ")", "HasLabel", "(", "key", ",", "value", "string", ")", "bool", "{", "for", "_", ",", "v", ":=", "range", "s", ".", "Label", "[", "key", "]", "{", "if", "v", "==", "value", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// HasLabel returns true if a sample has a label with indicated key and value.
[ "HasLabel", "returns", "true", "if", "a", "sample", "has", "a", "label", "with", "indicated", "key", "and", "value", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L698-L705
train
google/pprof
profile/profile.go
Scale
func (p *Profile) Scale(ratio float64) { if ratio == 1 { return } ratios := make([]float64, len(p.SampleType)) for i := range p.SampleType { ratios[i] = ratio } p.ScaleN(ratios) }
go
func (p *Profile) Scale(ratio float64) { if ratio == 1 { return } ratios := make([]float64, len(p.SampleType)) for i := range p.SampleType { ratios[i] = ratio } p.ScaleN(ratios) }
[ "func", "(", "p", "*", "Profile", ")", "Scale", "(", "ratio", "float64", ")", "{", "if", "ratio", "==", "1", "{", "return", "\n", "}", "\n", "ratios", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "p", ".", "SampleType", ")", ")", "\n", "for", "i", ":=", "range", "p", ".", "SampleType", "{", "ratios", "[", "i", "]", "=", "ratio", "\n", "}", "\n", "p", ".", "ScaleN", "(", "ratios", ")", "\n", "}" ]
// Scale multiplies all sample values in a profile by a constant.
[ "Scale", "multiplies", "all", "sample", "values", "in", "a", "profile", "by", "a", "constant", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L714-L723
train
google/pprof
profile/profile.go
ScaleN
func (p *Profile) ScaleN(ratios []float64) error { if len(p.SampleType) != len(ratios) { return fmt.Errorf("mismatched scale ratios, got %d, want %d", len(ratios), len(p.SampleType)) } allOnes := true for _, r := range ratios { if r != 1 { allOnes = false break } } if allOnes { return nil } for _, s := range p.Sample { for i, v := range s.Value { if ratios[i] != 1 { s.Value[i] = int64(float64(v) * ratios[i]) } } } return nil }
go
func (p *Profile) ScaleN(ratios []float64) error { if len(p.SampleType) != len(ratios) { return fmt.Errorf("mismatched scale ratios, got %d, want %d", len(ratios), len(p.SampleType)) } allOnes := true for _, r := range ratios { if r != 1 { allOnes = false break } } if allOnes { return nil } for _, s := range p.Sample { for i, v := range s.Value { if ratios[i] != 1 { s.Value[i] = int64(float64(v) * ratios[i]) } } } return nil }
[ "func", "(", "p", "*", "Profile", ")", "ScaleN", "(", "ratios", "[", "]", "float64", ")", "error", "{", "if", "len", "(", "p", ".", "SampleType", ")", "!=", "len", "(", "ratios", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "ratios", ")", ",", "len", "(", "p", ".", "SampleType", ")", ")", "\n", "}", "\n", "allOnes", ":=", "true", "\n", "for", "_", ",", "r", ":=", "range", "ratios", "{", "if", "r", "!=", "1", "{", "allOnes", "=", "false", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "allOnes", "{", "return", "nil", "\n", "}", "\n", "for", "_", ",", "s", ":=", "range", "p", ".", "Sample", "{", "for", "i", ",", "v", ":=", "range", "s", ".", "Value", "{", "if", "ratios", "[", "i", "]", "!=", "1", "{", "s", ".", "Value", "[", "i", "]", "=", "int64", "(", "float64", "(", "v", ")", "*", "ratios", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ScaleN multiplies each sample values in a sample by a different amount.
[ "ScaleN", "multiplies", "each", "sample", "values", "in", "a", "sample", "by", "a", "different", "amount", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L726-L748
train
google/pprof
profile/profile.go
HasFunctions
func (p *Profile) HasFunctions() bool { for _, l := range p.Location { if l.Mapping != nil && !l.Mapping.HasFunctions { return false } } return true }
go
func (p *Profile) HasFunctions() bool { for _, l := range p.Location { if l.Mapping != nil && !l.Mapping.HasFunctions { return false } } return true }
[ "func", "(", "p", "*", "Profile", ")", "HasFunctions", "(", ")", "bool", "{", "for", "_", ",", "l", ":=", "range", "p", ".", "Location", "{", "if", "l", ".", "Mapping", "!=", "nil", "&&", "!", "l", ".", "Mapping", ".", "HasFunctions", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// HasFunctions determines if all locations in this profile have // symbolized function information.
[ "HasFunctions", "determines", "if", "all", "locations", "in", "this", "profile", "have", "symbolized", "function", "information", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L752-L759
train
google/pprof
profile/profile.go
HasFileLines
func (p *Profile) HasFileLines() bool { for _, l := range p.Location { if l.Mapping != nil && (!l.Mapping.HasFilenames || !l.Mapping.HasLineNumbers) { return false } } return true }
go
func (p *Profile) HasFileLines() bool { for _, l := range p.Location { if l.Mapping != nil && (!l.Mapping.HasFilenames || !l.Mapping.HasLineNumbers) { return false } } return true }
[ "func", "(", "p", "*", "Profile", ")", "HasFileLines", "(", ")", "bool", "{", "for", "_", ",", "l", ":=", "range", "p", ".", "Location", "{", "if", "l", ".", "Mapping", "!=", "nil", "&&", "(", "!", "l", ".", "Mapping", ".", "HasFilenames", "||", "!", "l", ".", "Mapping", ".", "HasLineNumbers", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// HasFileLines determines if all locations in this profile have // symbolized file and line number information.
[ "HasFileLines", "determines", "if", "all", "locations", "in", "this", "profile", "have", "symbolized", "file", "and", "line", "number", "information", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L763-L770
train
google/pprof
internal/binutils/addr2liner_nm.go
newAddr2LinerNM
func newAddr2LinerNM(cmd, file string, base uint64) (*addr2LinerNM, error) { if cmd == "" { cmd = defaultNM } var b bytes.Buffer c := exec.Command(cmd, "-n", file) c.Stdout = &b if err := c.Run(); err != nil { return nil, err } return parseAddr2LinerNM(base, &b) }
go
func newAddr2LinerNM(cmd, file string, base uint64) (*addr2LinerNM, error) { if cmd == "" { cmd = defaultNM } var b bytes.Buffer c := exec.Command(cmd, "-n", file) c.Stdout = &b if err := c.Run(); err != nil { return nil, err } return parseAddr2LinerNM(base, &b) }
[ "func", "newAddr2LinerNM", "(", "cmd", ",", "file", "string", ",", "base", "uint64", ")", "(", "*", "addr2LinerNM", ",", "error", ")", "{", "if", "cmd", "==", "\"", "\"", "{", "cmd", "=", "defaultNM", "\n", "}", "\n", "var", "b", "bytes", ".", "Buffer", "\n", "c", ":=", "exec", ".", "Command", "(", "cmd", ",", "\"", "\"", ",", "file", ")", "\n", "c", ".", "Stdout", "=", "&", "b", "\n", "if", "err", ":=", "c", ".", "Run", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "parseAddr2LinerNM", "(", "base", ",", "&", "b", ")", "\n", "}" ]
// newAddr2LinerNM starts the given nm command reporting information about the // given executable file. If file is a shared library, base should be // the address at which it was mapped in the program under // consideration.
[ "newAddr2LinerNM", "starts", "the", "given", "nm", "command", "reporting", "information", "about", "the", "given", "executable", "file", ".", "If", "file", "is", "a", "shared", "library", "base", "should", "be", "the", "address", "at", "which", "it", "was", "mapped", "in", "the", "program", "under", "consideration", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/binutils/addr2liner_nm.go#L47-L58
train
google/pprof
internal/symbolz/symbolz.go
hasGperftoolsSuffix
func hasGperftoolsSuffix(path string) bool { suffixes := []string{ "/pprof/heap", "/pprof/growth", "/pprof/profile", "/pprof/pmuprofile", "/pprof/contention", } for _, s := range suffixes { if strings.HasSuffix(path, s) { return true } } return false }
go
func hasGperftoolsSuffix(path string) bool { suffixes := []string{ "/pprof/heap", "/pprof/growth", "/pprof/profile", "/pprof/pmuprofile", "/pprof/contention", } for _, s := range suffixes { if strings.HasSuffix(path, s) { return true } } return false }
[ "func", "hasGperftoolsSuffix", "(", "path", "string", ")", "bool", "{", "suffixes", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "}", "\n", "for", "_", ",", "s", ":=", "range", "suffixes", "{", "if", "strings", ".", "HasSuffix", "(", "path", ",", "s", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// hasGperftoolsSuffix checks whether path ends with one of the suffixes listed in // pprof_remote_servers.html from the gperftools distribution
[ "hasGperftoolsSuffix", "checks", "whether", "path", "ends", "with", "one", "of", "the", "suffixes", "listed", "in", "pprof_remote_servers", ".", "html", "from", "the", "gperftools", "distribution" ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/symbolz/symbolz.go#L73-L87
train
google/pprof
internal/symbolz/symbolz.go
symbolz
func symbolz(source string) string { if url, err := url.Parse(source); err == nil && url.Host != "" { // All paths in the net/http/pprof Go package contain /debug/pprof/ if strings.Contains(url.Path, "/debug/pprof/") || hasGperftoolsSuffix(url.Path) { url.Path = path.Clean(url.Path + "/../symbol") } else { url.Path = "/symbolz" } url.RawQuery = "" return url.String() } return "" }
go
func symbolz(source string) string { if url, err := url.Parse(source); err == nil && url.Host != "" { // All paths in the net/http/pprof Go package contain /debug/pprof/ if strings.Contains(url.Path, "/debug/pprof/") || hasGperftoolsSuffix(url.Path) { url.Path = path.Clean(url.Path + "/../symbol") } else { url.Path = "/symbolz" } url.RawQuery = "" return url.String() } return "" }
[ "func", "symbolz", "(", "source", "string", ")", "string", "{", "if", "url", ",", "err", ":=", "url", ".", "Parse", "(", "source", ")", ";", "err", "==", "nil", "&&", "url", ".", "Host", "!=", "\"", "\"", "{", "// All paths in the net/http/pprof Go package contain /debug/pprof/", "if", "strings", ".", "Contains", "(", "url", ".", "Path", ",", "\"", "\"", ")", "||", "hasGperftoolsSuffix", "(", "url", ".", "Path", ")", "{", "url", ".", "Path", "=", "path", ".", "Clean", "(", "url", ".", "Path", "+", "\"", "\"", ")", "\n", "}", "else", "{", "url", ".", "Path", "=", "\"", "\"", "\n", "}", "\n", "url", ".", "RawQuery", "=", "\"", "\"", "\n", "return", "url", ".", "String", "(", ")", "\n", "}", "\n\n", "return", "\"", "\"", "\n", "}" ]
// symbolz returns the corresponding symbolz source for a profile URL.
[ "symbolz", "returns", "the", "corresponding", "symbolz", "source", "for", "a", "profile", "URL", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/symbolz/symbolz.go#L90-L103
train
google/pprof
internal/symbolz/symbolz.go
adjust
func adjust(addr uint64, offset int64) (uint64, bool) { adj := uint64(int64(addr) + offset) if offset < 0 { if adj >= addr { return 0, true } } else { if adj < addr { return 0, true } } return adj, false }
go
func adjust(addr uint64, offset int64) (uint64, bool) { adj := uint64(int64(addr) + offset) if offset < 0 { if adj >= addr { return 0, true } } else { if adj < addr { return 0, true } } return adj, false }
[ "func", "adjust", "(", "addr", "uint64", ",", "offset", "int64", ")", "(", "uint64", ",", "bool", ")", "{", "adj", ":=", "uint64", "(", "int64", "(", "addr", ")", "+", "offset", ")", "\n", "if", "offset", "<", "0", "{", "if", "adj", ">=", "addr", "{", "return", "0", ",", "true", "\n", "}", "\n", "}", "else", "{", "if", "adj", "<", "addr", "{", "return", "0", ",", "true", "\n", "}", "\n", "}", "\n", "return", "adj", ",", "false", "\n", "}" ]
// adjust shifts the specified address by the signed offset. It returns the // adjusted address. It signals that the address cannot be adjusted without an // overflow by returning true in the second return value.
[ "adjust", "shifts", "the", "specified", "address", "by", "the", "signed", "offset", ".", "It", "returns", "the", "adjusted", "address", ".", "It", "signals", "that", "the", "address", "cannot", "be", "adjusted", "without", "an", "overflow", "by", "returning", "true", "in", "the", "second", "return", "value", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/symbolz/symbolz.go#L188-L200
train
google/pprof
internal/driver/svg.go
massageSVG
func massageSVG(svg string) string { // Work around for dot bug which misses quoting some ampersands, // resulting on unparsable SVG. svg = strings.Replace(svg, "&;", "&amp;;", -1) // Dot's SVG output is // // <svg width="___" height="___" // viewBox="___" xmlns=...> // <g id="graph0" transform="..."> // ... // </g> // </svg> // // Change it to // // <svg width="100%" height="100%" // xmlns=...> // <script type="text/ecmascript"><![CDATA[` ..$(svgpan.JSSource)... `]]></script>` // <g id="viewport" transform="translate(0,0)"> // <g id="graph0" transform="..."> // ... // </g> // </g> // </svg> if loc := viewBox.FindStringIndex(svg); loc != nil { svg = svg[:loc[0]] + `<svg width="100%" height="100%"` + svg[loc[1]:] } if loc := graphID.FindStringIndex(svg); loc != nil { svg = svg[:loc[0]] + `<script type="text/ecmascript"><![CDATA[` + string(svgpan.JSSource) + `]]></script>` + `<g id="viewport" transform="scale(0.5,0.5) translate(0,0)">` + svg[loc[0]:] } if loc := svgClose.FindStringIndex(svg); loc != nil { svg = svg[:loc[0]] + `</g>` + svg[loc[0]:] } return svg }
go
func massageSVG(svg string) string { // Work around for dot bug which misses quoting some ampersands, // resulting on unparsable SVG. svg = strings.Replace(svg, "&;", "&amp;;", -1) // Dot's SVG output is // // <svg width="___" height="___" // viewBox="___" xmlns=...> // <g id="graph0" transform="..."> // ... // </g> // </svg> // // Change it to // // <svg width="100%" height="100%" // xmlns=...> // <script type="text/ecmascript"><![CDATA[` ..$(svgpan.JSSource)... `]]></script>` // <g id="viewport" transform="translate(0,0)"> // <g id="graph0" transform="..."> // ... // </g> // </g> // </svg> if loc := viewBox.FindStringIndex(svg); loc != nil { svg = svg[:loc[0]] + `<svg width="100%" height="100%"` + svg[loc[1]:] } if loc := graphID.FindStringIndex(svg); loc != nil { svg = svg[:loc[0]] + `<script type="text/ecmascript"><![CDATA[` + string(svgpan.JSSource) + `]]></script>` + `<g id="viewport" transform="scale(0.5,0.5) translate(0,0)">` + svg[loc[0]:] } if loc := svgClose.FindStringIndex(svg); loc != nil { svg = svg[:loc[0]] + `</g>` + svg[loc[0]:] } return svg }
[ "func", "massageSVG", "(", "svg", "string", ")", "string", "{", "// Work around for dot bug which misses quoting some ampersands,", "// resulting on unparsable SVG.", "svg", "=", "strings", ".", "Replace", "(", "svg", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n\n", "// Dot's SVG output is", "//", "// <svg width=\"___\" height=\"___\"", "// viewBox=\"___\" xmlns=...>", "// <g id=\"graph0\" transform=\"...\">", "// ...", "// </g>", "// </svg>", "//", "// Change it to", "//", "// <svg width=\"100%\" height=\"100%\"", "// xmlns=...>", "// <script type=\"text/ecmascript\"><![CDATA[` ..$(svgpan.JSSource)... `]]></script>`", "// <g id=\"viewport\" transform=\"translate(0,0)\">", "// <g id=\"graph0\" transform=\"...\">", "// ...", "// </g>", "// </g>", "// </svg>", "if", "loc", ":=", "viewBox", ".", "FindStringIndex", "(", "svg", ")", ";", "loc", "!=", "nil", "{", "svg", "=", "svg", "[", ":", "loc", "[", "0", "]", "]", "+", "`<svg width=\"100%\" height=\"100%\"`", "+", "svg", "[", "loc", "[", "1", "]", ":", "]", "\n", "}", "\n\n", "if", "loc", ":=", "graphID", ".", "FindStringIndex", "(", "svg", ")", ";", "loc", "!=", "nil", "{", "svg", "=", "svg", "[", ":", "loc", "[", "0", "]", "]", "+", "`<script type=\"text/ecmascript\"><![CDATA[`", "+", "string", "(", "svgpan", ".", "JSSource", ")", "+", "`]]></script>`", "+", "`<g id=\"viewport\" transform=\"scale(0.5,0.5) translate(0,0)\">`", "+", "svg", "[", "loc", "[", "0", "]", ":", "]", "\n", "}", "\n\n", "if", "loc", ":=", "svgClose", ".", "FindStringIndex", "(", "svg", ")", ";", "loc", "!=", "nil", "{", "svg", "=", "svg", "[", ":", "loc", "[", "0", "]", "]", "+", "`</g>`", "+", "svg", "[", "loc", "[", "0", "]", ":", "]", "\n", "}", "\n\n", "return", "svg", "\n", "}" ]
// massageSVG enhances the SVG output from DOT to provide better // panning inside a web browser. It uses the svgpan library, which is // embedded into the svgpan.JSSource variable.
[ "massageSVG", "enhances", "the", "SVG", "output", "from", "DOT", "to", "provide", "better", "panning", "inside", "a", "web", "browser", ".", "It", "uses", "the", "svgpan", "library", "which", "is", "embedded", "into", "the", "svgpan", ".", "JSSource", "variable", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/svg.go#L33-L80
train
google/pprof
profile/legacy_profile.go
remapLocationIDs
func (p *Profile) remapLocationIDs() { seen := make(map[*Location]bool, len(p.Location)) var locs []*Location for _, s := range p.Sample { for _, l := range s.Location { if seen[l] { continue } l.ID = uint64(len(locs) + 1) locs = append(locs, l) seen[l] = true } } p.Location = locs }
go
func (p *Profile) remapLocationIDs() { seen := make(map[*Location]bool, len(p.Location)) var locs []*Location for _, s := range p.Sample { for _, l := range s.Location { if seen[l] { continue } l.ID = uint64(len(locs) + 1) locs = append(locs, l) seen[l] = true } } p.Location = locs }
[ "func", "(", "p", "*", "Profile", ")", "remapLocationIDs", "(", ")", "{", "seen", ":=", "make", "(", "map", "[", "*", "Location", "]", "bool", ",", "len", "(", "p", ".", "Location", ")", ")", "\n", "var", "locs", "[", "]", "*", "Location", "\n\n", "for", "_", ",", "s", ":=", "range", "p", ".", "Sample", "{", "for", "_", ",", "l", ":=", "range", "s", ".", "Location", "{", "if", "seen", "[", "l", "]", "{", "continue", "\n", "}", "\n", "l", ".", "ID", "=", "uint64", "(", "len", "(", "locs", ")", "+", "1", ")", "\n", "locs", "=", "append", "(", "locs", ",", "l", ")", "\n", "seen", "[", "l", "]", "=", "true", "\n", "}", "\n", "}", "\n", "p", ".", "Location", "=", "locs", "\n", "}" ]
// remapLocationIDs ensures there is a location for each address // referenced by a sample, and remaps the samples to point to the new // location ids.
[ "remapLocationIDs", "ensures", "there", "is", "a", "location", "for", "each", "address", "referenced", "by", "a", "sample", "and", "remaps", "the", "samples", "to", "point", "to", "the", "new", "location", "ids", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/legacy_profile.go#L151-L166
train
google/pprof
profile/legacy_profile.go
parseContentionSample
func parseContentionSample(line string, period, cpuHz int64) (value []int64, addrs []uint64, err error) { sampleData := contentionSampleRE.FindStringSubmatch(line) if sampleData == nil { return nil, nil, errUnrecognized } v1, err := strconv.ParseInt(sampleData[1], 10, 64) if err != nil { return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err) } v2, err := strconv.ParseInt(sampleData[2], 10, 64) if err != nil { return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err) } // Unsample values if period and cpuHz are available. // - Delays are scaled to cycles and then to nanoseconds. // - Contentions are scaled to cycles. if period > 0 { if cpuHz > 0 { cpuGHz := float64(cpuHz) / 1e9 v1 = int64(float64(v1) * float64(period) / cpuGHz) } v2 = v2 * period } value = []int64{v2, v1} addrs, err = parseHexAddresses(sampleData[3]) if err != nil { return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err) } return value, addrs, nil }
go
func parseContentionSample(line string, period, cpuHz int64) (value []int64, addrs []uint64, err error) { sampleData := contentionSampleRE.FindStringSubmatch(line) if sampleData == nil { return nil, nil, errUnrecognized } v1, err := strconv.ParseInt(sampleData[1], 10, 64) if err != nil { return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err) } v2, err := strconv.ParseInt(sampleData[2], 10, 64) if err != nil { return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err) } // Unsample values if period and cpuHz are available. // - Delays are scaled to cycles and then to nanoseconds. // - Contentions are scaled to cycles. if period > 0 { if cpuHz > 0 { cpuGHz := float64(cpuHz) / 1e9 v1 = int64(float64(v1) * float64(period) / cpuGHz) } v2 = v2 * period } value = []int64{v2, v1} addrs, err = parseHexAddresses(sampleData[3]) if err != nil { return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err) } return value, addrs, nil }
[ "func", "parseContentionSample", "(", "line", "string", ",", "period", ",", "cpuHz", "int64", ")", "(", "value", "[", "]", "int64", ",", "addrs", "[", "]", "uint64", ",", "err", "error", ")", "{", "sampleData", ":=", "contentionSampleRE", ".", "FindStringSubmatch", "(", "line", ")", "\n", "if", "sampleData", "==", "nil", "{", "return", "nil", ",", "nil", ",", "errUnrecognized", "\n", "}", "\n\n", "v1", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "sampleData", "[", "1", "]", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "line", ",", "err", ")", "\n", "}", "\n", "v2", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "sampleData", "[", "2", "]", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "line", ",", "err", ")", "\n", "}", "\n\n", "// Unsample values if period and cpuHz are available.", "// - Delays are scaled to cycles and then to nanoseconds.", "// - Contentions are scaled to cycles.", "if", "period", ">", "0", "{", "if", "cpuHz", ">", "0", "{", "cpuGHz", ":=", "float64", "(", "cpuHz", ")", "/", "1e9", "\n", "v1", "=", "int64", "(", "float64", "(", "v1", ")", "*", "float64", "(", "period", ")", "/", "cpuGHz", ")", "\n", "}", "\n", "v2", "=", "v2", "*", "period", "\n", "}", "\n\n", "value", "=", "[", "]", "int64", "{", "v2", ",", "v1", "}", "\n", "addrs", ",", "err", "=", "parseHexAddresses", "(", "sampleData", "[", "3", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "line", ",", "err", ")", "\n", "}", "\n\n", "return", "value", ",", "addrs", ",", "nil", "\n", "}" ]
// parseContentionSample parses a single row from a contention profile // into a new Sample.
[ "parseContentionSample", "parses", "a", "single", "row", "from", "a", "contention", "profile", "into", "a", "new", "Sample", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/legacy_profile.go#L800-L833
train
google/pprof
profile/legacy_profile.go
removeLoggingInfo
func removeLoggingInfo(line string) string { if match := logInfoRE.FindStringIndex(line); match != nil { return line[match[1]:] } return line }
go
func removeLoggingInfo(line string) string { if match := logInfoRE.FindStringIndex(line); match != nil { return line[match[1]:] } return line }
[ "func", "removeLoggingInfo", "(", "line", "string", ")", "string", "{", "if", "match", ":=", "logInfoRE", ".", "FindStringIndex", "(", "line", ")", ";", "match", "!=", "nil", "{", "return", "line", "[", "match", "[", "1", "]", ":", "]", "\n", "}", "\n", "return", "line", "\n", "}" ]
// removeLoggingInfo detects and removes log prefix entries generated // by the glog package. If no logging prefix is detected, the string // is returned unmodified.
[ "removeLoggingInfo", "detects", "and", "removes", "log", "prefix", "entries", "generated", "by", "the", "glog", "package", ".", "If", "no", "logging", "prefix", "is", "detected", "the", "string", "is", "returned", "unmodified", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/legacy_profile.go#L1010-L1015
train
google/pprof
profile/legacy_profile.go
isMemoryMapSentinel
func isMemoryMapSentinel(line string) bool { for _, s := range memoryMapSentinels { if strings.Contains(line, s) { return true } } return false }
go
func isMemoryMapSentinel(line string) bool { for _, s := range memoryMapSentinels { if strings.Contains(line, s) { return true } } return false }
[ "func", "isMemoryMapSentinel", "(", "line", "string", ")", "bool", "{", "for", "_", ",", "s", ":=", "range", "memoryMapSentinels", "{", "if", "strings", ".", "Contains", "(", "line", ",", "s", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// isMemoryMapSentinel returns true if the string contains one of the // known sentinels for memory map information.
[ "isMemoryMapSentinel", "returns", "true", "if", "the", "string", "contains", "one", "of", "the", "known", "sentinels", "for", "memory", "map", "information", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/legacy_profile.go#L1081-L1088
train
google/pprof
profile/legacy_java_profile.go
javaCPUProfile
func javaCPUProfile(b []byte, period int64, parse func(b []byte) (uint64, []byte)) (*Profile, error) { p := &Profile{ Period: period * 1000, PeriodType: &ValueType{Type: "cpu", Unit: "nanoseconds"}, SampleType: []*ValueType{{Type: "samples", Unit: "count"}, {Type: "cpu", Unit: "nanoseconds"}}, } var err error var locs map[uint64]*Location if b, locs, err = parseCPUSamples(b, parse, false, p); err != nil { return nil, err } if err = parseJavaLocations(b, locs, p); err != nil { return nil, err } // Strip out addresses for better merge. if err = p.Aggregate(true, true, true, true, false); err != nil { return nil, err } return p, nil }
go
func javaCPUProfile(b []byte, period int64, parse func(b []byte) (uint64, []byte)) (*Profile, error) { p := &Profile{ Period: period * 1000, PeriodType: &ValueType{Type: "cpu", Unit: "nanoseconds"}, SampleType: []*ValueType{{Type: "samples", Unit: "count"}, {Type: "cpu", Unit: "nanoseconds"}}, } var err error var locs map[uint64]*Location if b, locs, err = parseCPUSamples(b, parse, false, p); err != nil { return nil, err } if err = parseJavaLocations(b, locs, p); err != nil { return nil, err } // Strip out addresses for better merge. if err = p.Aggregate(true, true, true, true, false); err != nil { return nil, err } return p, nil }
[ "func", "javaCPUProfile", "(", "b", "[", "]", "byte", ",", "period", "int64", ",", "parse", "func", "(", "b", "[", "]", "byte", ")", "(", "uint64", ",", "[", "]", "byte", ")", ")", "(", "*", "Profile", ",", "error", ")", "{", "p", ":=", "&", "Profile", "{", "Period", ":", "period", "*", "1000", ",", "PeriodType", ":", "&", "ValueType", "{", "Type", ":", "\"", "\"", ",", "Unit", ":", "\"", "\"", "}", ",", "SampleType", ":", "[", "]", "*", "ValueType", "{", "{", "Type", ":", "\"", "\"", ",", "Unit", ":", "\"", "\"", "}", ",", "{", "Type", ":", "\"", "\"", ",", "Unit", ":", "\"", "\"", "}", "}", ",", "}", "\n", "var", "err", "error", "\n", "var", "locs", "map", "[", "uint64", "]", "*", "Location", "\n", "if", "b", ",", "locs", ",", "err", "=", "parseCPUSamples", "(", "b", ",", "parse", ",", "false", ",", "p", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", "=", "parseJavaLocations", "(", "b", ",", "locs", ",", "p", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Strip out addresses for better merge.", "if", "err", "=", "p", ".", "Aggregate", "(", "true", ",", "true", ",", "true", ",", "true", ",", "false", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "p", ",", "nil", "\n", "}" ]
// javaCPUProfile returns a new Profile from profilez data. // b is the profile bytes after the header, period is the profiling // period, and parse is a function to parse 8-byte chunks from the // profile in its native endianness.
[ "javaCPUProfile", "returns", "a", "new", "Profile", "from", "profilez", "data", ".", "b", "is", "the", "profile", "bytes", "after", "the", "header", "period", "is", "the", "profiling", "period", "and", "parse", "is", "a", "function", "to", "parse", "8", "-", "byte", "chunks", "from", "the", "profile", "in", "its", "native", "endianness", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/legacy_java_profile.go#L42-L64
train
google/pprof
profile/legacy_java_profile.go
parseJavaProfile
func parseJavaProfile(b []byte) (*Profile, error) { h := bytes.SplitAfterN(b, []byte("\n"), 2) if len(h) < 2 { return nil, errUnrecognized } p := &Profile{ PeriodType: &ValueType{}, } header := string(bytes.TrimSpace(h[0])) var err error var pType string switch header { case "--- heapz 1 ---": pType = "heap" case "--- contentionz 1 ---": pType = "contention" default: return nil, errUnrecognized } if b, err = parseJavaHeader(pType, h[1], p); err != nil { return nil, err } var locs map[uint64]*Location if b, locs, err = parseJavaSamples(pType, b, p); err != nil { return nil, err } if err = parseJavaLocations(b, locs, p); err != nil { return nil, err } // Strip out addresses for better merge. if err = p.Aggregate(true, true, true, true, false); err != nil { return nil, err } return p, nil }
go
func parseJavaProfile(b []byte) (*Profile, error) { h := bytes.SplitAfterN(b, []byte("\n"), 2) if len(h) < 2 { return nil, errUnrecognized } p := &Profile{ PeriodType: &ValueType{}, } header := string(bytes.TrimSpace(h[0])) var err error var pType string switch header { case "--- heapz 1 ---": pType = "heap" case "--- contentionz 1 ---": pType = "contention" default: return nil, errUnrecognized } if b, err = parseJavaHeader(pType, h[1], p); err != nil { return nil, err } var locs map[uint64]*Location if b, locs, err = parseJavaSamples(pType, b, p); err != nil { return nil, err } if err = parseJavaLocations(b, locs, p); err != nil { return nil, err } // Strip out addresses for better merge. if err = p.Aggregate(true, true, true, true, false); err != nil { return nil, err } return p, nil }
[ "func", "parseJavaProfile", "(", "b", "[", "]", "byte", ")", "(", "*", "Profile", ",", "error", ")", "{", "h", ":=", "bytes", ".", "SplitAfterN", "(", "b", ",", "[", "]", "byte", "(", "\"", "\\n", "\"", ")", ",", "2", ")", "\n", "if", "len", "(", "h", ")", "<", "2", "{", "return", "nil", ",", "errUnrecognized", "\n", "}", "\n\n", "p", ":=", "&", "Profile", "{", "PeriodType", ":", "&", "ValueType", "{", "}", ",", "}", "\n", "header", ":=", "string", "(", "bytes", ".", "TrimSpace", "(", "h", "[", "0", "]", ")", ")", "\n\n", "var", "err", "error", "\n", "var", "pType", "string", "\n", "switch", "header", "{", "case", "\"", "\"", ":", "pType", "=", "\"", "\"", "\n", "case", "\"", "\"", ":", "pType", "=", "\"", "\"", "\n", "default", ":", "return", "nil", ",", "errUnrecognized", "\n", "}", "\n\n", "if", "b", ",", "err", "=", "parseJavaHeader", "(", "pType", ",", "h", "[", "1", "]", ",", "p", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "locs", "map", "[", "uint64", "]", "*", "Location", "\n", "if", "b", ",", "locs", ",", "err", "=", "parseJavaSamples", "(", "pType", ",", "b", ",", "p", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", "=", "parseJavaLocations", "(", "b", ",", "locs", ",", "p", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Strip out addresses for better merge.", "if", "err", "=", "p", ".", "Aggregate", "(", "true", ",", "true", ",", "true", ",", "true", ",", "false", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "p", ",", "nil", "\n", "}" ]
// parseJavaProfile returns a new profile from heapz or contentionz // data. b is the profile bytes after the header.
[ "parseJavaProfile", "returns", "a", "new", "profile", "from", "heapz", "or", "contentionz", "data", ".", "b", "is", "the", "profile", "bytes", "after", "the", "header", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/legacy_java_profile.go#L68-L107
train
google/pprof
profile/legacy_java_profile.go
parseJavaHeader
func parseJavaHeader(pType string, b []byte, p *Profile) ([]byte, error) { nextNewLine := bytes.IndexByte(b, byte('\n')) for nextNewLine != -1 { line := string(bytes.TrimSpace(b[0:nextNewLine])) if line != "" { h := attributeRx.FindStringSubmatch(line) if h == nil { // Not a valid attribute, exit. return b, nil } attribute, value := strings.TrimSpace(h[1]), strings.TrimSpace(h[2]) var err error switch pType + "/" + attribute { case "heap/format", "cpu/format", "contention/format": if value != "java" { return nil, errUnrecognized } case "heap/resolution": p.SampleType = []*ValueType{ {Type: "inuse_objects", Unit: "count"}, {Type: "inuse_space", Unit: value}, } case "contention/resolution": p.SampleType = []*ValueType{ {Type: "contentions", Unit: "count"}, {Type: "delay", Unit: value}, } case "contention/sampling period": p.PeriodType = &ValueType{ Type: "contentions", Unit: "count", } if p.Period, err = strconv.ParseInt(value, 0, 64); err != nil { return nil, fmt.Errorf("failed to parse attribute %s: %v", line, err) } case "contention/ms since reset": millis, err := strconv.ParseInt(value, 0, 64) if err != nil { return nil, fmt.Errorf("failed to parse attribute %s: %v", line, err) } p.DurationNanos = millis * 1000 * 1000 default: return nil, errUnrecognized } } // Grab next line. b = b[nextNewLine+1:] nextNewLine = bytes.IndexByte(b, byte('\n')) } return b, nil }
go
func parseJavaHeader(pType string, b []byte, p *Profile) ([]byte, error) { nextNewLine := bytes.IndexByte(b, byte('\n')) for nextNewLine != -1 { line := string(bytes.TrimSpace(b[0:nextNewLine])) if line != "" { h := attributeRx.FindStringSubmatch(line) if h == nil { // Not a valid attribute, exit. return b, nil } attribute, value := strings.TrimSpace(h[1]), strings.TrimSpace(h[2]) var err error switch pType + "/" + attribute { case "heap/format", "cpu/format", "contention/format": if value != "java" { return nil, errUnrecognized } case "heap/resolution": p.SampleType = []*ValueType{ {Type: "inuse_objects", Unit: "count"}, {Type: "inuse_space", Unit: value}, } case "contention/resolution": p.SampleType = []*ValueType{ {Type: "contentions", Unit: "count"}, {Type: "delay", Unit: value}, } case "contention/sampling period": p.PeriodType = &ValueType{ Type: "contentions", Unit: "count", } if p.Period, err = strconv.ParseInt(value, 0, 64); err != nil { return nil, fmt.Errorf("failed to parse attribute %s: %v", line, err) } case "contention/ms since reset": millis, err := strconv.ParseInt(value, 0, 64) if err != nil { return nil, fmt.Errorf("failed to parse attribute %s: %v", line, err) } p.DurationNanos = millis * 1000 * 1000 default: return nil, errUnrecognized } } // Grab next line. b = b[nextNewLine+1:] nextNewLine = bytes.IndexByte(b, byte('\n')) } return b, nil }
[ "func", "parseJavaHeader", "(", "pType", "string", ",", "b", "[", "]", "byte", ",", "p", "*", "Profile", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "nextNewLine", ":=", "bytes", ".", "IndexByte", "(", "b", ",", "byte", "(", "'\\n'", ")", ")", "\n", "for", "nextNewLine", "!=", "-", "1", "{", "line", ":=", "string", "(", "bytes", ".", "TrimSpace", "(", "b", "[", "0", ":", "nextNewLine", "]", ")", ")", "\n", "if", "line", "!=", "\"", "\"", "{", "h", ":=", "attributeRx", ".", "FindStringSubmatch", "(", "line", ")", "\n", "if", "h", "==", "nil", "{", "// Not a valid attribute, exit.", "return", "b", ",", "nil", "\n", "}", "\n\n", "attribute", ",", "value", ":=", "strings", ".", "TrimSpace", "(", "h", "[", "1", "]", ")", ",", "strings", ".", "TrimSpace", "(", "h", "[", "2", "]", ")", "\n", "var", "err", "error", "\n", "switch", "pType", "+", "\"", "\"", "+", "attribute", "{", "case", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ":", "if", "value", "!=", "\"", "\"", "{", "return", "nil", ",", "errUnrecognized", "\n", "}", "\n", "case", "\"", "\"", ":", "p", ".", "SampleType", "=", "[", "]", "*", "ValueType", "{", "{", "Type", ":", "\"", "\"", ",", "Unit", ":", "\"", "\"", "}", ",", "{", "Type", ":", "\"", "\"", ",", "Unit", ":", "value", "}", ",", "}", "\n", "case", "\"", "\"", ":", "p", ".", "SampleType", "=", "[", "]", "*", "ValueType", "{", "{", "Type", ":", "\"", "\"", ",", "Unit", ":", "\"", "\"", "}", ",", "{", "Type", ":", "\"", "\"", ",", "Unit", ":", "value", "}", ",", "}", "\n", "case", "\"", "\"", ":", "p", ".", "PeriodType", "=", "&", "ValueType", "{", "Type", ":", "\"", "\"", ",", "Unit", ":", "\"", "\"", ",", "}", "\n", "if", "p", ".", "Period", ",", "err", "=", "strconv", ".", "ParseInt", "(", "value", ",", "0", ",", "64", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "line", ",", "err", ")", "\n", "}", "\n", "case", "\"", "\"", ":", "millis", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "value", ",", "0", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "line", ",", "err", ")", "\n", "}", "\n", "p", ".", "DurationNanos", "=", "millis", "*", "1000", "*", "1000", "\n", "default", ":", "return", "nil", ",", "errUnrecognized", "\n", "}", "\n", "}", "\n", "// Grab next line.", "b", "=", "b", "[", "nextNewLine", "+", "1", ":", "]", "\n", "nextNewLine", "=", "bytes", ".", "IndexByte", "(", "b", ",", "byte", "(", "'\\n'", ")", ")", "\n", "}", "\n", "return", "b", ",", "nil", "\n", "}" ]
// parseJavaHeader parses the attribute section on a java profile and // populates a profile. Returns the remainder of the buffer after all // attributes.
[ "parseJavaHeader", "parses", "the", "attribute", "section", "on", "a", "java", "profile", "and", "populates", "a", "profile", ".", "Returns", "the", "remainder", "of", "the", "buffer", "after", "all", "attributes", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/legacy_java_profile.go#L112-L162
train
google/pprof
profile/legacy_java_profile.go
parseJavaLocations
func parseJavaLocations(b []byte, locs map[uint64]*Location, p *Profile) error { r := bytes.NewBuffer(b) fns := make(map[string]*Function) for { line, err := r.ReadString('\n') if err != nil { if err != io.EOF { return err } if line == "" { break } } if line = strings.TrimSpace(line); line == "" { continue } jloc := javaLocationRx.FindStringSubmatch(line) if len(jloc) != 3 { continue } addr, err := strconv.ParseUint(jloc[1], 16, 64) if err != nil { return fmt.Errorf("parsing sample %s: %v", line, err) } loc := locs[addr] if loc == nil { // Unused/unseen continue } var lineFunc, lineFile string var lineNo int64 if fileLine := javaLocationFileLineRx.FindStringSubmatch(jloc[2]); len(fileLine) == 4 { // Found a line of the form: "function (file:line)" lineFunc, lineFile = fileLine[1], fileLine[2] if n, err := strconv.ParseInt(fileLine[3], 10, 64); err == nil && n > 0 { lineNo = n } } else if filePath := javaLocationPathRx.FindStringSubmatch(jloc[2]); len(filePath) == 3 { // If there's not a file:line, it's a shared library path. // The path isn't interesting, so just give the .so. lineFunc, lineFile = filePath[1], filepath.Base(filePath[2]) } else if strings.Contains(jloc[2], "generated stub/JIT") { lineFunc = "STUB" } else { // Treat whole line as the function name. This is used by the // java agent for internal states such as "GC" or "VM". lineFunc = jloc[2] } fn := fns[lineFunc] if fn == nil { fn = &Function{ Name: lineFunc, SystemName: lineFunc, Filename: lineFile, } fns[lineFunc] = fn p.Function = append(p.Function, fn) } loc.Line = []Line{ { Function: fn, Line: lineNo, }, } loc.Address = 0 } p.remapLocationIDs() p.remapFunctionIDs() p.remapMappingIDs() return nil }
go
func parseJavaLocations(b []byte, locs map[uint64]*Location, p *Profile) error { r := bytes.NewBuffer(b) fns := make(map[string]*Function) for { line, err := r.ReadString('\n') if err != nil { if err != io.EOF { return err } if line == "" { break } } if line = strings.TrimSpace(line); line == "" { continue } jloc := javaLocationRx.FindStringSubmatch(line) if len(jloc) != 3 { continue } addr, err := strconv.ParseUint(jloc[1], 16, 64) if err != nil { return fmt.Errorf("parsing sample %s: %v", line, err) } loc := locs[addr] if loc == nil { // Unused/unseen continue } var lineFunc, lineFile string var lineNo int64 if fileLine := javaLocationFileLineRx.FindStringSubmatch(jloc[2]); len(fileLine) == 4 { // Found a line of the form: "function (file:line)" lineFunc, lineFile = fileLine[1], fileLine[2] if n, err := strconv.ParseInt(fileLine[3], 10, 64); err == nil && n > 0 { lineNo = n } } else if filePath := javaLocationPathRx.FindStringSubmatch(jloc[2]); len(filePath) == 3 { // If there's not a file:line, it's a shared library path. // The path isn't interesting, so just give the .so. lineFunc, lineFile = filePath[1], filepath.Base(filePath[2]) } else if strings.Contains(jloc[2], "generated stub/JIT") { lineFunc = "STUB" } else { // Treat whole line as the function name. This is used by the // java agent for internal states such as "GC" or "VM". lineFunc = jloc[2] } fn := fns[lineFunc] if fn == nil { fn = &Function{ Name: lineFunc, SystemName: lineFunc, Filename: lineFile, } fns[lineFunc] = fn p.Function = append(p.Function, fn) } loc.Line = []Line{ { Function: fn, Line: lineNo, }, } loc.Address = 0 } p.remapLocationIDs() p.remapFunctionIDs() p.remapMappingIDs() return nil }
[ "func", "parseJavaLocations", "(", "b", "[", "]", "byte", ",", "locs", "map", "[", "uint64", "]", "*", "Location", ",", "p", "*", "Profile", ")", "error", "{", "r", ":=", "bytes", ".", "NewBuffer", "(", "b", ")", "\n", "fns", ":=", "make", "(", "map", "[", "string", "]", "*", "Function", ")", "\n", "for", "{", "line", ",", "err", ":=", "r", ".", "ReadString", "(", "'\\n'", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "!=", "io", ".", "EOF", "{", "return", "err", "\n", "}", "\n", "if", "line", "==", "\"", "\"", "{", "break", "\n", "}", "\n", "}", "\n\n", "if", "line", "=", "strings", ".", "TrimSpace", "(", "line", ")", ";", "line", "==", "\"", "\"", "{", "continue", "\n", "}", "\n\n", "jloc", ":=", "javaLocationRx", ".", "FindStringSubmatch", "(", "line", ")", "\n", "if", "len", "(", "jloc", ")", "!=", "3", "{", "continue", "\n", "}", "\n", "addr", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "jloc", "[", "1", "]", ",", "16", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "line", ",", "err", ")", "\n", "}", "\n", "loc", ":=", "locs", "[", "addr", "]", "\n", "if", "loc", "==", "nil", "{", "// Unused/unseen", "continue", "\n", "}", "\n", "var", "lineFunc", ",", "lineFile", "string", "\n", "var", "lineNo", "int64", "\n\n", "if", "fileLine", ":=", "javaLocationFileLineRx", ".", "FindStringSubmatch", "(", "jloc", "[", "2", "]", ")", ";", "len", "(", "fileLine", ")", "==", "4", "{", "// Found a line of the form: \"function (file:line)\"", "lineFunc", ",", "lineFile", "=", "fileLine", "[", "1", "]", ",", "fileLine", "[", "2", "]", "\n", "if", "n", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "fileLine", "[", "3", "]", ",", "10", ",", "64", ")", ";", "err", "==", "nil", "&&", "n", ">", "0", "{", "lineNo", "=", "n", "\n", "}", "\n", "}", "else", "if", "filePath", ":=", "javaLocationPathRx", ".", "FindStringSubmatch", "(", "jloc", "[", "2", "]", ")", ";", "len", "(", "filePath", ")", "==", "3", "{", "// If there's not a file:line, it's a shared library path.", "// The path isn't interesting, so just give the .so.", "lineFunc", ",", "lineFile", "=", "filePath", "[", "1", "]", ",", "filepath", ".", "Base", "(", "filePath", "[", "2", "]", ")", "\n", "}", "else", "if", "strings", ".", "Contains", "(", "jloc", "[", "2", "]", ",", "\"", "\"", ")", "{", "lineFunc", "=", "\"", "\"", "\n", "}", "else", "{", "// Treat whole line as the function name. This is used by the", "// java agent for internal states such as \"GC\" or \"VM\".", "lineFunc", "=", "jloc", "[", "2", "]", "\n", "}", "\n", "fn", ":=", "fns", "[", "lineFunc", "]", "\n\n", "if", "fn", "==", "nil", "{", "fn", "=", "&", "Function", "{", "Name", ":", "lineFunc", ",", "SystemName", ":", "lineFunc", ",", "Filename", ":", "lineFile", ",", "}", "\n", "fns", "[", "lineFunc", "]", "=", "fn", "\n", "p", ".", "Function", "=", "append", "(", "p", ".", "Function", ",", "fn", ")", "\n", "}", "\n", "loc", ".", "Line", "=", "[", "]", "Line", "{", "{", "Function", ":", "fn", ",", "Line", ":", "lineNo", ",", "}", ",", "}", "\n", "loc", ".", "Address", "=", "0", "\n", "}", "\n\n", "p", ".", "remapLocationIDs", "(", ")", "\n", "p", ".", "remapFunctionIDs", "(", ")", "\n", "p", ".", "remapMappingIDs", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// parseJavaLocations parses the location information in a java // profile and populates the Locations in a profile. It uses the // location addresses from the profile as both the ID of each // location.
[ "parseJavaLocations", "parses", "the", "location", "information", "in", "a", "java", "profile", "and", "populates", "the", "Locations", "in", "a", "profile", ".", "It", "uses", "the", "location", "addresses", "from", "the", "profile", "as", "both", "the", "ID", "of", "each", "location", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/legacy_java_profile.go#L239-L315
train
google/pprof
profile/prune.go
simplifyFunc
func simplifyFunc(f string) string { // Account for leading '.' on the PPC ELF v1 ABI. funcName := strings.TrimPrefix(f, ".") // Account for unsimplified names -- try to remove the argument list by trimming // starting from the first '(', but skipping reserved names that have '('. for _, ind := range bracketRx.FindAllStringSubmatchIndex(funcName, -1) { foundReserved := false for _, res := range reservedNames { if funcName[ind[0]:ind[1]] == res { foundReserved = true break } } if !foundReserved { funcName = funcName[:ind[0]] break } } return funcName }
go
func simplifyFunc(f string) string { // Account for leading '.' on the PPC ELF v1 ABI. funcName := strings.TrimPrefix(f, ".") // Account for unsimplified names -- try to remove the argument list by trimming // starting from the first '(', but skipping reserved names that have '('. for _, ind := range bracketRx.FindAllStringSubmatchIndex(funcName, -1) { foundReserved := false for _, res := range reservedNames { if funcName[ind[0]:ind[1]] == res { foundReserved = true break } } if !foundReserved { funcName = funcName[:ind[0]] break } } return funcName }
[ "func", "simplifyFunc", "(", "f", "string", ")", "string", "{", "// Account for leading '.' on the PPC ELF v1 ABI.", "funcName", ":=", "strings", ".", "TrimPrefix", "(", "f", ",", "\"", "\"", ")", "\n", "// Account for unsimplified names -- try to remove the argument list by trimming", "// starting from the first '(', but skipping reserved names that have '('.", "for", "_", ",", "ind", ":=", "range", "bracketRx", ".", "FindAllStringSubmatchIndex", "(", "funcName", ",", "-", "1", ")", "{", "foundReserved", ":=", "false", "\n", "for", "_", ",", "res", ":=", "range", "reservedNames", "{", "if", "funcName", "[", "ind", "[", "0", "]", ":", "ind", "[", "1", "]", "]", "==", "res", "{", "foundReserved", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "foundReserved", "{", "funcName", "=", "funcName", "[", ":", "ind", "[", "0", "]", "]", "\n", "break", "\n", "}", "\n", "}", "\n", "return", "funcName", "\n", "}" ]
// simplifyFunc does some primitive simplification of function names.
[ "simplifyFunc", "does", "some", "primitive", "simplification", "of", "function", "names", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/prune.go#L37-L56
train
google/pprof
profile/prune.go
RemoveUninteresting
func (p *Profile) RemoveUninteresting() error { var keep, drop *regexp.Regexp var err error if p.DropFrames != "" { if drop, err = regexp.Compile("^(" + p.DropFrames + ")$"); err != nil { return fmt.Errorf("failed to compile regexp %s: %v", p.DropFrames, err) } if p.KeepFrames != "" { if keep, err = regexp.Compile("^(" + p.KeepFrames + ")$"); err != nil { return fmt.Errorf("failed to compile regexp %s: %v", p.KeepFrames, err) } } p.Prune(drop, keep) } return nil }
go
func (p *Profile) RemoveUninteresting() error { var keep, drop *regexp.Regexp var err error if p.DropFrames != "" { if drop, err = regexp.Compile("^(" + p.DropFrames + ")$"); err != nil { return fmt.Errorf("failed to compile regexp %s: %v", p.DropFrames, err) } if p.KeepFrames != "" { if keep, err = regexp.Compile("^(" + p.KeepFrames + ")$"); err != nil { return fmt.Errorf("failed to compile regexp %s: %v", p.KeepFrames, err) } } p.Prune(drop, keep) } return nil }
[ "func", "(", "p", "*", "Profile", ")", "RemoveUninteresting", "(", ")", "error", "{", "var", "keep", ",", "drop", "*", "regexp", ".", "Regexp", "\n", "var", "err", "error", "\n\n", "if", "p", ".", "DropFrames", "!=", "\"", "\"", "{", "if", "drop", ",", "err", "=", "regexp", ".", "Compile", "(", "\"", "\"", "+", "p", ".", "DropFrames", "+", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "p", ".", "DropFrames", ",", "err", ")", "\n", "}", "\n", "if", "p", ".", "KeepFrames", "!=", "\"", "\"", "{", "if", "keep", ",", "err", "=", "regexp", ".", "Compile", "(", "\"", "\"", "+", "p", ".", "KeepFrames", "+", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "p", ".", "KeepFrames", ",", "err", ")", "\n", "}", "\n", "}", "\n", "p", ".", "Prune", "(", "drop", ",", "keep", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RemoveUninteresting prunes and elides profiles using built-in // tables of uninteresting function names.
[ "RemoveUninteresting", "prunes", "and", "elides", "profiles", "using", "built", "-", "in", "tables", "of", "uninteresting", "function", "names", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/prune.go#L121-L137
train
google/pprof
internal/driver/options.go
setDefaults
func setDefaults(o *plugin.Options) *plugin.Options { d := &plugin.Options{} if o != nil { *d = *o } if d.Writer == nil { d.Writer = oswriter{} } if d.Flagset == nil { d.Flagset = &GoFlags{} } if d.Obj == nil { d.Obj = &binutils.Binutils{} } if d.UI == nil { d.UI = &stdUI{r: bufio.NewReader(os.Stdin)} } if d.HTTPTransport == nil { d.HTTPTransport = transport.New(d.Flagset) } if d.Sym == nil { d.Sym = &symbolizer.Symbolizer{Obj: d.Obj, UI: d.UI, Transport: d.HTTPTransport} } return d }
go
func setDefaults(o *plugin.Options) *plugin.Options { d := &plugin.Options{} if o != nil { *d = *o } if d.Writer == nil { d.Writer = oswriter{} } if d.Flagset == nil { d.Flagset = &GoFlags{} } if d.Obj == nil { d.Obj = &binutils.Binutils{} } if d.UI == nil { d.UI = &stdUI{r: bufio.NewReader(os.Stdin)} } if d.HTTPTransport == nil { d.HTTPTransport = transport.New(d.Flagset) } if d.Sym == nil { d.Sym = &symbolizer.Symbolizer{Obj: d.Obj, UI: d.UI, Transport: d.HTTPTransport} } return d }
[ "func", "setDefaults", "(", "o", "*", "plugin", ".", "Options", ")", "*", "plugin", ".", "Options", "{", "d", ":=", "&", "plugin", ".", "Options", "{", "}", "\n", "if", "o", "!=", "nil", "{", "*", "d", "=", "*", "o", "\n", "}", "\n", "if", "d", ".", "Writer", "==", "nil", "{", "d", ".", "Writer", "=", "oswriter", "{", "}", "\n", "}", "\n", "if", "d", ".", "Flagset", "==", "nil", "{", "d", ".", "Flagset", "=", "&", "GoFlags", "{", "}", "\n", "}", "\n", "if", "d", ".", "Obj", "==", "nil", "{", "d", ".", "Obj", "=", "&", "binutils", ".", "Binutils", "{", "}", "\n", "}", "\n", "if", "d", ".", "UI", "==", "nil", "{", "d", ".", "UI", "=", "&", "stdUI", "{", "r", ":", "bufio", ".", "NewReader", "(", "os", ".", "Stdin", ")", "}", "\n", "}", "\n", "if", "d", ".", "HTTPTransport", "==", "nil", "{", "d", ".", "HTTPTransport", "=", "transport", ".", "New", "(", "d", ".", "Flagset", ")", "\n", "}", "\n", "if", "d", ".", "Sym", "==", "nil", "{", "d", ".", "Sym", "=", "&", "symbolizer", ".", "Symbolizer", "{", "Obj", ":", "d", ".", "Obj", ",", "UI", ":", "d", ".", "UI", ",", "Transport", ":", "d", ".", "HTTPTransport", "}", "\n", "}", "\n", "return", "d", "\n", "}" ]
// setDefaults returns a new plugin.Options with zero fields sets to // sensible defaults.
[ "setDefaults", "returns", "a", "new", "plugin", ".", "Options", "with", "zero", "fields", "sets", "to", "sensible", "defaults", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/options.go#L32-L56
train
google/pprof
internal/driver/interactive.go
interactive
func interactive(p *profile.Profile, o *plugin.Options) error { // Enter command processing loop. o.UI.SetAutoComplete(newCompleter(functionNames(p))) pprofVariables.set("compact_labels", "true") pprofVariables["sample_index"].help += fmt.Sprintf("Or use sample_index=name, with name in %v.\n", sampleTypes(p)) // Do not wait for the visualizer to complete, to allow multiple // graphs to be visualized simultaneously. interactiveMode = true shortcuts := profileShortcuts(p) // Get all groups in pprofVariables to allow for clearer error messages. groups := groupOptions(pprofVariables) greetings(p, o.UI) for { input, err := o.UI.ReadLine("(pprof) ") if err != nil { if err != io.EOF { return err } if input == "" { return nil } } for _, input := range shortcuts.expand(input) { // Process assignments of the form variable=value if s := strings.SplitN(input, "=", 2); len(s) > 0 { name := strings.TrimSpace(s[0]) var value string if len(s) == 2 { value = s[1] if comment := strings.LastIndex(value, commentStart); comment != -1 { value = value[:comment] } value = strings.TrimSpace(value) } if v := pprofVariables[name]; v != nil { if name == "sample_index" { // Error check sample_index=xxx to ensure xxx is a valid sample type. index, err := p.SampleIndexByName(value) if err != nil { o.UI.PrintErr(err) continue } value = p.SampleType[index].Type } if err := pprofVariables.set(name, value); err != nil { o.UI.PrintErr(err) } continue } // Allow group=variable syntax by converting into variable="". if v := pprofVariables[value]; v != nil && v.group == name { if err := pprofVariables.set(value, ""); err != nil { o.UI.PrintErr(err) } continue } else if okValues := groups[name]; okValues != nil { o.UI.PrintErr(fmt.Errorf("unrecognized value for %s: %q. Use one of %s", name, value, strings.Join(okValues, ", "))) continue } } tokens := strings.Fields(input) if len(tokens) == 0 { continue } switch tokens[0] { case "o", "options": printCurrentOptions(p, o.UI) continue case "exit", "quit": return nil case "help": commandHelp(strings.Join(tokens[1:], " "), o.UI) continue } args, vars, err := parseCommandLine(tokens) if err == nil { err = generateReportWrapper(p, args, vars, o) } if err != nil { o.UI.PrintErr(err) } } } }
go
func interactive(p *profile.Profile, o *plugin.Options) error { // Enter command processing loop. o.UI.SetAutoComplete(newCompleter(functionNames(p))) pprofVariables.set("compact_labels", "true") pprofVariables["sample_index"].help += fmt.Sprintf("Or use sample_index=name, with name in %v.\n", sampleTypes(p)) // Do not wait for the visualizer to complete, to allow multiple // graphs to be visualized simultaneously. interactiveMode = true shortcuts := profileShortcuts(p) // Get all groups in pprofVariables to allow for clearer error messages. groups := groupOptions(pprofVariables) greetings(p, o.UI) for { input, err := o.UI.ReadLine("(pprof) ") if err != nil { if err != io.EOF { return err } if input == "" { return nil } } for _, input := range shortcuts.expand(input) { // Process assignments of the form variable=value if s := strings.SplitN(input, "=", 2); len(s) > 0 { name := strings.TrimSpace(s[0]) var value string if len(s) == 2 { value = s[1] if comment := strings.LastIndex(value, commentStart); comment != -1 { value = value[:comment] } value = strings.TrimSpace(value) } if v := pprofVariables[name]; v != nil { if name == "sample_index" { // Error check sample_index=xxx to ensure xxx is a valid sample type. index, err := p.SampleIndexByName(value) if err != nil { o.UI.PrintErr(err) continue } value = p.SampleType[index].Type } if err := pprofVariables.set(name, value); err != nil { o.UI.PrintErr(err) } continue } // Allow group=variable syntax by converting into variable="". if v := pprofVariables[value]; v != nil && v.group == name { if err := pprofVariables.set(value, ""); err != nil { o.UI.PrintErr(err) } continue } else if okValues := groups[name]; okValues != nil { o.UI.PrintErr(fmt.Errorf("unrecognized value for %s: %q. Use one of %s", name, value, strings.Join(okValues, ", "))) continue } } tokens := strings.Fields(input) if len(tokens) == 0 { continue } switch tokens[0] { case "o", "options": printCurrentOptions(p, o.UI) continue case "exit", "quit": return nil case "help": commandHelp(strings.Join(tokens[1:], " "), o.UI) continue } args, vars, err := parseCommandLine(tokens) if err == nil { err = generateReportWrapper(p, args, vars, o) } if err != nil { o.UI.PrintErr(err) } } } }
[ "func", "interactive", "(", "p", "*", "profile", ".", "Profile", ",", "o", "*", "plugin", ".", "Options", ")", "error", "{", "// Enter command processing loop.", "o", ".", "UI", ".", "SetAutoComplete", "(", "newCompleter", "(", "functionNames", "(", "p", ")", ")", ")", "\n", "pprofVariables", ".", "set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "pprofVariables", "[", "\"", "\"", "]", ".", "help", "+=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "sampleTypes", "(", "p", ")", ")", "\n\n", "// Do not wait for the visualizer to complete, to allow multiple", "// graphs to be visualized simultaneously.", "interactiveMode", "=", "true", "\n", "shortcuts", ":=", "profileShortcuts", "(", "p", ")", "\n\n", "// Get all groups in pprofVariables to allow for clearer error messages.", "groups", ":=", "groupOptions", "(", "pprofVariables", ")", "\n\n", "greetings", "(", "p", ",", "o", ".", "UI", ")", "\n", "for", "{", "input", ",", "err", ":=", "o", ".", "UI", ".", "ReadLine", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "!=", "io", ".", "EOF", "{", "return", "err", "\n", "}", "\n", "if", "input", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "input", ":=", "range", "shortcuts", ".", "expand", "(", "input", ")", "{", "// Process assignments of the form variable=value", "if", "s", ":=", "strings", ".", "SplitN", "(", "input", ",", "\"", "\"", ",", "2", ")", ";", "len", "(", "s", ")", ">", "0", "{", "name", ":=", "strings", ".", "TrimSpace", "(", "s", "[", "0", "]", ")", "\n", "var", "value", "string", "\n", "if", "len", "(", "s", ")", "==", "2", "{", "value", "=", "s", "[", "1", "]", "\n", "if", "comment", ":=", "strings", ".", "LastIndex", "(", "value", ",", "commentStart", ")", ";", "comment", "!=", "-", "1", "{", "value", "=", "value", "[", ":", "comment", "]", "\n", "}", "\n", "value", "=", "strings", ".", "TrimSpace", "(", "value", ")", "\n", "}", "\n", "if", "v", ":=", "pprofVariables", "[", "name", "]", ";", "v", "!=", "nil", "{", "if", "name", "==", "\"", "\"", "{", "// Error check sample_index=xxx to ensure xxx is a valid sample type.", "index", ",", "err", ":=", "p", ".", "SampleIndexByName", "(", "value", ")", "\n", "if", "err", "!=", "nil", "{", "o", ".", "UI", ".", "PrintErr", "(", "err", ")", "\n", "continue", "\n", "}", "\n", "value", "=", "p", ".", "SampleType", "[", "index", "]", ".", "Type", "\n", "}", "\n", "if", "err", ":=", "pprofVariables", ".", "set", "(", "name", ",", "value", ")", ";", "err", "!=", "nil", "{", "o", ".", "UI", ".", "PrintErr", "(", "err", ")", "\n", "}", "\n", "continue", "\n", "}", "\n", "// Allow group=variable syntax by converting into variable=\"\".", "if", "v", ":=", "pprofVariables", "[", "value", "]", ";", "v", "!=", "nil", "&&", "v", ".", "group", "==", "name", "{", "if", "err", ":=", "pprofVariables", ".", "set", "(", "value", ",", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "o", ".", "UI", ".", "PrintErr", "(", "err", ")", "\n", "}", "\n", "continue", "\n", "}", "else", "if", "okValues", ":=", "groups", "[", "name", "]", ";", "okValues", "!=", "nil", "{", "o", ".", "UI", ".", "PrintErr", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ",", "value", ",", "strings", ".", "Join", "(", "okValues", ",", "\"", "\"", ")", ")", ")", "\n", "continue", "\n", "}", "\n", "}", "\n\n", "tokens", ":=", "strings", ".", "Fields", "(", "input", ")", "\n", "if", "len", "(", "tokens", ")", "==", "0", "{", "continue", "\n", "}", "\n\n", "switch", "tokens", "[", "0", "]", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "printCurrentOptions", "(", "p", ",", "o", ".", "UI", ")", "\n", "continue", "\n", "case", "\"", "\"", ",", "\"", "\"", ":", "return", "nil", "\n", "case", "\"", "\"", ":", "commandHelp", "(", "strings", ".", "Join", "(", "tokens", "[", "1", ":", "]", ",", "\"", "\"", ")", ",", "o", ".", "UI", ")", "\n", "continue", "\n", "}", "\n\n", "args", ",", "vars", ",", "err", ":=", "parseCommandLine", "(", "tokens", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "generateReportWrapper", "(", "p", ",", "args", ",", "vars", ",", "o", ")", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "o", ".", "UI", ".", "PrintErr", "(", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// interactive starts a shell to read pprof commands.
[ "interactive", "starts", "a", "shell", "to", "read", "pprof", "commands", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/interactive.go#L34-L125
train
google/pprof
internal/driver/interactive.go
groupOptions
func groupOptions(vars variables) map[string][]string { groups := make(map[string][]string) for name, option := range vars { group := option.group if group != "" { groups[group] = append(groups[group], name) } } for _, names := range groups { sort.Strings(names) } return groups }
go
func groupOptions(vars variables) map[string][]string { groups := make(map[string][]string) for name, option := range vars { group := option.group if group != "" { groups[group] = append(groups[group], name) } } for _, names := range groups { sort.Strings(names) } return groups }
[ "func", "groupOptions", "(", "vars", "variables", ")", "map", "[", "string", "]", "[", "]", "string", "{", "groups", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "for", "name", ",", "option", ":=", "range", "vars", "{", "group", ":=", "option", ".", "group", "\n", "if", "group", "!=", "\"", "\"", "{", "groups", "[", "group", "]", "=", "append", "(", "groups", "[", "group", "]", ",", "name", ")", "\n", "}", "\n", "}", "\n", "for", "_", ",", "names", ":=", "range", "groups", "{", "sort", ".", "Strings", "(", "names", ")", "\n", "}", "\n", "return", "groups", "\n", "}" ]
// groupOptions returns a map containing all non-empty groups // mapped to an array of the option names in that group in // sorted order.
[ "groupOptions", "returns", "a", "map", "containing", "all", "non", "-", "empty", "groups", "mapped", "to", "an", "array", "of", "the", "option", "names", "in", "that", "group", "in", "sorted", "order", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/interactive.go#L130-L142
train
google/pprof
internal/driver/interactive.go
greetings
func greetings(p *profile.Profile, ui plugin.UI) { numLabelUnits := identifyNumLabelUnits(p, ui) ropt, err := reportOptions(p, numLabelUnits, pprofVariables) if err == nil { rpt := report.New(p, ropt) ui.Print(strings.Join(report.ProfileLabels(rpt), "\n")) if rpt.Total() == 0 && len(p.SampleType) > 1 { ui.Print(`No samples were found with the default sample value type.`) ui.Print(`Try "sample_index" command to analyze different sample values.`, "\n") } } ui.Print(`Entering interactive mode (type "help" for commands, "o" for options)`) }
go
func greetings(p *profile.Profile, ui plugin.UI) { numLabelUnits := identifyNumLabelUnits(p, ui) ropt, err := reportOptions(p, numLabelUnits, pprofVariables) if err == nil { rpt := report.New(p, ropt) ui.Print(strings.Join(report.ProfileLabels(rpt), "\n")) if rpt.Total() == 0 && len(p.SampleType) > 1 { ui.Print(`No samples were found with the default sample value type.`) ui.Print(`Try "sample_index" command to analyze different sample values.`, "\n") } } ui.Print(`Entering interactive mode (type "help" for commands, "o" for options)`) }
[ "func", "greetings", "(", "p", "*", "profile", ".", "Profile", ",", "ui", "plugin", ".", "UI", ")", "{", "numLabelUnits", ":=", "identifyNumLabelUnits", "(", "p", ",", "ui", ")", "\n", "ropt", ",", "err", ":=", "reportOptions", "(", "p", ",", "numLabelUnits", ",", "pprofVariables", ")", "\n", "if", "err", "==", "nil", "{", "rpt", ":=", "report", ".", "New", "(", "p", ",", "ropt", ")", "\n", "ui", ".", "Print", "(", "strings", ".", "Join", "(", "report", ".", "ProfileLabels", "(", "rpt", ")", ",", "\"", "\\n", "\"", ")", ")", "\n", "if", "rpt", ".", "Total", "(", ")", "==", "0", "&&", "len", "(", "p", ".", "SampleType", ")", ">", "1", "{", "ui", ".", "Print", "(", "`No samples were found with the default sample value type.`", ")", "\n", "ui", ".", "Print", "(", "`Try \"sample_index\" command to analyze different sample values.`", ",", "\"", "\\n", "\"", ")", "\n", "}", "\n", "}", "\n", "ui", ".", "Print", "(", "`Entering interactive mode (type \"help\" for commands, \"o\" for options)`", ")", "\n", "}" ]
// greetings prints a brief welcome and some overall profile // information before accepting interactive commands.
[ "greetings", "prints", "a", "brief", "welcome", "and", "some", "overall", "profile", "information", "before", "accepting", "interactive", "commands", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/interactive.go#L148-L160
train
google/pprof
internal/driver/interactive.go
profileShortcuts
func profileShortcuts(p *profile.Profile) shortcuts { s := pprofShortcuts // Add shortcuts for sample types for _, st := range p.SampleType { command := fmt.Sprintf("sample_index=%s", st.Type) s[st.Type] = []string{command} s["total_"+st.Type] = []string{"mean=0", command} s["mean_"+st.Type] = []string{"mean=1", command} } return s }
go
func profileShortcuts(p *profile.Profile) shortcuts { s := pprofShortcuts // Add shortcuts for sample types for _, st := range p.SampleType { command := fmt.Sprintf("sample_index=%s", st.Type) s[st.Type] = []string{command} s["total_"+st.Type] = []string{"mean=0", command} s["mean_"+st.Type] = []string{"mean=1", command} } return s }
[ "func", "profileShortcuts", "(", "p", "*", "profile", ".", "Profile", ")", "shortcuts", "{", "s", ":=", "pprofShortcuts", "\n", "// Add shortcuts for sample types", "for", "_", ",", "st", ":=", "range", "p", ".", "SampleType", "{", "command", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "st", ".", "Type", ")", "\n", "s", "[", "st", ".", "Type", "]", "=", "[", "]", "string", "{", "command", "}", "\n", "s", "[", "\"", "\"", "+", "st", ".", "Type", "]", "=", "[", "]", "string", "{", "\"", "\"", ",", "command", "}", "\n", "s", "[", "\"", "\"", "+", "st", ".", "Type", "]", "=", "[", "]", "string", "{", "\"", "\"", ",", "command", "}", "\n", "}", "\n", "return", "s", "\n", "}" ]
// profileShortcuts creates macros for convenience and backward compatibility.
[ "profileShortcuts", "creates", "macros", "for", "convenience", "and", "backward", "compatibility", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/interactive.go#L181-L191
train
google/pprof
internal/driver/interactive.go
parseCommandLine
func parseCommandLine(input []string) ([]string, variables, error) { cmd, args := input[:1], input[1:] name := cmd[0] c := pprofCommands[name] if c == nil { // Attempt splitting digits on abbreviated commands (eg top10) if d := tailDigitsRE.FindString(name); d != "" && d != name { name = name[:len(name)-len(d)] cmd[0], args = name, append([]string{d}, args...) c = pprofCommands[name] } } if c == nil { return nil, nil, fmt.Errorf("unrecognized command: %q", name) } if c.hasParam { if len(args) == 0 { return nil, nil, fmt.Errorf("command %s requires an argument", name) } cmd = append(cmd, args[0]) args = args[1:] } // Copy the variables as options set in the command line are not persistent. vcopy := pprofVariables.makeCopy() var focus, ignore string for i := 0; i < len(args); i++ { t := args[i] if _, err := strconv.ParseInt(t, 10, 32); err == nil { vcopy.set("nodecount", t) continue } switch t[0] { case '>': outputFile := t[1:] if outputFile == "" { i++ if i >= len(args) { return nil, nil, fmt.Errorf("unexpected end of line after >") } outputFile = args[i] } vcopy.set("output", outputFile) case '-': if t == "--cum" || t == "-cum" { vcopy.set("cum", "t") continue } ignore = catRegex(ignore, t[1:]) default: focus = catRegex(focus, t) } } if name == "tags" { updateFocusIgnore(vcopy, "tag", focus, ignore) } else { updateFocusIgnore(vcopy, "", focus, ignore) } if vcopy["nodecount"].intValue() == -1 && (name == "text" || name == "top") { vcopy.set("nodecount", "10") } return cmd, vcopy, nil }
go
func parseCommandLine(input []string) ([]string, variables, error) { cmd, args := input[:1], input[1:] name := cmd[0] c := pprofCommands[name] if c == nil { // Attempt splitting digits on abbreviated commands (eg top10) if d := tailDigitsRE.FindString(name); d != "" && d != name { name = name[:len(name)-len(d)] cmd[0], args = name, append([]string{d}, args...) c = pprofCommands[name] } } if c == nil { return nil, nil, fmt.Errorf("unrecognized command: %q", name) } if c.hasParam { if len(args) == 0 { return nil, nil, fmt.Errorf("command %s requires an argument", name) } cmd = append(cmd, args[0]) args = args[1:] } // Copy the variables as options set in the command line are not persistent. vcopy := pprofVariables.makeCopy() var focus, ignore string for i := 0; i < len(args); i++ { t := args[i] if _, err := strconv.ParseInt(t, 10, 32); err == nil { vcopy.set("nodecount", t) continue } switch t[0] { case '>': outputFile := t[1:] if outputFile == "" { i++ if i >= len(args) { return nil, nil, fmt.Errorf("unexpected end of line after >") } outputFile = args[i] } vcopy.set("output", outputFile) case '-': if t == "--cum" || t == "-cum" { vcopy.set("cum", "t") continue } ignore = catRegex(ignore, t[1:]) default: focus = catRegex(focus, t) } } if name == "tags" { updateFocusIgnore(vcopy, "tag", focus, ignore) } else { updateFocusIgnore(vcopy, "", focus, ignore) } if vcopy["nodecount"].intValue() == -1 && (name == "text" || name == "top") { vcopy.set("nodecount", "10") } return cmd, vcopy, nil }
[ "func", "parseCommandLine", "(", "input", "[", "]", "string", ")", "(", "[", "]", "string", ",", "variables", ",", "error", ")", "{", "cmd", ",", "args", ":=", "input", "[", ":", "1", "]", ",", "input", "[", "1", ":", "]", "\n", "name", ":=", "cmd", "[", "0", "]", "\n\n", "c", ":=", "pprofCommands", "[", "name", "]", "\n", "if", "c", "==", "nil", "{", "// Attempt splitting digits on abbreviated commands (eg top10)", "if", "d", ":=", "tailDigitsRE", ".", "FindString", "(", "name", ")", ";", "d", "!=", "\"", "\"", "&&", "d", "!=", "name", "{", "name", "=", "name", "[", ":", "len", "(", "name", ")", "-", "len", "(", "d", ")", "]", "\n", "cmd", "[", "0", "]", ",", "args", "=", "name", ",", "append", "(", "[", "]", "string", "{", "d", "}", ",", "args", "...", ")", "\n", "c", "=", "pprofCommands", "[", "name", "]", "\n", "}", "\n", "}", "\n", "if", "c", "==", "nil", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n\n", "if", "c", ".", "hasParam", "{", "if", "len", "(", "args", ")", "==", "0", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "cmd", "=", "append", "(", "cmd", ",", "args", "[", "0", "]", ")", "\n", "args", "=", "args", "[", "1", ":", "]", "\n", "}", "\n\n", "// Copy the variables as options set in the command line are not persistent.", "vcopy", ":=", "pprofVariables", ".", "makeCopy", "(", ")", "\n\n", "var", "focus", ",", "ignore", "string", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "args", ")", ";", "i", "++", "{", "t", ":=", "args", "[", "i", "]", "\n", "if", "_", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "t", ",", "10", ",", "32", ")", ";", "err", "==", "nil", "{", "vcopy", ".", "set", "(", "\"", "\"", ",", "t", ")", "\n", "continue", "\n", "}", "\n", "switch", "t", "[", "0", "]", "{", "case", "'>'", ":", "outputFile", ":=", "t", "[", "1", ":", "]", "\n", "if", "outputFile", "==", "\"", "\"", "{", "i", "++", "\n", "if", "i", ">=", "len", "(", "args", ")", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "outputFile", "=", "args", "[", "i", "]", "\n", "}", "\n", "vcopy", ".", "set", "(", "\"", "\"", ",", "outputFile", ")", "\n", "case", "'-'", ":", "if", "t", "==", "\"", "\"", "||", "t", "==", "\"", "\"", "{", "vcopy", ".", "set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "continue", "\n", "}", "\n", "ignore", "=", "catRegex", "(", "ignore", ",", "t", "[", "1", ":", "]", ")", "\n", "default", ":", "focus", "=", "catRegex", "(", "focus", ",", "t", ")", "\n", "}", "\n", "}", "\n\n", "if", "name", "==", "\"", "\"", "{", "updateFocusIgnore", "(", "vcopy", ",", "\"", "\"", ",", "focus", ",", "ignore", ")", "\n", "}", "else", "{", "updateFocusIgnore", "(", "vcopy", ",", "\"", "\"", ",", "focus", ",", "ignore", ")", "\n", "}", "\n\n", "if", "vcopy", "[", "\"", "\"", "]", ".", "intValue", "(", ")", "==", "-", "1", "&&", "(", "name", "==", "\"", "\"", "||", "name", "==", "\"", "\"", ")", "{", "vcopy", ".", "set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "cmd", ",", "vcopy", ",", "nil", "\n", "}" ]
// parseCommandLine parses a command and returns the pprof command to // execute and a set of variables for the report.
[ "parseCommandLine", "parses", "a", "command", "and", "returns", "the", "pprof", "command", "to", "execute", "and", "a", "set", "of", "variables", "for", "the", "report", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/interactive.go#L256-L324
train
google/pprof
internal/driver/interactive.go
commandHelp
func commandHelp(args string, ui plugin.UI) { if args == "" { help := usage(false) help = help + ` : Clear focus/ignore/hide/tagfocus/tagignore type "help <cmd|option>" for more information ` ui.Print(help) return } if c := pprofCommands[args]; c != nil { ui.Print(c.help(args)) return } if v := pprofVariables[args]; v != nil { ui.Print(v.help + "\n") return } ui.PrintErr("Unknown command: " + args) }
go
func commandHelp(args string, ui plugin.UI) { if args == "" { help := usage(false) help = help + ` : Clear focus/ignore/hide/tagfocus/tagignore type "help <cmd|option>" for more information ` ui.Print(help) return } if c := pprofCommands[args]; c != nil { ui.Print(c.help(args)) return } if v := pprofVariables[args]; v != nil { ui.Print(v.help + "\n") return } ui.PrintErr("Unknown command: " + args) }
[ "func", "commandHelp", "(", "args", "string", ",", "ui", "plugin", ".", "UI", ")", "{", "if", "args", "==", "\"", "\"", "{", "help", ":=", "usage", "(", "false", ")", "\n", "help", "=", "help", "+", "`\n : Clear focus/ignore/hide/tagfocus/tagignore\n\n type \"help <cmd|option>\" for more information\n`", "\n\n", "ui", ".", "Print", "(", "help", ")", "\n", "return", "\n", "}", "\n\n", "if", "c", ":=", "pprofCommands", "[", "args", "]", ";", "c", "!=", "nil", "{", "ui", ".", "Print", "(", "c", ".", "help", "(", "args", ")", ")", "\n", "return", "\n", "}", "\n\n", "if", "v", ":=", "pprofVariables", "[", "args", "]", ";", "v", "!=", "nil", "{", "ui", ".", "Print", "(", "v", ".", "help", "+", "\"", "\\n", "\"", ")", "\n", "return", "\n", "}", "\n\n", "ui", ".", "PrintErr", "(", "\"", "\"", "+", "args", ")", "\n", "}" ]
// commandHelp displays help and usage information for all Commands // and Variables or a specific Command or Variable.
[ "commandHelp", "displays", "help", "and", "usage", "information", "for", "all", "Commands", "and", "Variables", "or", "a", "specific", "Command", "or", "Variable", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/interactive.go#L347-L371
train
google/pprof
internal/driver/interactive.go
newCompleter
func newCompleter(fns []string) func(string) string { return func(line string) string { v := pprofVariables switch tokens := strings.Fields(line); len(tokens) { case 0: // Nothing to complete case 1: // Single token -- complete command name if match := matchVariableOrCommand(v, tokens[0]); match != "" { return match } case 2: if tokens[0] == "help" { if match := matchVariableOrCommand(v, tokens[1]); match != "" { return tokens[0] + " " + match } return line } fallthrough default: // Multiple tokens -- complete using functions, except for tags if cmd := pprofCommands[tokens[0]]; cmd != nil && tokens[0] != "tags" { lastTokenIdx := len(tokens) - 1 lastToken := tokens[lastTokenIdx] if strings.HasPrefix(lastToken, "-") { lastToken = "-" + functionCompleter(lastToken[1:], fns) } else { lastToken = functionCompleter(lastToken, fns) } return strings.Join(append(tokens[:lastTokenIdx], lastToken), " ") } } return line } }
go
func newCompleter(fns []string) func(string) string { return func(line string) string { v := pprofVariables switch tokens := strings.Fields(line); len(tokens) { case 0: // Nothing to complete case 1: // Single token -- complete command name if match := matchVariableOrCommand(v, tokens[0]); match != "" { return match } case 2: if tokens[0] == "help" { if match := matchVariableOrCommand(v, tokens[1]); match != "" { return tokens[0] + " " + match } return line } fallthrough default: // Multiple tokens -- complete using functions, except for tags if cmd := pprofCommands[tokens[0]]; cmd != nil && tokens[0] != "tags" { lastTokenIdx := len(tokens) - 1 lastToken := tokens[lastTokenIdx] if strings.HasPrefix(lastToken, "-") { lastToken = "-" + functionCompleter(lastToken[1:], fns) } else { lastToken = functionCompleter(lastToken, fns) } return strings.Join(append(tokens[:lastTokenIdx], lastToken), " ") } } return line } }
[ "func", "newCompleter", "(", "fns", "[", "]", "string", ")", "func", "(", "string", ")", "string", "{", "return", "func", "(", "line", "string", ")", "string", "{", "v", ":=", "pprofVariables", "\n", "switch", "tokens", ":=", "strings", ".", "Fields", "(", "line", ")", ";", "len", "(", "tokens", ")", "{", "case", "0", ":", "// Nothing to complete", "case", "1", ":", "// Single token -- complete command name", "if", "match", ":=", "matchVariableOrCommand", "(", "v", ",", "tokens", "[", "0", "]", ")", ";", "match", "!=", "\"", "\"", "{", "return", "match", "\n", "}", "\n", "case", "2", ":", "if", "tokens", "[", "0", "]", "==", "\"", "\"", "{", "if", "match", ":=", "matchVariableOrCommand", "(", "v", ",", "tokens", "[", "1", "]", ")", ";", "match", "!=", "\"", "\"", "{", "return", "tokens", "[", "0", "]", "+", "\"", "\"", "+", "match", "\n", "}", "\n", "return", "line", "\n", "}", "\n", "fallthrough", "\n", "default", ":", "// Multiple tokens -- complete using functions, except for tags", "if", "cmd", ":=", "pprofCommands", "[", "tokens", "[", "0", "]", "]", ";", "cmd", "!=", "nil", "&&", "tokens", "[", "0", "]", "!=", "\"", "\"", "{", "lastTokenIdx", ":=", "len", "(", "tokens", ")", "-", "1", "\n", "lastToken", ":=", "tokens", "[", "lastTokenIdx", "]", "\n", "if", "strings", ".", "HasPrefix", "(", "lastToken", ",", "\"", "\"", ")", "{", "lastToken", "=", "\"", "\"", "+", "functionCompleter", "(", "lastToken", "[", "1", ":", "]", ",", "fns", ")", "\n", "}", "else", "{", "lastToken", "=", "functionCompleter", "(", "lastToken", ",", "fns", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "append", "(", "tokens", "[", ":", "lastTokenIdx", "]", ",", "lastToken", ")", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "return", "line", "\n", "}", "\n", "}" ]
// newCompleter creates an autocompletion function for a set of commands.
[ "newCompleter", "creates", "an", "autocompletion", "function", "for", "a", "set", "of", "commands", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/interactive.go#L374-L408
train
google/pprof
internal/driver/interactive.go
matchVariableOrCommand
func matchVariableOrCommand(v variables, token string) string { token = strings.ToLower(token) found := "" for cmd := range pprofCommands { if strings.HasPrefix(cmd, token) { if found != "" { return "" } found = cmd } } for variable := range v { if strings.HasPrefix(variable, token) { if found != "" { return "" } found = variable } } return found }
go
func matchVariableOrCommand(v variables, token string) string { token = strings.ToLower(token) found := "" for cmd := range pprofCommands { if strings.HasPrefix(cmd, token) { if found != "" { return "" } found = cmd } } for variable := range v { if strings.HasPrefix(variable, token) { if found != "" { return "" } found = variable } } return found }
[ "func", "matchVariableOrCommand", "(", "v", "variables", ",", "token", "string", ")", "string", "{", "token", "=", "strings", ".", "ToLower", "(", "token", ")", "\n", "found", ":=", "\"", "\"", "\n", "for", "cmd", ":=", "range", "pprofCommands", "{", "if", "strings", ".", "HasPrefix", "(", "cmd", ",", "token", ")", "{", "if", "found", "!=", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n", "found", "=", "cmd", "\n", "}", "\n", "}", "\n", "for", "variable", ":=", "range", "v", "{", "if", "strings", ".", "HasPrefix", "(", "variable", ",", "token", ")", "{", "if", "found", "!=", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n", "found", "=", "variable", "\n", "}", "\n", "}", "\n", "return", "found", "\n", "}" ]
// matchVariableOrCommand attempts to match a string token to the prefix of a Command.
[ "matchVariableOrCommand", "attempts", "to", "match", "a", "string", "token", "to", "the", "prefix", "of", "a", "Command", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/interactive.go#L411-L431
train
google/pprof
internal/measurement/measurement.go
ScaleProfiles
func ScaleProfiles(profiles []*profile.Profile) error { if len(profiles) == 0 { return nil } periodTypes := make([]*profile.ValueType, 0, len(profiles)) for _, p := range profiles { if p.PeriodType != nil { periodTypes = append(periodTypes, p.PeriodType) } } periodType, err := CommonValueType(periodTypes) if err != nil { return fmt.Errorf("period type: %v", err) } // Identify common sample types numSampleTypes := len(profiles[0].SampleType) for _, p := range profiles[1:] { if numSampleTypes != len(p.SampleType) { return fmt.Errorf("inconsistent samples type count: %d != %d", numSampleTypes, len(p.SampleType)) } } sampleType := make([]*profile.ValueType, numSampleTypes) for i := 0; i < numSampleTypes; i++ { sampleTypes := make([]*profile.ValueType, len(profiles)) for j, p := range profiles { sampleTypes[j] = p.SampleType[i] } sampleType[i], err = CommonValueType(sampleTypes) if err != nil { return fmt.Errorf("sample types: %v", err) } } for _, p := range profiles { if p.PeriodType != nil && periodType != nil { period, _ := Scale(p.Period, p.PeriodType.Unit, periodType.Unit) p.Period, p.PeriodType.Unit = int64(period), periodType.Unit } ratios := make([]float64, len(p.SampleType)) for i, st := range p.SampleType { if sampleType[i] == nil { ratios[i] = 1 continue } ratios[i], _ = Scale(1, st.Unit, sampleType[i].Unit) p.SampleType[i].Unit = sampleType[i].Unit } if err := p.ScaleN(ratios); err != nil { return fmt.Errorf("scale: %v", err) } } return nil }
go
func ScaleProfiles(profiles []*profile.Profile) error { if len(profiles) == 0 { return nil } periodTypes := make([]*profile.ValueType, 0, len(profiles)) for _, p := range profiles { if p.PeriodType != nil { periodTypes = append(periodTypes, p.PeriodType) } } periodType, err := CommonValueType(periodTypes) if err != nil { return fmt.Errorf("period type: %v", err) } // Identify common sample types numSampleTypes := len(profiles[0].SampleType) for _, p := range profiles[1:] { if numSampleTypes != len(p.SampleType) { return fmt.Errorf("inconsistent samples type count: %d != %d", numSampleTypes, len(p.SampleType)) } } sampleType := make([]*profile.ValueType, numSampleTypes) for i := 0; i < numSampleTypes; i++ { sampleTypes := make([]*profile.ValueType, len(profiles)) for j, p := range profiles { sampleTypes[j] = p.SampleType[i] } sampleType[i], err = CommonValueType(sampleTypes) if err != nil { return fmt.Errorf("sample types: %v", err) } } for _, p := range profiles { if p.PeriodType != nil && periodType != nil { period, _ := Scale(p.Period, p.PeriodType.Unit, periodType.Unit) p.Period, p.PeriodType.Unit = int64(period), periodType.Unit } ratios := make([]float64, len(p.SampleType)) for i, st := range p.SampleType { if sampleType[i] == nil { ratios[i] = 1 continue } ratios[i], _ = Scale(1, st.Unit, sampleType[i].Unit) p.SampleType[i].Unit = sampleType[i].Unit } if err := p.ScaleN(ratios); err != nil { return fmt.Errorf("scale: %v", err) } } return nil }
[ "func", "ScaleProfiles", "(", "profiles", "[", "]", "*", "profile", ".", "Profile", ")", "error", "{", "if", "len", "(", "profiles", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "periodTypes", ":=", "make", "(", "[", "]", "*", "profile", ".", "ValueType", ",", "0", ",", "len", "(", "profiles", ")", ")", "\n", "for", "_", ",", "p", ":=", "range", "profiles", "{", "if", "p", ".", "PeriodType", "!=", "nil", "{", "periodTypes", "=", "append", "(", "periodTypes", ",", "p", ".", "PeriodType", ")", "\n", "}", "\n", "}", "\n", "periodType", ",", "err", ":=", "CommonValueType", "(", "periodTypes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Identify common sample types", "numSampleTypes", ":=", "len", "(", "profiles", "[", "0", "]", ".", "SampleType", ")", "\n", "for", "_", ",", "p", ":=", "range", "profiles", "[", "1", ":", "]", "{", "if", "numSampleTypes", "!=", "len", "(", "p", ".", "SampleType", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "numSampleTypes", ",", "len", "(", "p", ".", "SampleType", ")", ")", "\n", "}", "\n", "}", "\n", "sampleType", ":=", "make", "(", "[", "]", "*", "profile", ".", "ValueType", ",", "numSampleTypes", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "numSampleTypes", ";", "i", "++", "{", "sampleTypes", ":=", "make", "(", "[", "]", "*", "profile", ".", "ValueType", ",", "len", "(", "profiles", ")", ")", "\n", "for", "j", ",", "p", ":=", "range", "profiles", "{", "sampleTypes", "[", "j", "]", "=", "p", ".", "SampleType", "[", "i", "]", "\n", "}", "\n", "sampleType", "[", "i", "]", ",", "err", "=", "CommonValueType", "(", "sampleTypes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "p", ":=", "range", "profiles", "{", "if", "p", ".", "PeriodType", "!=", "nil", "&&", "periodType", "!=", "nil", "{", "period", ",", "_", ":=", "Scale", "(", "p", ".", "Period", ",", "p", ".", "PeriodType", ".", "Unit", ",", "periodType", ".", "Unit", ")", "\n", "p", ".", "Period", ",", "p", ".", "PeriodType", ".", "Unit", "=", "int64", "(", "period", ")", ",", "periodType", ".", "Unit", "\n", "}", "\n", "ratios", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "p", ".", "SampleType", ")", ")", "\n", "for", "i", ",", "st", ":=", "range", "p", ".", "SampleType", "{", "if", "sampleType", "[", "i", "]", "==", "nil", "{", "ratios", "[", "i", "]", "=", "1", "\n", "continue", "\n", "}", "\n", "ratios", "[", "i", "]", ",", "_", "=", "Scale", "(", "1", ",", "st", ".", "Unit", ",", "sampleType", "[", "i", "]", ".", "Unit", ")", "\n", "p", ".", "SampleType", "[", "i", "]", ".", "Unit", "=", "sampleType", "[", "i", "]", ".", "Unit", "\n", "}", "\n", "if", "err", ":=", "p", ".", "ScaleN", "(", "ratios", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ScaleProfiles updates the units in a set of profiles to make them // compatible. It scales the profiles to the smallest unit to preserve // data.
[ "ScaleProfiles", "updates", "the", "units", "in", "a", "set", "of", "profiles", "to", "make", "them", "compatible", ".", "It", "scales", "the", "profiles", "to", "the", "smallest", "unit", "to", "preserve", "data", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/measurement/measurement.go#L30-L83
train
google/pprof
internal/measurement/measurement.go
CommonValueType
func CommonValueType(ts []*profile.ValueType) (*profile.ValueType, error) { if len(ts) <= 1 { return nil, nil } minType := ts[0] for _, t := range ts[1:] { if !compatibleValueTypes(minType, t) { return nil, fmt.Errorf("incompatible types: %v %v", *minType, *t) } if ratio, _ := Scale(1, t.Unit, minType.Unit); ratio < 1 { minType = t } } rcopy := *minType return &rcopy, nil }
go
func CommonValueType(ts []*profile.ValueType) (*profile.ValueType, error) { if len(ts) <= 1 { return nil, nil } minType := ts[0] for _, t := range ts[1:] { if !compatibleValueTypes(minType, t) { return nil, fmt.Errorf("incompatible types: %v %v", *minType, *t) } if ratio, _ := Scale(1, t.Unit, minType.Unit); ratio < 1 { minType = t } } rcopy := *minType return &rcopy, nil }
[ "func", "CommonValueType", "(", "ts", "[", "]", "*", "profile", ".", "ValueType", ")", "(", "*", "profile", ".", "ValueType", ",", "error", ")", "{", "if", "len", "(", "ts", ")", "<=", "1", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "minType", ":=", "ts", "[", "0", "]", "\n", "for", "_", ",", "t", ":=", "range", "ts", "[", "1", ":", "]", "{", "if", "!", "compatibleValueTypes", "(", "minType", ",", "t", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "*", "minType", ",", "*", "t", ")", "\n", "}", "\n", "if", "ratio", ",", "_", ":=", "Scale", "(", "1", ",", "t", ".", "Unit", ",", "minType", ".", "Unit", ")", ";", "ratio", "<", "1", "{", "minType", "=", "t", "\n", "}", "\n", "}", "\n", "rcopy", ":=", "*", "minType", "\n", "return", "&", "rcopy", ",", "nil", "\n", "}" ]
// CommonValueType returns the finest type from a set of compatible // types.
[ "CommonValueType", "returns", "the", "finest", "type", "from", "a", "set", "of", "compatible", "types", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/measurement/measurement.go#L87-L102
train
google/pprof
internal/measurement/measurement.go
Percentage
func Percentage(value, total int64) string { var ratio float64 if total != 0 { ratio = math.Abs(float64(value)/float64(total)) * 100 } switch { case math.Abs(ratio) >= 99.95 && math.Abs(ratio) <= 100.05: return " 100%" case math.Abs(ratio) >= 1.0: return fmt.Sprintf("%5.2f%%", ratio) default: return fmt.Sprintf("%5.2g%%", ratio) } }
go
func Percentage(value, total int64) string { var ratio float64 if total != 0 { ratio = math.Abs(float64(value)/float64(total)) * 100 } switch { case math.Abs(ratio) >= 99.95 && math.Abs(ratio) <= 100.05: return " 100%" case math.Abs(ratio) >= 1.0: return fmt.Sprintf("%5.2f%%", ratio) default: return fmt.Sprintf("%5.2g%%", ratio) } }
[ "func", "Percentage", "(", "value", ",", "total", "int64", ")", "string", "{", "var", "ratio", "float64", "\n", "if", "total", "!=", "0", "{", "ratio", "=", "math", ".", "Abs", "(", "float64", "(", "value", ")", "/", "float64", "(", "total", ")", ")", "*", "100", "\n", "}", "\n", "switch", "{", "case", "math", ".", "Abs", "(", "ratio", ")", ">=", "99.95", "&&", "math", ".", "Abs", "(", "ratio", ")", "<=", "100.05", ":", "return", "\"", "\"", "\n", "case", "math", ".", "Abs", "(", "ratio", ")", ">=", "1.0", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ratio", ")", "\n", "default", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ratio", ")", "\n", "}", "\n", "}" ]
// Percentage computes the percentage of total of a value, and encodes // it as a string. At least two digits of precision are printed.
[ "Percentage", "computes", "the", "percentage", "of", "total", "of", "a", "value", "and", "encodes", "it", "as", "a", "string", ".", "At", "least", "two", "digits", "of", "precision", "are", "printed", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/measurement/measurement.go#L160-L173
train
google/pprof
internal/measurement/measurement.go
isMemoryUnit
func isMemoryUnit(unit string) bool { switch strings.TrimSuffix(strings.ToLower(unit), "s") { case "byte", "b", "kilobyte", "kb", "megabyte", "mb", "gigabyte", "gb": return true } return false }
go
func isMemoryUnit(unit string) bool { switch strings.TrimSuffix(strings.ToLower(unit), "s") { case "byte", "b", "kilobyte", "kb", "megabyte", "mb", "gigabyte", "gb": return true } return false }
[ "func", "isMemoryUnit", "(", "unit", "string", ")", "bool", "{", "switch", "strings", ".", "TrimSuffix", "(", "strings", ".", "ToLower", "(", "unit", ")", ",", "\"", "\"", ")", "{", "case", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ":", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// isMemoryUnit returns whether a name is recognized as a memory size // unit.
[ "isMemoryUnit", "returns", "whether", "a", "name", "is", "recognized", "as", "a", "memory", "size", "unit", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/measurement/measurement.go#L177-L183
train
google/pprof
internal/measurement/measurement.go
isTimeUnit
func isTimeUnit(unit string) bool { unit = strings.ToLower(unit) if len(unit) > 2 { unit = strings.TrimSuffix(unit, "s") } switch unit { case "nanosecond", "ns", "microsecond", "millisecond", "ms", "s", "second", "sec", "hr", "day", "week", "year": return true } return false }
go
func isTimeUnit(unit string) bool { unit = strings.ToLower(unit) if len(unit) > 2 { unit = strings.TrimSuffix(unit, "s") } switch unit { case "nanosecond", "ns", "microsecond", "millisecond", "ms", "s", "second", "sec", "hr", "day", "week", "year": return true } return false }
[ "func", "isTimeUnit", "(", "unit", "string", ")", "bool", "{", "unit", "=", "strings", ".", "ToLower", "(", "unit", ")", "\n", "if", "len", "(", "unit", ")", ">", "2", "{", "unit", "=", "strings", ".", "TrimSuffix", "(", "unit", ",", "\"", "\"", ")", "\n", "}", "\n\n", "switch", "unit", "{", "case", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ":", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// isTimeUnit returns whether a name is recognized as a time unit.
[ "isTimeUnit", "returns", "whether", "a", "name", "is", "recognized", "as", "a", "time", "unit", "." ]
8358a9778bd1e48718ffcb96eb11ee061385bf62
https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/measurement/measurement.go#L241-L252
train
kubernetes-retired/contrib
scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/writerc.go
yaml_emitter_set_writer_error
func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { emitter.error = yaml_WRITER_ERROR emitter.problem = problem return false }
go
func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { emitter.error = yaml_WRITER_ERROR emitter.problem = problem return false }
[ "func", "yaml_emitter_set_writer_error", "(", "emitter", "*", "yaml_emitter_t", ",", "problem", "string", ")", "bool", "{", "emitter", ".", "error", "=", "yaml_WRITER_ERROR", "\n", "emitter", ".", "problem", "=", "problem", "\n", "return", "false", "\n", "}" ]
// Set the writer error and return false.
[ "Set", "the", "writer", "error", "and", "return", "false", "." ]
89f6948e24578fed2a90a87871b2263729f90ac3
https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/writerc.go#L4-L8
train
kubernetes-retired/contrib
service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/podsecuritypolicy.go
List
func (s *podSecurityPolicy) List(opts api.ListOptions) (*extensions.PodSecurityPolicyList, error) { result := &extensions.PodSecurityPolicyList{} err := s.client.Get(). Resource("podsecuritypolicies"). VersionedParams(&opts, api.ParameterCodec). Do(). Into(result) return result, err }
go
func (s *podSecurityPolicy) List(opts api.ListOptions) (*extensions.PodSecurityPolicyList, error) { result := &extensions.PodSecurityPolicyList{} err := s.client.Get(). Resource("podsecuritypolicies"). VersionedParams(&opts, api.ParameterCodec). Do(). Into(result) return result, err }
[ "func", "(", "s", "*", "podSecurityPolicy", ")", "List", "(", "opts", "api", ".", "ListOptions", ")", "(", "*", "extensions", ".", "PodSecurityPolicyList", ",", "error", ")", "{", "result", ":=", "&", "extensions", ".", "PodSecurityPolicyList", "{", "}", "\n\n", "err", ":=", "s", ".", "client", ".", "Get", "(", ")", ".", "Resource", "(", "\"", "\"", ")", ".", "VersionedParams", "(", "&", "opts", ",", "api", ".", "ParameterCodec", ")", ".", "Do", "(", ")", ".", "Into", "(", "result", ")", "\n\n", "return", "result", ",", "err", "\n", "}" ]
// List returns a list of PodSecurityPolicies matching the selectors.
[ "List", "returns", "a", "list", "of", "PodSecurityPolicies", "matching", "the", "selectors", "." ]
89f6948e24578fed2a90a87871b2263729f90ac3
https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/podsecuritypolicy.go#L60-L70
train
kubernetes-retired/contrib
service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/podsecuritypolicy.go
Get
func (s *podSecurityPolicy) Get(name string) (*extensions.PodSecurityPolicy, error) { result := &extensions.PodSecurityPolicy{} err := s.client.Get(). Resource("podsecuritypolicies"). Name(name). Do(). Into(result) return result, err }
go
func (s *podSecurityPolicy) Get(name string) (*extensions.PodSecurityPolicy, error) { result := &extensions.PodSecurityPolicy{} err := s.client.Get(). Resource("podsecuritypolicies"). Name(name). Do(). Into(result) return result, err }
[ "func", "(", "s", "*", "podSecurityPolicy", ")", "Get", "(", "name", "string", ")", "(", "*", "extensions", ".", "PodSecurityPolicy", ",", "error", ")", "{", "result", ":=", "&", "extensions", ".", "PodSecurityPolicy", "{", "}", "\n", "err", ":=", "s", ".", "client", ".", "Get", "(", ")", ".", "Resource", "(", "\"", "\"", ")", ".", "Name", "(", "name", ")", ".", "Do", "(", ")", ".", "Into", "(", "result", ")", "\n\n", "return", "result", ",", "err", "\n", "}" ]
// Get returns the given PodSecurityPolicy, or an error.
[ "Get", "returns", "the", "given", "PodSecurityPolicy", "or", "an", "error", "." ]
89f6948e24578fed2a90a87871b2263729f90ac3
https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/podsecuritypolicy.go#L73-L82
train
kubernetes-retired/contrib
service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/podsecuritypolicy.go
Watch
func (s *podSecurityPolicy) Watch(opts api.ListOptions) (watch.Interface, error) { return s.client.Get(). Prefix("watch"). Resource("podsecuritypolicies"). VersionedParams(&opts, api.ParameterCodec). Watch() }
go
func (s *podSecurityPolicy) Watch(opts api.ListOptions) (watch.Interface, error) { return s.client.Get(). Prefix("watch"). Resource("podsecuritypolicies"). VersionedParams(&opts, api.ParameterCodec). Watch() }
[ "func", "(", "s", "*", "podSecurityPolicy", ")", "Watch", "(", "opts", "api", ".", "ListOptions", ")", "(", "watch", ".", "Interface", ",", "error", ")", "{", "return", "s", ".", "client", ".", "Get", "(", ")", ".", "Prefix", "(", "\"", "\"", ")", ".", "Resource", "(", "\"", "\"", ")", ".", "VersionedParams", "(", "&", "opts", ",", "api", ".", "ParameterCodec", ")", ".", "Watch", "(", ")", "\n", "}" ]
// Watch starts watching for PodSecurityPolicies matching the given selectors.
[ "Watch", "starts", "watching", "for", "PodSecurityPolicies", "matching", "the", "given", "selectors", "." ]
89f6948e24578fed2a90a87871b2263729f90ac3
https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/podsecuritypolicy.go#L85-L91
train