Skip to content

Commit

Permalink
new: initial commit
Browse files Browse the repository at this point in the history
right now bpftree provides 5 commands:
* dump
* fields
* info
* lineage
* tree

Signed-off-by: Andrea Terzolo <[email protected]>
  • Loading branch information
Andreagit97 committed Jul 23, 2023
0 parents commit 8a2b4bc
Show file tree
Hide file tree
Showing 50 changed files with 138,959 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -8
BreakBeforeBraces: Allman
BreakConstructorInitializers: AfterColon
ColumnLimit: 100
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
DerivePointerAlignment: true
IndentWidth: 8
SortIncludes: false
SpaceAfterTemplateKeyword: false
SpaceBeforeCtorInitializerColon: false
SpaceBeforeParens: Never
UseTab: Always
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Exclude vmlinux from github stats
pkg/task/bpf/vmlinux.h linguist-vendored
69 changes: 69 additions & 0 deletions .github/workflows/build_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Build and test

on:
pull_request:
push:
branches:
- main

jobs:

build_and_test:
runs-on: ubuntu-22.04
steps:
- name: Install deps
run: |
sudo apt update -y
sudo apt install -y --no-install-recommends build-essential git clang llvm libelf-dev
git clone https://github.com/libbpf/libbpf.git --branch v1.2.0 --single-branch
pushd libbpf/src
sudo make install
popd
sudo rm -rf ./libbpf
- name: Checkout commit
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: '1.20'
check-latest: true

- name: Build
run: |
go generate ./...
go build .
- name: Run tests
run: |
sudo -E env "PATH=$PATH" go test ./... -count=1
# use goreleaser to build all supported archs
- name: Build all supported archs
id: run-goreleaser
uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0
with:
distribution: goreleaser
version: latest
args: release --snapshot --clean

- name: Archive x86_64 tar.gz
uses: actions/upload-artifact@v3
with:
name: x86_64
path: ./dist/bpftree_Linux_x86_64.tar.gz

- name: Archive arm64 tar.gz
uses: actions/upload-artifact@v3
with:
name: arm64
path: ./dist/bpftree_Linux_arm64.tar.gz

- name: Archive s390x tar.gz
uses: actions/upload-artifact@v3
with:
name: s390x
path: ./dist/bpftree_Linux_s390x.tar.gz
80 changes: 80 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Linting
on:
pull_request:
push:
branches:
- main

jobs:

golangci:
name: Lint golang files
runs-on: ubuntu-22.04
steps:
- name: Install deps
run: |
sudo apt update -y
sudo apt install -y --no-install-recommends build-essential git clang llvm libelf-dev
git clone https://github.com/libbpf/libbpf.git --branch v1.2.0 --single-branch
pushd libbpf/src
sudo make install
popd
sudo rm -rf ./libbpf
- name: Checkout commit
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: '1.20'
check-latest: true

- name: Build
run: |
go generate ./...
go build .
go clean -modcache
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
only-new-issues: false
version: v1.53.3
args: --timeout=900s

gomodtidy:
name: Enforce go.mod tidiness
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
with:
ref: "${{ github.event.pull_request.head.sha }}"
repository: ${{github.event.pull_request.head.repo.full_name}}
persist-credentials: false

- name: Setup Go
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: '1.20'
check-latest: true

- name: Execute go mod tidy and check the outcome
working-directory: ./
run: |
go mod tidy
exit_code=$(git diff --exit-code)
exit ${exit_code}
- name: Print a comment in case of failure
run: |
echo "The go.mod and/or go.sum files appear not to be correctly tidied.
Please, rerun go mod tidy to fix the issues."
exit 1
if: |
failure() && github.event.pull_request.head.repo.full_name == github.repository
46 changes: 46 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
build-all-archs:
runs-on: ubuntu-22.04
permissions:
contents: write # To add assets to a release.
steps:
- name: Install deps
run: |
sudo apt update -y
sudo apt install -y --no-install-recommends build-essential git clang llvm libelf-dev
git clone https://github.com/libbpf/libbpf.git --branch v1.2.0 --single-branch
pushd libbpf/src
sudo make install
popd
sudo rm -rf ./libbpf
- name: Checkout
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
with:
fetch-depth: 0

- name: Fetch all tags
run: git fetch --force --tags

- name: Setup Go
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: '1.20'
check-latest: true

- name: Run GoReleaser
id: run-goreleaser
uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0
with:
distribution: goreleaser
version: latest
args: release --clean --release-notes=./release_changelog.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
*.o
.vscode
# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

bpftree

dist/
testdata/output/script*
temp.*
pkg/task/iter_bpf*
125 changes: 125 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
run:
timeout: 10m
skip-files:
- pkg/task/iter_bpfel.go
- pkg/task/iter_bpfeb.go

linters-settings:
exhaustive:
check-generated: false
default-signifies-exhaustive: true

lll:
line-length: 100

gci:
sections:
- standard # Captures all standard packages if they do not match another section.
- default # Contains all imports that could not be matched to another section type.
- prefix(github.com/Andreagit97/bpftree) # Groups all imports with the specified Prefix.
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
# Conflicts with govet check-shadowing
- sloppyReassign
goimports:
local-prefixes: github.com/Andreagit97/bpftree
govet:
check-shadowing: true
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: true # require an explanation for nolint directives
require-specific: true # require nolint directives to be specific about which linter is being skipped
dupl:
threshold: 300

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
# - depguard
- dogsled
- dupl
- errcheck
- errorlint
- exhaustive
- exportloopref
# - funlen
# - gochecknoglobals
# - gochecknoinits
# - gocognit
- gci
- goconst
- gocritic
- gocyclo
- godot
# - godox
# - goerr113
- gofmt
- goheader
- goimports
- gomodguard
# - gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
# - maligned
- misspell
- nakedret
# - nestif
- noctx
- nolintlint
# - prealloc
# - revive
- rowserrcheck
- staticcheck
- stylecheck
# - testpackage
# - typecheck
- unconvert
- unparam
- unused
- whitespace
# - wsl

issues:
#fix: true

max-issues-per-linter: 0
max-same-issues: 0

# Disable the default exclude patterns (as they disable the mandatory comments)
exclude-use-default: false
exclude:
# errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked

exclude-rules:
- linters:
- govet
text: 'declaration of "(err|ctx)" shadows declaration at'
- linters:
- errorlint
# Disable the check to test errors type assertion on switches.
text: type switch on error will fail on wrapped errors. Use errors.As to check for specific errors

# Exclude the following linters from running on tests files.
- path: _test\.go
linters:
- gosec
- typecheck
Loading

0 comments on commit 8a2b4bc

Please sign in to comment.