id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
165,000 | 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",
",",
"demangl... | // 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 |
165,001 | 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",
... | // 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 |
165,002 | 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",
":=",
"ob... | // 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 |
165,003 | 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",
".",
... | // 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",
"dema... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/symbolizer/symbolizer.go#L198-L244 |
165,004 | 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",
"st... | // 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 |
165,005 | 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",
... | // 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 |
165,006 | 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",
"\"",
... | // 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 |
165,007 | 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",
... | // 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",
"com... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/commands.go#L66-L68 |
165,008 | 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 |
165,009 | 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... | // 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 |
165,010 | 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",
"... | // 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 |
165,011 | 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"... | // 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 |
165,012 | 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... | // 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 |
165,013 | 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",
"+",
"\"",
... | // 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 |
165,014 | 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",
"+",
... | // 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 |
165,015 | 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"... | // 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 |
165,016 | 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",
":",
"retu... | // 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 |
165,017 | 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",
"... | // 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 |
165,018 | 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",
".",
"Prof... | // 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",
... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L169-L203 |
165,019 | 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",
".",
"P... | // concurrentGrab fetches multiple profiles concurrently | [
"concurrentGrab",
"fetches",
"multiple",
"profiles",
"concurrently"
] | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L206-L241 |
165,020 | 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",
"*",
"prof... | // 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 |
165,021 | 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",
".",
"... | // 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 |
165,022 | 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",
"... | // 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 |
165,023 | 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",
"("... | // 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 |
165,024 | 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... | // 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",
"profil... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L463-L483 |
165,025 | 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",
":",
... | // 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 |
165,026 | 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",
... | // 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 |
165,027 | 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",
"pro... | // 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",
"da... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L535-L551 |
165,028 | 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",
"... | // 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",
... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/fetch.go#L556-L587 |
165,029 | 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",
"re... | // 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",... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/transport/transport.go#L49-L59 |
165,030 | 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",
... | // 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 |
165,031 | 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",
".",
"J... | // 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 |
165,032 | 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",
".",
"U... | // 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 |
165,033 | 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... | // 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",
... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/report/source.go#L427-L483 |
165,034 | 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, requi... | // 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... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/report/source.go#L578-L602 |
165,035 | 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",
"(",
... | // 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 |
165,036 | 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",
"(",
"[",
"]",... | // 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 |
165,037 | 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",
":=",
"&",
"addr2Liner... | // 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",
"wa... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/binutils/addr2liner.go#L86-L116 |
165,038 | 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",
".",
"Fr... | // 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 |
165,039 | 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 err... | // 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 |
165,040 | 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",
":=",
"\"",
"\"",
",",
... | // 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 |
165,041 | 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"... | // 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 |
165,042 | 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",
"(... | // 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",
"re... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/filter.go#L24-L75 |
165,043 | 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",
... | // 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"... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/filter.go#L118-L127 |
165,044 | 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",
... | // 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 |
165,045 | 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",
":=",
... | // 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 |
165,046 | 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... | // 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 |
165,047 | 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",
"]",
"==",
... | // 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 |
165,048 | 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",
"{",
"}",
... | // 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 |
165,049 | 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",
"{",... | // 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 |
165,050 | 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",
"... | // 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",
... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L278-L299 |
165,051 | 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 |
165,052 | 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",
".",
"HasInlin... | // 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 |
165,053 | 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",
... | // 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",
".",... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/profile.go#L464-L517 |
165,054 | 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",
"."... | // 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 |
165,055 | 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",
"... | // 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 |
165,056 | 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",... | // 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 |
165,057 | 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... | // 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 |
165,058 | 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",
",",
... | // 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 |
165,059 | 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",
... | // 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 |
165,060 | 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",
".",... | // 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 |
165,061 | 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 |
165,062 | 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",
"}",
... | // 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 |
165,063 | 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",
")",
")",
"\... | // 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 |
165,064 | 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",
"(",
"\"",
"\"",
",",
"... | // 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 |
165,065 | 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",
"{",
"retur... | // 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 |
165,066 | 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",
"||",
... | // 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 |
165,067 | 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",
".",
"Buf... | // 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",
... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/binutils/addr2liner_nm.go#L47-L58 |
165,068 | 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",
":=",
"rang... | // 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 |
165,069 | 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 packa... | // 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 |
165,070 | 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",... | // 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",
... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/symbolz/symbolz.go#L188-L200 |
165,071 | 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, "&;", "&;", -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, "&;", "&;", -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",... | // 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",
"varia... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/internal/driver/svg.go#L33-L80 |
165,072 | 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"... | // 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 |
165,073 | 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",
".",
"FindStringS... | // 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 |
165,074 | 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",
"}",
"\... | // 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 |
165,075 | 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",
"... | // 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 |
165,076 | 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",
":=",
"&",
... | // 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",
"-... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/legacy_java_profile.go#L42-L64 |
165,077 | 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",
... | // 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 |
165,078 | 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'",
")",
... | // 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 |
165,079 | 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",
"(",
"... | // 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"... | 8358a9778bd1e48718ffcb96eb11ee061385bf62 | https://github.com/google/pprof/blob/8358a9778bd1e48718ffcb96eb11ee061385bf62/profile/legacy_java_profile.go#L239-L315 |
165,080 | 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 ... | // 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 |
165,081 | 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",
... | // 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 |
165,082 | 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... | // 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 |
165,083 | 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",
")"... | // 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 |
165,084 | 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",
"... | // 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 |
165,085 | 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",
",",
"numLabel... | // 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 |
165,086 | 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",
".... | // 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 |
165,087 | 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",
":=",
"... | // 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 |
165,088 | 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 t... | // 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 |
165,089 | 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",
... | // 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 |
165,090 | 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... | // 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 |
165,091 | 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",
... | // 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 |
165,092 | 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",
"minT... | // 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 |
165,093 | 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",
")",
"... | // 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 |
165,094 | 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",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
... | // 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 |
165,095 | 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",
",",
"\"",
"\"",
... | // 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 |
165,096 | 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 |
165,097 | 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",
"{",
"}",
"... | // 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 |
165,098 | 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",
... | // 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 |
165,099 | 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",
"(",
"\"",
"\"",
")",
... | // 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.