Skip to content

Commit

Permalink
Update report generation and driver for column numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
snehasish committed Dec 20, 2023
1 parent 2120b2e commit 073c7cb
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 23 deletions.
4 changes: 2 additions & 2 deletions internal/driver/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ var configHelp = map[string]string{
"noinlines": helpText(
"Ignore inlines.",
"Attributes inlined functions to their first out-of-line caller."),
"columns": helpText(
"Use column numbers when aggregating at the source code line level."),
"showcolumns": helpText(
"Show column numbers at the source code line level."),
}

func helpText(s ...string) string {
Expand Down
6 changes: 3 additions & 3 deletions internal/driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type config struct {
TagShow string `json:"tagshow,omitempty"`
TagHide string `json:"taghide,omitempty"`
NoInlines bool `json:"noinlines,omitempty"`
Columns bool `json:"columns,omitempty"`
ShowColumns bool `json:"showcolumns,omitempty"`

// Output granularity
Granularity string `json:"granularity,omitempty"`
Expand Down Expand Up @@ -125,7 +125,7 @@ func init() {
// take on one of a bounded set of values.
choices := map[string][]string{
"sort": {"cum", "flat"},
"granularity": {"functions", "filefunctions", "files", "lines", "columns", "addresses"},
"granularity": {"functions", "filefunctions", "files", "lines", "addresses"},
}

// urlparam holds the mapping from a config field name to the URL
Expand Down Expand Up @@ -158,7 +158,7 @@ func init() {
"sort": "sort",
"granularity": "g",
"noinlines": "noinlines",
"columns": "columns",
"showcolumns": "showcolumns",
}

def := defaultConfig()
Expand Down
9 changes: 2 additions & 7 deletions internal/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func dropEmptyStrings(in []string) (out []string) {
}

func aggregate(prof *profile.Profile, cfg config) error {
var function, filename, linenumber, columnnumber, address bool
var function, filename, linenumber, address bool
inlines := !cfg.NoInlines
switch cfg.Granularity {
case "addresses":
Expand All @@ -246,11 +246,6 @@ func aggregate(prof *profile.Profile, cfg config) error {
function = true
filename = true
linenumber = true
case "columns":
function = true
filename = true
linenumber = true
columnnumber = true
case "files":
filename = true
case "functions":
Expand All @@ -261,7 +256,7 @@ func aggregate(prof *profile.Profile, cfg config) error {
default:
return fmt.Errorf("unexpected granularity")
}
return prof.Aggregate(inlines, function, filename, linenumber, columnnumber, address)
return prof.Aggregate(inlines, function, filename, linenumber, cfg.ShowColumns, address)
}

func reportOptions(p *profile.Profile, numLabelUnits map[string]string, cfg config) (*report.Options, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestParseConfig(t *testing.T) {
Sort: "cum",
Granularity: "functions",
NoInlines: true,
Columns: true,
ShowColumns: true,
}
url, changed := cfg.makeURL(url.URL{})
if !changed {
Expand Down
15 changes: 11 additions & 4 deletions internal/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ type NodeInfo struct {
Address uint64
File string
StartLine, Lineno int
Columnno int
Objfile string
}

Expand All @@ -174,8 +175,12 @@ func (i *NodeInfo) NameComponents() []string {

switch {
case i.Lineno != 0:
s := fmt.Sprintf("%s:%d", i.File, i.Lineno)
if i.Columnno != 0 {
s += fmt.Sprintf(":%d", i.Columnno)
}
// User requested line numbers, provide what we have.
name = append(name, fmt.Sprintf("%s:%d", i.File, i.Lineno))
name = append(name, s)
case i.File != "":
// User requested file name, provide it.
name = append(name, i.File)
Expand Down Expand Up @@ -239,6 +244,7 @@ func (nm NodeMap) FindOrInsertNode(info NodeInfo, kept NodeSet) *Node {
// Find a node that represents the whole function.
info.Address = 0
info.Lineno = 0
info.Columnno = 0
n.Function = nm.FindOrInsertNode(info, nil)
return n
}
Expand Down Expand Up @@ -592,9 +598,10 @@ func nodeInfo(l *profile.Location, line profile.Line, objfile string, o *Options
return &NodeInfo{Address: l.Address, Objfile: objfile}
}
ni := &NodeInfo{
Address: l.Address,
Lineno: int(line.Line),
Name: line.Function.Name,
Address: l.Address,
Lineno: int(line.Line),
Columnno: int(line.Column),
Name: line.Function.Name,
}
if fname := line.Function.Filename; fname != "" {
ni.File = filepath.Clean(fname)
Expand Down
1 change: 1 addition & 0 deletions internal/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func printTopProto(w io.Writer, rpt *Report) error {
Line: []profile.Line{
{
Line: int64(n.Info.Lineno),
Column: int64(n.Info.Columnno),
Function: f,
},
},
Expand Down
2 changes: 2 additions & 0 deletions internal/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ var testL = []*profile.Location{
{
Function: testF[0],
Line: 2,
Column: 2,
},
},
},
Expand All @@ -201,6 +202,7 @@ var testL = []*profile.Location{
{
Function: testF[1],
Line: 4,
Column: 4,
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions internal/report/testdata/source.dot
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ digraph "unnamed" {
node [style=filled fillcolor="#f8f8f8"]
subgraph cluster_L { "Duration: 10s, Total samples = 11111 " [shape=box fontsize=16 label="Duration: 10s, Total samples = 11111 \lShowing nodes accounting for 11111, 100% of 11111 total\l\lSee https://git.io/JfYMW for how to read the graph\l"] }
N1 [label="tee\nsource2:8\n10000 (90.00%)" id="node1" fontsize=24 shape=box tooltip="tee testdata/source2:8 (10000)" color="#b20500" fillcolor="#edd6d5"]
N2 [label="main\nsource1:2\n1 (0.009%)\nof 11111 (100%)" id="node2" fontsize=9 shape=box tooltip="main testdata/source1:2 (11111)" color="#b20000" fillcolor="#edd5d5"]
N2 [label="main\nsource1:2:2\n1 (0.009%)\nof 11111 (100%)" id="node2" fontsize=9 shape=box tooltip="main testdata/source1:2:2 (11111)" color="#b20000" fillcolor="#edd5d5"]
N3 [label="tee\nsource2:2\n1000 (9.00%)\nof 11000 (99.00%)" id="node3" fontsize=14 shape=box tooltip="tee testdata/source2:2 (11000)" color="#b20000" fillcolor="#edd5d5"]
N4 [label="tee\nsource2:8\n100 (0.9%)" id="node4" fontsize=10 shape=box tooltip="tee testdata/source2:8 (100)" color="#b2b0aa" fillcolor="#edecec"]
N5 [label="bar\nsource1:10\n10 (0.09%)" id="node5" fontsize=9 shape=box tooltip="bar testdata/source1:10 (10)" color="#b2b2b1" fillcolor="#ededed"]
N6 [label="bar\nsource1:10\n0 of 100 (0.9%)" id="node6" fontsize=8 shape=box tooltip="bar testdata/source1:10 (100)" color="#b2b0aa" fillcolor="#edecec"]
N7 [label="foo\nsource1:4\n0 of 10 (0.09%)" id="node7" fontsize=8 shape=box tooltip="foo testdata/source1:4 (10)" color="#b2b2b1" fillcolor="#ededed"]
N2 -> N3 [label=" 11000" weight=100 penwidth=5 color="#b20000" tooltip="main testdata/source1:2 -> tee testdata/source2:2 (11000)" labeltooltip="main testdata/source1:2 -> tee testdata/source2:2 (11000)"]
N7 [label="foo\nsource1:4:4\n0 of 10 (0.09%)" id="node7" fontsize=8 shape=box tooltip="foo testdata/source1:4:4 (10)" color="#b2b2b1" fillcolor="#ededed"]
N2 -> N3 [label=" 11000" weight=100 penwidth=5 color="#b20000" tooltip="main testdata/source1:2:2 -> tee testdata/source2:2 (11000)" labeltooltip="main testdata/source1:2:2 -> tee testdata/source2:2 (11000)"]
N3 -> N1 [label=" 10000" weight=91 penwidth=5 color="#b20500" tooltip="tee testdata/source2:2 -> tee testdata/source2:8 (10000)" labeltooltip="tee testdata/source2:2 -> tee testdata/source2:8 (10000)"]
N6 -> N4 [label=" 100" color="#b2b0aa" tooltip="bar testdata/source1:10 -> tee testdata/source2:8 (100)" labeltooltip="bar testdata/source1:10 -> tee testdata/source2:8 (100)"]
N2 -> N6 [label=" 100" color="#b2b0aa" tooltip="main testdata/source1:2 -> bar testdata/source1:10 (100)" labeltooltip="main testdata/source1:2 -> bar testdata/source1:10 (100)"]
N7 -> N5 [label=" 10" color="#b2b2b1" tooltip="foo testdata/source1:4 -> bar testdata/source1:10 (10)" labeltooltip="foo testdata/source1:4 -> bar testdata/source1:10 (10)"]
N2 -> N7 [label=" 10" color="#b2b2b1" tooltip="main testdata/source1:2 -> foo testdata/source1:4 (10)" labeltooltip="main testdata/source1:2 -> foo testdata/source1:4 (10)"]
N2 -> N6 [label=" 100" color="#b2b0aa" tooltip="main testdata/source1:2:2 -> bar testdata/source1:10 (100)" labeltooltip="main testdata/source1:2:2 -> bar testdata/source1:10 (100)"]
N7 -> N5 [label=" 10" color="#b2b2b1" tooltip="foo testdata/source1:4:4 -> bar testdata/source1:10 (10)" labeltooltip="foo testdata/source1:4:4 -> bar testdata/source1:10 (10)"]
N2 -> N7 [label=" 10" color="#b2b2b1" tooltip="main testdata/source1:2:2 -> foo testdata/source1:4:4 (10)" labeltooltip="main testdata/source1:2:2 -> foo testdata/source1:4:4 (10)"]
}

0 comments on commit 073c7cb

Please sign in to comment.