Skip to content

Commit

Permalink
Automate pprof insertion (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanavery authored Dec 13, 2024
1 parent faae4cc commit e892656
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ FFmpeg
*.DS_Store
bin
module.tar.gz
.build_tags
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ TARGET_ARCH ?= $(SOURCE_ARCH)
normalize_arch = $(if $(filter aarch64,$(1)),arm64,$(if $(filter x86_64,$(1)),amd64,$(1)))
SOURCE_ARCH := $(call normalize_arch,$(SOURCE_ARCH))
TARGET_ARCH := $(call normalize_arch,$(TARGET_ARCH))
PPROF_ENABLED ?= false
BUILD_TAGS ?=

ifeq ($(PPROF_ENABLED),true)
BUILD_TAGS := $(BUILD_TAGS) pprof
endif

BIN_OUTPUT_PATH = bin/$(TARGET_OS)-$(TARGET_ARCH)
TOOL_BIN = bin/gotools/$(shell uname -s)-$(shell uname -m)
BUILD_TAG_FILE := .build_tags

FFMPEG_TAG ?= n6.1
FFMPEG_VERSION ?= $(shell pwd)/FFmpeg/$(FFMPEG_TAG)
Expand Down Expand Up @@ -47,11 +54,17 @@ GOFLAGS := -buildvcs=false
export PKG_CONFIG_PATH=$(FFMPEG_BUILD)/lib/pkgconfig
export PATH := $(PATH):$(shell go env GOPATH)/bin

.PHONY: lint tool-install test clean module
.PHONY: lint tool-install test clean module build build-pprof

build: $(BIN_OUTPUT_PATH)/video-store

$(BIN_OUTPUT_PATH)/video-store: *.go cam/*.go $(FFMPEG_BUILD)
build-pprof:
$(MAKE) build PPROF_ENABLED=true

$(BIN_OUTPUT_PATH)/video-store: *.go cam/*.go $(FFMPEG_BUILD) $(BUILD_TAG_FILE)
go mod tidy
CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS=$(CGO_CFLAGS) go build -o $(BIN_OUTPUT_PATH)/video-store main.go
CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS=$(CGO_CFLAGS) go build -tags "$(BUILD_TAGS)" -o $(BIN_OUTPUT_PATH)/video-store main.go
echo "$(BUILD_TAGS)" > $(BUILD_TAG_FILE)

$(FFMPEG_VERSION_PLATFORM):
git clone https://github.com/FFmpeg/FFmpeg.git --depth 1 --branch $(FFMPEG_TAG) $(FFMPEG_VERSION_PLATFORM)
Expand All @@ -73,6 +86,10 @@ endif
endif
cd $(FFMPEG_VERSION_PLATFORM) && ./configure $(FFMPEG_OPTS) && $(MAKE) -j$(NPROC) && $(MAKE) install

# Force rebuild if BUILD_TAGS change
$(BUILD_TAG_FILE):
echo "$(BUILD_TAGS)" > $(BUILD_TAG_FILE)

tool-install:
GOBIN=`pwd`/$(TOOL_BIN) go install \
github.com/edaniels/golinters/cmd/combined \
Expand Down Expand Up @@ -107,5 +124,6 @@ module: $(BIN_OUTPUT_PATH)/video-store

clean:
rm -rf $(BIN_OUTPUT_PATH)
rm -f $(BUILD_TAG_FILE)
rm -rf FFmpeg
git clean -fxd
17 changes: 17 additions & 0 deletions pprof.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build pprof
// +build pprof

package main

import (
"log"
"net/http"
_ "net/http/pprof"
)

func init() {
go func() {
log.Println("Starting pprof server on :6060")
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
}

0 comments on commit e892656

Please sign in to comment.