Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/actions/checkout-4…
Browse files Browse the repository at this point in the history
….1.1
  • Loading branch information
aalexand authored Jan 30, 2024
2 parents 44920b5 + 7cd122e commit 2079387
Show file tree
Hide file tree
Showing 46 changed files with 486 additions and 2,105 deletions.
53 changes: 16 additions & 37 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,18 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.19', '1.20', 'tip']
go: ['1.20', '1.21', 'tip']
# Supported macOS versions can be found in
# https://github.com/actions/virtual-environments#available-environments.
os: ['macos-11', 'macos-12']
# Supported Xcode versions for macOS 11 can be found in
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md#xcode
# Supported Xcode versions for macOS 12 can be found in
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-12-Readme.md#xcode
xcode-version: ['14.2', '14.1', '14.0.1', '13.4.1', '13.3.1', '13.2.1', '13.1', '13.0', '12.5.1', '12.4', '11.7']
exclude:
- os: 'macos-11'
xcode-version: '13.3.1'
- os: 'macos-11'
xcode-version: '13.4.1'
- os: 'macos-11'
xcode-version: '14.0.1'
- os: 'macos-11'
xcode-version: '14.1'
- os: 'macos-11'
xcode-version: '14.2'
- os: 'macos-12'
xcode-version: '11.7'
- os: 'macos-12'
xcode-version: '12.4'
- os: 'macos-12'
xcode-version: '12.5.1'
- os: 'macos-12'
xcode-version: '13.0'
# TODO: Add macos-13. As of now there are build errors when installing graphviz.
os: ['macos-12']
# Supported Xcode versions can be found in:
# - https://github.com/actions/virtual-environments/blob/main/images/macos/macos-12-Readme.md#xcode
# - https://github.com/actions/virtual-environments/blob/main/images/macos/macos-13-Readme.md#xcode
xcode-version: ['14.2', '14.1', '14.0.1', '13.4.1', '13.3.1', '13.2.1', '13.1']
steps:
- name: Update Go version using setup-go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
if: matrix.go != 'tip'
with:
go-version: ${{ matrix.go }}
Expand Down Expand Up @@ -80,8 +61,7 @@ jobs:
brew install graphviz
# Do not let tools interfere with the main module's go.mod.
cd && go mod init tools
# TODO: Update to a specific version when https://github.com/dominikh/go-tools/issues/1362 is fixed.
go install honnef.co/go/tools/cmd/staticcheck@master
go install honnef.co/go/tools/cmd/staticcheck@v0.4.6
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.0
# Add PATH for installed tools.
echo "$GOPATH/bin:$PATH" >> $GITHUB_PATH
Expand All @@ -92,7 +72,7 @@ jobs:
./test.sh
- name: Code coverage
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5
with:
file: ${{ env.WORKING_DIR }}/coverage.txt

Expand All @@ -104,11 +84,11 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.19', '1.20', 'tip']
go: ['1.20', '1.21', 'tip']
os: ['ubuntu-22.04', 'ubuntu-20.04']
steps:
- name: Update Go version using setup-go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
if: matrix.go != 'tip'
with:
go-version: ${{ matrix.go }}
Expand Down Expand Up @@ -139,8 +119,7 @@ jobs:
sudo apt-get install graphviz
# Do not let tools interfere with the main module's go.mod.
cd && go mod init tools
# TODO: Update to a specific version when https://github.com/dominikh/go-tools/issues/1362 is fixed.
go install honnef.co/go/tools/cmd/staticcheck@master
go install honnef.co/go/tools/cmd/staticcheck@v0.4.6
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.0
# Add PATH for installed tools.
echo "$GOPATH/bin:$PATH" >> $GITHUB_PATH
Expand All @@ -151,7 +130,7 @@ jobs:
./test.sh
- name: Code coverage
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5
with:
file: ${{ env.WORKING_DIR }}/coverage.txt

Expand All @@ -160,10 +139,10 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.19', '1.20']
go: ['1.20', '1.21']
steps:
- name: Update Go version using setup-go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ${{ matrix.go }}

Expand Down
7 changes: 4 additions & 3 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ type ObjFile interface {

// A Frame describes a single line in a source file.
type Frame struct {
Func string // name of function
File string // source file name
Line int // line in file
Func string // name of function
File string // source file name
Line int // line in file
Column int // column in file
}

// A Sym describes a single symbol in an object file.
Expand Down
22 changes: 14 additions & 8 deletions internal/binutils/addr2liner_llvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (d *llvmSymbolizer) readFrame() (plugin.Frame, bool) {
}

linenumber := 0
columnnumber := 0
// The llvm-symbolizer outputs the <file_name>:<line_number>:<column_number>.
// When it cannot identify the source code location, it outputs "??:0:0".
// Older versions output just the filename and line number, so we check for
Expand All @@ -137,22 +138,27 @@ func (d *llvmSymbolizer) readFrame() (plugin.Frame, bool) {
fileline = ""
} else {
switch split := strings.Split(fileline, ":"); len(split) {
case 1:
// filename
fileline = split[0]
case 2, 3:
// filename:line , or
// filename:line:disc , or
fileline = split[0]
case 3:
// filename:line:column
if col, err := strconv.Atoi(split[2]); err == nil {
columnnumber = col
}
fallthrough
case 2:
// filename:line
if line, err := strconv.Atoi(split[1]); err == nil {
linenumber = line
}
fallthrough
case 1:
// filename
fileline = split[0]
default:
// Unrecognized, ignore
}
}

return plugin.Frame{Func: funcname, File: fileline, Line: linenumber}, false
return plugin.Frame{Func: funcname, File: fileline, Line: linenumber, Column: columnnumber}, false
}

// addrInfo returns the stack frame information for a specific program
Expand Down
6 changes: 3 additions & 3 deletions internal/binutils/binutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ func TestLLVMSymbolizer(t *testing.T) {
frames []plugin.Frame
}{
{0x10, false, []plugin.Frame{
{Func: "Inlined_0x10", File: "foo.h", Line: 0},
{Func: "Func_0x10", File: "foo.c", Line: 2},
{Func: "Inlined_0x10", File: "foo.h", Line: 0, Column: 0},
{Func: "Func_0x10", File: "foo.c", Line: 2, Column: 1},
}},
{0x20, true, []plugin.Frame{
{Func: "foo_0x20", File: "0x20 8"},
Expand Down Expand Up @@ -532,7 +532,7 @@ func TestPEFile(t *testing.T) {
t.Fatalf("SourceLine: unexpected error %v", err)
}
wantFrames := []plugin.Frame{
{Func: "main", File: "hello.c", Line: 3},
{Func: "main", File: "hello.c", Line: 3, Column: 12},
}
if !reflect.DeepEqual(gotFrames, wantFrames) {
t.Fatalf("SourceLine for main: got %v; want %v\n", gotFrames, wantFrames)
Expand Down
2 changes: 2 additions & 0 deletions internal/driver/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ var configHelp = map[string]string{
"noinlines": helpText(
"Ignore inlines.",
"Attributes inlined functions to their first out-of-line caller."),
"showcolumns": helpText(
"Show column numbers at the source code line level."),
}

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

// Output granularity
Granularity string `json:"granularity,omitempty"`
Expand Down Expand Up @@ -157,6 +158,7 @@ func init() {
"sort": "sort",
"granularity": "g",
"noinlines": "noinlines",
"showcolumns": "showcolumns",
}

def := defaultConfig()
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func aggregate(prof *profile.Profile, cfg config) error {
default:
return fmt.Errorf("unexpected granularity")
}
return prof.Aggregate(inlines, function, filename, linenumber, 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
5 changes: 3 additions & 2 deletions internal/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1680,8 +1680,9 @@ func (m *mockFile) BuildID() string {
func (*mockFile) SourceLine(addr uint64) ([]plugin.Frame, error) {
// Return enough data to support the SourceLine() calls needed for
// weblist on cpuProfile() contents.
frame := func(fn, file string, line int) plugin.Frame {
return plugin.Frame{Func: fn, File: file, Line: line}
frame := func(fn, file string, num int) plugin.Frame {
// Reuse the same num for line number and column number.
return plugin.Frame{Func: fn, File: file, Line: num, Column: num}
}
switch addr {
case 0x1000:
Expand Down
24 changes: 15 additions & 9 deletions internal/driver/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,17 +492,23 @@ mapping:
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))
// First determine whether the source is a file, if not, it will be treated as a URL.
if _, openErr := os.Stat(source); openErr == nil {
if isPerfFile(source) {
f, err = convertPerfData(source, ui)
} else {
f, err = os.Open(source)
}
f, err = fetchURL(sourceURL, timeout, tr)
src = sourceURL
} else if isPerfFile(source) {
f, err = convertPerfData(source, ui)
} else {
f, err = os.Open(source)
sourceURL, timeout := adjustURL(source, duration, timeout)
if 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
}
}
if err == nil {
defer f.Close()
Expand Down
22 changes: 19 additions & 3 deletions internal/driver/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,28 @@ func TestFetch(t *testing.T) {
type testcase struct {
source, execName string
}

for _, tc := range []testcase{
ts := []testcase{
{path + "go.crc32.cpu", ""},
{path + "go.nomappings.crash", "/bin/gotest.exe"},
{"http://localhost/profile?file=cppbench.cpu", ""},
} {
}
// Test that paths with a colon character are recognized as file paths
// if the file exists, rather than as a URL. We have to skip this test
// on Windows since the colon char is not allowed in Windows paths.
if runtime.GOOS != "windows" {
src := filepath.Join(path, "go.crc32.cpu")
dst := filepath.Join(t.TempDir(), "go.crc32.cpu_2023-11-11_01:02:03")
data, err := os.ReadFile(src)
if err != nil {
t.Fatalf("read src file %s failed: %#v", src, err)
}
err = os.WriteFile(dst, data, 0644)
if err != nil {
t.Fatalf("create dst file %s failed: %#v", dst, err)
}
ts = append(ts, testcase{dst, ""})
}
for _, tc := range ts {
p, _, _, err := grabProfile(&source{ExecName: tc.execName}, tc.source, nil, testObj{}, &proftest.TestUI{T: t}, &httpTransport{})
if err != nil {
t.Fatalf("%s: %s", tc.source, err)
Expand Down
Loading

0 comments on commit 2079387

Please sign in to comment.