Cleaned up benchmark running code. Using a weak reference so profiled programs do not need to link in libdl to build with progress points.

This commit is contained in:
Charlie Curtsinger 2019-08-18 17:32:02 -05:00
parent 46691ac521
commit 7abaffec9f
15 changed files with 90 additions and 137 deletions

4
.gitignore vendored
View File

@ -18,8 +18,8 @@ benchmarks/word_count/word_count
benchmarks/histogram/histogram_datafiles
benchmarks/linear_regression/linear_regression_datafiles
benchmarks/matrix_multiply/.input_bench
benchmarks/matrix_multiply/.input_test
benchmarks/matrix_multiply/.input_large
benchmarks/matrix_multiply/.input_small
benchmarks/matrix_multiply/matrix_file_A.txt
benchmarks/matrix_multiply/matrix_file_B.txt
benchmarks/matrix_multiply/matrix_file_out_pthreads.txt

View File

@ -34,7 +34,7 @@ $ make
## Using Coz
Using coz requires a small amount of setup, but you can jump ahead to the section on the included [sample applications](#sample-applications) in this repository if you want to try coz right away.
To run your program with coz, you will need to build it with debug information. You do not need to include debug symbols in the main executable: coz uses the same procedure as `gdb` to locate debug information for stripped binaries. If you plan to use your program with progress points (see below), you also need to link your program with the dynamic loader library by specifying the `-ldl` option.
To run your program with coz, you will need to build it with debug information. You do not need to include debug symbols in the main executable: coz uses the same procedure as `gdb` to locate debug information for stripped binaries.
Once you have your program built with debug information, you can run it with coz using the command `coz run {coz options} --- {program name and arguments}`. But, to produce a useful profile you need to decide which part(s) of the application you want to speed up by specifying one or more progress points.

23
benchmark.mk Normal file
View File

@ -0,0 +1,23 @@
include $(ROOT)/common.mk
RECURSIVE_TARGETS += bench bench_large bench_small
ifeq ($(USE_SYSTEM_COZ),)
CFLAGS += -I$(ROOT)/include
CXXFLAGS += -I$(ROOT)/include
endif
# Set up build targets for benchmarking
large_inputs:
small_inputs:
bench:: bench_large
bench_large:: $(OTHER_TARGETS) large_inputs
@echo $(LOG_PREFIX) Running benchmark on large input $(LOG_SUFFIX)
$(COZ) run $(COZ_ARGS) --- ./$< $(BENCH_LARGE_ARGS)
bench_small:: $(OTHER_TARGETS) small_inputs
@echo $(LOG_PREFIX) Running benchmark on small input $(LOG_SUFFIX)
$(COZ) run $(COZ_ARGS) --- ./$< $(BENCH_SMALL_ARGS)

View File

@ -1,22 +1,16 @@
ROOT := ../..
TARGETS := histogram
LIBS := pthread dl
LIBS := pthread
CFLAGS := -g -O2
ifeq ($(USE_SYSTEM_COZ),)
CFLAGS += -I$(ROOT)/include
endif
include $(ROOT)/benchmark.mk
BENCHMARK := 1
BENCH_LARGE_ARGS := histogram_datafiles/large.bmp
BENCH_SMALL_ARGS := histogram_datafiles/small.bmp
include $(ROOT)/common.mk
large_inputs: histogram_datafiles/large.bmp
BENCH_ARGS := histogram_datafiles/large.bmp
TEST_ARGS := histogram_datafiles/small.bmp
bench_inputs: histogram_datafiles/large.bmp
test_inputs: histogram_datafiles/small.bmp
small_inputs: histogram_datafiles/small.bmp
histogram_datafiles/%:
@echo $(LOG_PREFIX) Downloading histogram inputs $(LOG_SUFFIX)

View File

@ -1,15 +1,9 @@
ROOT := ../..
TARGETS := kmeans
LIBS := pthread dl
LIBS := pthread
CFLAGS := -g -O2
ifeq ($(USE_SYSTEM_COZ),)
CFLAGS += -I$(ROOT)/include
endif
include $(ROOT)/benchmark.mk
BENCHMARK := 1
include $(ROOT)/common.mk
BENCH_ARGS := -d 3 -c 100 -p 100000 -s 1000
TEST_ARGS := -d 3 -c 100 -p 10000 -s 100
BENCH_LARGE_ARGS := -d 3 -c 100 -p 100000 -s 1000
BENCH_SMALL_ARGS := -d 3 -c 100 -p 10000 -s 100

View File

@ -1,22 +1,16 @@
ROOT := ../..
TARGETS := linear_regression
LIBS := pthread dl
LIBS := pthread
CFLAGS := -g -O2
ifeq ($(USE_SYSTEM_COZ),)
CFLAGS += -I$(ROOT)/include
endif
include $(ROOT)/benchmark.mk
BENCHMARK := 1
BENCH_LARGE_ARGS := linear_regression_datafiles/key_file_500MB.txt
BENCH_SMALL_ARGS := linear_regression_datafiles/key_file_50MB.txt
include $(ROOT)/common.mk
large_inputs: linear_regression_datafiles/key_file_500MB.txt
BENCH_ARGS := linear_regression_datafiles/key_file_500MB.txt
TEST_ARGS := linear_regression_datafiles/key_file_50MB.txt
bench_inputs: linear_regression_datafiles/key_file_500MB.txt
test_inputs: linear_regression_datafiles/key_file_50MB.txt
small_inputs: linear_regression_datafiles/key_file_50MB.txt
linear_regression_datafiles/%:
@echo $(LOG_PREFIX) Downloading linear_regression inputs $(LOG_SUFFIX)

View File

@ -1,31 +1,25 @@
ROOT := ../..
TARGETS := matrix_multiply
LIBS := pthread dl
LIBS := pthread
CFLAGS := -g -O2 -Wno-format
ifeq ($(USE_SYSTEM_COZ),)
CFLAGS += -I$(ROOT)/include
endif
include $(ROOT)/benchmark.mk
BENCHMARK := 1
BENCH_LARGE_ARGS := 1000 > /dev/null
BENCH_SMALL_ARGS := 400 > /dev/null
include $(ROOT)/common.mk
large_inputs: .input_large
BENCH_ARGS := 1000 > /dev/null
TEST_ARGS := 400 > /dev/null
small_inputs: .input_small
bench_inputs: .input_bench
test_inputs: .input_test
.input_bench:
.input_large: matrix_multiply
@echo $(LOG_PREFIX) Generating bench input $(LOG_SUFFIX)
@./matrix_multiply 1000 1000 > /dev/null
@rm -f .input_test
@touch .input_bench
@rm -f .input_small
@touch .input_large
.input_test:
.input_small: matrix_multiply
@echo $(LOG_PREFIX) Generating test input $(LOG_SUFFIX)
@./matrix_multiply 400 400 > /dev/null
@rm -f .input_bench
@touch .input_test
@rm -f .input_large
@touch .input_small

View File

@ -1,24 +1,15 @@
ROOT := ../..
TARGETS := pbzip2
LIBS := bz2 pthread dl
LIBS := bz2 pthread
CXXFLAGS := -g -O2 -Wno-format -Ibzip2-1.0.6
LDFLAGS := -Lbzip2-1.0.6
ifeq ($(USE_SYSTEM_COZ),)
CXXFLAGS += -I$(ROOT)/include
endif
BENCHMARK := 1
include $(ROOT)/common.mk
include $(ROOT)/benchmark.mk
# pbzip2 depends on the libbz2 library
pbzip2: bzip2-1.0.6/libbz2.a
# Download and build libbz2
# This no longer works: wget -c http://bzip.org/1.0.6/bzip2-1.0.6.tar.gz
# Replaced with a fossies.org link
bzip2-1.0.6/libbz2.a:
@echo $(LOG_PREFIX) Downloading libbz2 $(LOG_SUFFIX)
@wget -c https://sourceware.org/pub/bzip2/bzip2-1.0.6.tar.gz
@ -28,12 +19,12 @@ bzip2-1.0.6/libbz2.a:
@cd bzip2-1.0.6; $(MAKE) CFLAGS=-g > /dev/null
@rm bzip2-1.0.6.tar.gz
BENCH_ARGS := -c < data/key_file_500MB.txt > data/key_file_500MB_compressed.bz2
TEST_ARGS := -c < data/key_file_50MB.txt > data/key_file_50MB_compressed.bz2
BENCH_LARGE_ARGS := -c < data/key_file_500MB.txt > data/key_file_500MB_compressed.bz2
BENCH_SMALL_ARGS := -c < data/key_file_50MB.txt > data/key_file_50MB_compressed.bz2
bench_inputs: data/key_file_500MB.txt
large_inputs: data/key_file_500MB.txt
test_inputs: data/key_file_50MB.txt
small_inputs: data/key_file_50MB.txt
data/%:
@echo $(LOG_PREFIX) Downloading pbzip2 inputs $(LOG_SUFFIX)

View File

@ -1,15 +1,9 @@
ROOT := ../..
TARGETS := pca
LIBS := pthread dl
LIBS := pthread
CFLAGS := -g -O2
ifeq ($(USE_SYSTEM_COZ),)
CFLAGS += -I$(ROOT)/include
endif
include $(ROOT)/benchmark.mk
BENCHMARK := 1
include $(ROOT)/common.mk
BENCH_ARGS := > /dev/null
TEST_ARGS := > /dev/null
BENCH_LARGE_ARGS := > /dev/null
BENCH_SMALL_ARGS := > /dev/null

View File

@ -1,12 +1,6 @@
ROOT := ../..
TARGETS := producer_consumer
LIBS := dl pthread
LIBS := pthread
CXXFLAGS := -g -O2
ifeq ($(USE_SYSTEM_COZ),)
CXXFLAGS += -I$(ROOT)/include
endif
BENCHMARK := 1
include $(ROOT)/common.mk
include $(ROOT)/benchmark.mk

View File

@ -1,22 +1,16 @@
ROOT := ../..
TARGETS := string_match
LIBS := pthread dl
LIBS := pthread
CFLAGS := -g -O2
ifeq ($(USE_SYSTEM_COZ),)
CFLAGS += -I$(ROOT)/include
endif
include $(ROOT)/benchmark.mk
BENCHMARK := 1
BENCH_LARGE_ARGS := string_match_datafiles/key_file_500MB.txt > /dev/null
BENCH_SMALL_ARGS := string_match_datafiles/key_file_50MB.txt > /dev/null
include $(ROOT)/common.mk
large_inputs: string_match_datafiles/key_file_500MB.txt
BENCH_ARGS := string_match_datafiles/key_file_500MB.txt > /dev/null
TEST_ARGS := string_match_datafiles/key_file_50MB.txt > /dev/null
bench_inputs: string_match_datafiles/key_file_500MB.txt
test_inputs: string_match_datafiles/key_file_50MB.txt
small_inputs: string_match_datafiles/key_file_50MB.txt
string_match_datafiles/%:
@echo $(LOG_PREFIX) Downloading string_match inputs $(LOG_SUFFIX)

View File

@ -1,12 +1,6 @@
ROOT := ../..
TARGETS := toy
LIBS := dl pthread
LIBS := pthread
CXXFLAGS := --std=c++11 -g -O2
ifeq ($(USE_SYSTEM_COZ),)
CFLAGS += -I$(ROOT)/include
endif
BENCHMARK := 1
include $(ROOT)/common.mk
include $(ROOT)/benchmark.mk

View File

@ -1,22 +1,16 @@
ROOT := ../..
TARGETS := word_count
LIBS := pthread dl
LIBS := pthread
CFLAGS := -g -O2
ifeq ($(USE_SYSTEM_COZ),)
CFLAGS += -I$(ROOT)/include
endif
include $(ROOT)/benchmark.mk
BENCHMARK := 1
BENCH_LARGE_ARGS := word_count_datafiles/word_100MB.txt
BENCH_SMALL_ARGS := word_count_datafiles/word_10MB.txt
include $(ROOT)/common.mk
large_inputs: word_count_datafiles/word_100MB.txt
BENCH_ARGS := word_count_datafiles/word_100MB.txt
TEST_ARGS := word_count_datafiles/word_10MB.txt
bench_inputs: word_count_datafiles/word_100MB.txt
test_inputs: word_count_datafiles/word_10MB.txt
small_inputs: word_count_datafiles/word_10MB.txt
word_count_datafiles/%:
@echo $(LOG_PREFIX) Downloading word_count inputs $(LOG_SUFFIX)

View File

@ -33,7 +33,7 @@ OBJS ?= $(addprefix obj/,$(patsubst %.cpp,%.o,$(patsubst %.c,%.o,$(SRCS))))
.PHONY: all clean distclean bench test
# Targets to build recirsively into $(DIRS)
RECURSIVE_TARGETS ?= all clean bench test install check
RECURSIVE_TARGETS ?= all clean bench bench_large bench_small test install check
# Targets separated by type
SHARED_LIB_TARGETS := $(filter %.so, $(TARGETS))
@ -53,7 +53,7 @@ MAKEFLAGS += -j
# Build all targets by default, unless this is a benchmark
all:: $(TARGETS)
# Clean up after a bild
# Clean up after a build
clean::
@for t in $(TARGETS); do \
echo $(LOG_PREFIX) Cleaning $$t $(LOG_SUFFIX); \
@ -90,21 +90,6 @@ $(OTHER_TARGETS): $(OBJS)
@echo $(LOG_PREFIX) Linking $@ $(LOG_SUFFIX)
@$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
# Set up build targets for benchmarking
ifneq ($(BENCHMARK),)
bench_inputs:
test_inputs:
bench:: $(OTHER_TARGETS) bench_inputs
@echo $(LOG_PREFIX) Running benchmark on full input $(LOG_SUFFIX)
$(COZ) run $(COZ_ARGS) --- ./$< $(BENCH_ARGS)
test:: $(OTHER_TARGETS) test_inputs
@echo $(LOG_PREFIX) Running benchmark on test input $(LOG_SUFFIX)
$(COZ) run $(COZ_ARGS) --- ./$< $(TEST_ARGS)
endif
# Include dependency rules for all objects
-include $(OBJS:.o=.d)

View File

@ -28,6 +28,14 @@ extern "C" {
#define COZ_COUNTER_TYPE_BEGIN 2
#define COZ_COUNTER_TYPE_END 3
// Declare dlsym as a weak reference so libdl isn't required
void* dlsym(void* handle, const char* symbol) __attribute__((weak, alias("__null_dlsym")));
// When running without libdl (e.g. without coz) this is the function that runs when calling dlsym
static void* __null_dlsym(void* handle, const char* symbol) {
return NULL;
}
// Counter info struct, containing both a counter and backoff size
typedef struct {
size_t count; // The actual count