-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathMakefile
More file actions
235 lines (208 loc) · 7.9 KB
/
Makefile
File metadata and controls
235 lines (208 loc) · 7.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!make
#
# Copyright (C) 2021-2025 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
#
COMMIT_ID := $(shell git rev-parse --short=8 HEAD)
COMMIT_DATE := $(shell git show -s --format=%cd --date=short HEAD)
COMMIT_TIME := $(shell git show -s --format=%cd --date=format:'%H:%M:%S' HEAD)
VERSION_FILE := ./version.txt
VERSION_NUMBER := $(shell cat ${VERSION_FILE})
VERSION := $(VERSION_NUMBER)_$(COMMIT_DATE)_$(COMMIT_ID)
default: perfspect
GOFLAGS_COMMON=-trimpath -mod=readonly -ldflags="-X perfspect/cmd.gVersion=$(VERSION) -s -w"
GO=CGO_ENABLED=0 GOOS=linux go
# Required embedded binary resources (must exist before building)
# Note: This is a subset of binaries used to detect if builder/build.sh has been run,
# not the complete list of embedded resources.
REQUIRED_RESOURCES := \
internal/script/resources/x86_64/perf \
internal/script/resources/x86_64/fio \
internal/script/resources/aarch64/perf \
internal/script/resources/aarch64/fio
# Check that binary dependencies are available
.PHONY: check-resources
check-resources:
@missing=""; \
for f in $(REQUIRED_RESOURCES); do \
if [ ! -f "$$f" ]; then \
missing="$$missing $$f"; \
fi; \
done; \
if [ -n "$$missing" ]; then \
echo "Error: Required binary resources are missing:$$missing"; \
echo ""; \
echo "Run 'builder/build.sh' first to build the binary dependencies."; \
echo "For subsequent builds, use 'make' after the initial build."; \
exit 1; \
fi
# Build the perfspect binary
.PHONY: perfspect
perfspect: check-resources
GOARCH=amd64 $(GO) build $(GOFLAGS_COMMON) -o $@
# Build the perfspect binary for AARCH64
.PHONY: perfspect-aarch64
perfspect-aarch64: check-resources
GOARCH=arm64 $(GO) build $(GOFLAGS_COMMON) -o $@
# Copy prebuilt tools to script resources
.PHONY: resources
resources:
mkdir -p internal/script/resources
ifneq ("$(wildcard /prebuilt/tools)","") # /prebuilt/tools is a directory in the container
@echo "Copying prebuilt tools from /prebuilt/tools to script resources"
cp -r /prebuilt/tools/* internal/script/resources/
else # copy dev system tools to script resources
ifneq ("$(wildcard tools/bin)","")
@echo "Copying dev system tools from tools/bin to script resources"
cp -r tools/bin/* internal/script/resources/
else # no prebuilt tools found
@echo "No prebuilt tools found in /prebuilt/tools or tools/bin"
endif
endif
# Build the distribution package
.PHONY: dist
dist: resources check perfspect perfspect-aarch64
rm -rf dist/perfspect
mkdir -p dist/perfspect/tools/x86_64
mkdir -p dist/perfspect/tools/aarch64
cp LICENSE dist/perfspect/
cp THIRD_PARTY_PROGRAMS dist/perfspect/
cp NOTICE dist/perfspect/
cp targets.yaml dist/perfspect/
cp perfspect dist/perfspect/
cd dist && tar -czf perfspect.tgz perfspect
cd dist && md5sum perfspect.tgz > perfspect.tgz.md5.txt
# for aarch64 dist, overwrite perfspect binary
cp perfspect-aarch64 dist/perfspect/perfspect
cd dist && tar -czf perfspect-aarch64.tgz perfspect
cd dist && md5sum perfspect-aarch64.tgz > perfspect-aarch64.tgz.md5.txt
rm -rf dist/perfspect
echo '{"version": "$(VERSION_NUMBER)", "date": "$(COMMIT_DATE)", "time": "$(COMMIT_TIME)", "commit": "$(COMMIT_ID)" }' | jq '.' > dist/manifest.json
ifneq ("$(wildcard /prebuilt)","") # /prebuilt is a directory in the container
cp -r /prebuilt/oss_source* dist/
endif
# Run package-level unit tests
.PHONY: test
test:
@echo "Running unit tests..."
go test -v ./...
cd tools/stackcollapse-perf && go test -v ./...
.PHONY: update-deps
update-deps:
@echo "Updating Go dependencies..."
go get -u ./...
go mod tidy
# Check code formatting
.PHONY: check_format
check_format:
@echo "Running gofmt to check for code formatting issues..."
@files=$$(gofmt -l -s ./); \
if [ -n "$$files" ]; then \
echo "[WARN] Formatting issues detected in the following files:"; \
echo "$$files"; \
echo "Resolve with 'make format'"; \
exit 1; \
fi
@echo "gofmt detected no issues"
# Format code
.PHONY: format
format:
@echo "Running gofmt to format code..."
gofmt -l -w -s ./
.PHONY: check_vet
check_vet:
@echo "Running go vet to check for suspicious constructs..."
@test -z "$(shell go vet ./...)" || { echo "[WARN] go vet detected issues"; exit 1; }
@echo "go vet detected no issues"
.PHONY: check_static
check_static:
@echo "Running staticcheck to check for bugs..."
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...
.PHONY: check_license
check_license:
@echo "Confirming source files have license headers..."
@for f in `find . -type f ! -path './perfspect_202*' ! -path './tools/bin/*' ! -path './tools/bin-aarch64/*' ! -path './tools-cache/*' ! -path './internal/script/resources/*' ! -path './scripts/.venv/*' ! -path './test/output/*' ! -path './debug_out/*' ! -path './tools/perf-archive/*' ! -path './tools/avx-turbo/*' \( -name "*.go" -o -name "*.s" -o -name "*.html" -o -name "Makefile" -o -name "*.sh" -o -name "*.Dockerfile" -o -name "*.py" \)`; do \
if ! grep -E 'SPDX-License-Identifier: BSD-3-Clause' "$$f" >/dev/null; then echo "Error: license not found: $$f"; fail=1; fi; \
done; if [ -n "$$fail" ]; then exit 1; fi
.PHONY: check_lint
check_lint:
@echo "Running golangci-lint to check for style issues..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run
.PHONY: check_vuln
check_vuln:
@echo "Running govulncheck to check for vulnerabilities..."
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
.PHONY: check_sec
check_sec:
@echo "Running gosec to check for security issues..."
go install github.com/securego/gosec/v2/cmd/gosec@latest
gosec ./...
.PHONY: check_semgrep
check_semgrep:
@echo "Running semgrep to check for security issues..."
@echo "Please install semgrep from https://semgrep.dev/docs/getting-started/installation/ if not already installed."
@echo "Running semgrep..."
semgrep scan
.PHONY: check_modernize
check_modernize:
@echo "Running go-modernize to check for modernization opportunities..."
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test ./...
.PHONY: modernize
modernize:
@echo "Running go-modernize to apply modernization opportunities..."
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...
.PHONY: check
check: check_format check_vet check_static check_license check_lint check_vuln test
.PHONY: sweep
sweep:
rm -rf perfspect_202?-*
rm -rf debug_out/*
rm -rf test/output
rm -f __debug_bin*.log
rm -f perfspect.log
.PHONY: clean
clean: sweep clean-tools-cache
@echo "Cleaning up..."
rm -f perfspect
rm -f perfspect-aarch64
sudo rm -rf dist
rm -rf internal/script/resources/aarch64
rm -rf internal/script/resources/x86_64
.PHONY: clean-tools-cache
clean-tools-cache:
@echo "Removing cached tool binaries..."
rm -rf tools-cache
# Generate command documentation from help text
COMMANDS := report benchmark metrics telemetry flamegraph lock config update extract
SUBCOMMANDS := metrics:trim config:restore
.PHONY: docs
docs: perfspect
@echo "Generating command documentation..."
@mkdir -p docs
@echo '# perfspect' > docs/perfspect.md
@echo '' >> docs/perfspect.md
@echo '```text' >> docs/perfspect.md
@./perfspect --help >> docs/perfspect.md
@echo '```' >> docs/perfspect.md
@for cmd in $(COMMANDS); do \
echo " $$cmd"; \
echo "# perfspect $$cmd" > docs/perfspect_$$cmd.md; \
echo '' >> docs/perfspect_$$cmd.md; \
echo '```text' >> docs/perfspect_$$cmd.md; \
./perfspect $$cmd --help >> docs/perfspect_$$cmd.md; \
echo '```' >> docs/perfspect_$$cmd.md; \
done
@for sub in $(SUBCOMMANDS); do \
cmd=$${sub%%:*}; \
subcmd=$${sub##*:}; \
echo " $$cmd $$subcmd"; \
echo "# perfspect $$cmd $$subcmd" > docs/perfspect_$${cmd}_$${subcmd}.md; \
echo '' >> docs/perfspect_$${cmd}_$${subcmd}.md; \
echo '```text' >> docs/perfspect_$${cmd}_$${subcmd}.md; \
./perfspect $$cmd $$subcmd --help >> docs/perfspect_$${cmd}_$${subcmd}.md; \
echo '```' >> docs/perfspect_$${cmd}_$${subcmd}.md; \
done
@echo "Documentation generated in docs/"