From f31b5a69157ad7ca0371e92e57073477622db771 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Tue, 27 Aug 2019 22:29:46 +0000 Subject: [PATCH] Add benchmark for zrle --- .gitignore | 7 ++++-- Makefile | 11 +++++++-- bench/zrle-bench.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ inc/util.h | 2 ++ src/server.c | 2 ++ src/zrle.c | 4 ---- 6 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 bench/zrle-bench.c diff --git a/.gitignore b/.gitignore index d957e69..c678d63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ .clang_complete -src/*.o -src/*.o.deps +*/*.o +*/*.o.deps neatvnc vgcore.* +perf.data +perf.data.old +zrle-bench diff --git a/Makefile b/Makefile index 88b26a2..f4afc79 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ all: neatvnc DEPENDENCIES := pixman-1 libpng libuv -CFLAGS := -g -O0 -std=gnu11 -D_GNU_SOURCE -Iinc \ +CFLAGS := -g -O3 -DNDEBUG -std=gnu11 -D_GNU_SOURCE -Iinc \ $(foreach dep,$(DEPENDENCIES),$(shell pkg-config --cflags $(dep))) LDFLAGS := $(foreach dep,$(DEPENDENCIES),$(shell pkg-config --libs $(dep))) @@ -10,13 +10,20 @@ LDFLAGS := $(foreach dep,$(DEPENDENCIES),$(shell pkg-config --libs $(dep))) neatvnc: src/server.o src/util.o src/vec.o src/zrle.o src/pngfb.o $(CC) $^ $(LDFLAGS) -o $@ +zrle-bench: bench/zrle-bench.o src/server.o src/util.o src/vec.o src/zrle.o \ + src/pngfb.o + $(CC) $^ $(LDFLAGS) -o $@ + src/%.o: src/%.c $(CC) -c $(CFLAGS) $< -o $@ -MMD -MP -MF $@.deps +bench/%.o: bench/%.c + $(CC) -c $(CFLAGS) $< -o $@ -MMD -MP -MF $@.deps + .PHONY: clean clean: rm -f neatvnc - rm -f src/*.o src/*.deps + rm -f src/*.o src/*.deps bench/*.o bench/*.deps -include src/*.deps diff --git a/bench/zrle-bench.c b/bench/zrle-bench.c new file mode 100644 index 0000000..eead1f8 --- /dev/null +++ b/bench/zrle-bench.c @@ -0,0 +1,59 @@ +#include "zrle.h" +#include "rfb-proto.h" +#include "util.h" +#include "vec.h" + +#include +#include +#include + +int read_png_file(struct vnc_framebuffer* fb, const char *filename); + +int run_benchmark(const char *image) +{ + int rc = -1; + + struct vnc_framebuffer fb; + rc = read_png_file(&fb, image); + if (rc < 0) + return -1; + + struct rfb_pixel_format pixfmt; + rfb_pixfmt_from_fourcc(&pixfmt, DRM_FORMAT_ARGB8888); + + struct pixman_region16 region; + pixman_region_init(®ion); + + pixman_region_union_rect(®ion, ®ion, 0, 0, fb.width, fb.height); + + struct vec frame; + vec_init(&frame, fb.width * fb.height * 3 / 2); + + rc = zrle_encode_frame(&frame, &pixfmt, fb.addr, &pixfmt, + fb.width, fb.height, ®ion); + + if (rc < 0) + goto failure; + + rc = 0; +failure: + pixman_region_fini(®ion); + vec_destroy(&frame); + free(fb.addr); + return 0; +} + +int main(int argc, char *argv[]) +{ + int rc = 0; + + char *image = argv[1]; + + if (image) + return run_benchmark(image) < 0 ? 1 :0; + + rc |= run_benchmark("test-images/tv-test-card.png") < 0 ? 1 : 0; + rc |= run_benchmark("test-images/lena-soderberg.png") < 0 ? 1 : 0; + + return rc; +} diff --git a/inc/util.h b/inc/util.h index 4567c52..2630c17 100644 --- a/inc/util.h +++ b/inc/util.h @@ -19,4 +19,6 @@ struct vnc_write_request { int vnc__write(uv_stream_t *stream, const void *payload, size_t size, uv_write_cb on_done); +int rfb_pixfmt_from_fourcc(struct rfb_pixel_format *dst, uint32_t src); + #endif /* _VNC_UTIL_H_ */ diff --git a/src/server.c b/src/server.c index 17940d5..80fe04e 100644 --- a/src/server.c +++ b/src/server.c @@ -685,6 +685,7 @@ failure: int read_png_file(struct vnc_framebuffer* fb, const char *filename); +/* int main(int argc, char *argv[]) { if (!argv[1]) { @@ -709,3 +710,4 @@ int main(int argc, char *argv[]) uv_run(uv_default_loop(), UV_RUN_DEFAULT); } +*/ diff --git a/src/zrle.c b/src/zrle.c index 09149af..c4297b7 100644 --- a/src/zrle.c +++ b/src/zrle.c @@ -235,9 +235,6 @@ int zrle_encode_box(struct vec* out, const struct rfb_pixel_format *dst_fmt, int tile_width = width - tile_x >= 64 ? 64 : width - tile_x; int tile_height = height - tile_y >= 64 ? 64 : height - tile_y; - printf("Encoding tile @ %dx%d. width: %d, height: %d\n", tile_x, - tile_y, tile_width, tile_height); - zrle_encode_tile(&in, dst_fmt, ((uint32_t*)src) + tile_x + tile_y * width, src_fmt, stride, tile_width, tile_height); @@ -251,7 +248,6 @@ int zrle_encode_box(struct vec* out, const struct rfb_pixel_format *dst_fmt, /* There seems to be something extra at the end */ out->len -= 4; - printf("Encoded with size: %lu\n", out->len - size_index); uint32_t out_size = htonl(out->len - size_index - 4); memcpy(((uint8_t*)out->data) + size_index, &out_size, sizeof(out_size));