diff options
author | Harald Welte <laforge@gnumonks.org> | 2014-05-08 19:18:01 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2014-05-08 19:18:01 +0200 |
commit | 7a04624563ac72b7237e39d6fcee5dab96f4d948 (patch) | |
tree | e97aa7567abe2c3f205c327ff3ef5d5d160fbd2e /src | |
parent | 8b5e0c7b81cba9f064bed97dc743e5a9a13818f1 (diff) |
Add cycle benchmarking support
This enables benchmarking of the codec. It will print
the amount of CPU cycles needed for encoding/decoding a single
20ms frame on average.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/benchmark.c | 55 | ||||
-rw-r--r-- | src/codec_efr.c | 5 | ||||
-rw-r--r-- | src/codec_fr.c | 9 | ||||
-rw-r--r-- | src/codec_hr.c | 13 | ||||
-rw-r--r-- | src/main.c | 3 |
6 files changed, 83 insertions, 4 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 818f215..788d425 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,7 +6,7 @@ AM_LDFLAGS=$(LIBOSMOCODEC_LIBS) $(LIBOSMOCORE_LIBS) \ COM_SOURCES = procqueue.c pq_file.c pq_format.c pq_codec.c pq_rtp.c \ formats.c fmt_amr.c fmt_gsm.c fmt_hr_ref.c fmt_racal.c \ - fmt_rawpcm.c fmt_ti.c \ + fmt_rawpcm.c fmt_ti.c benchmark.c \ codecs.c codec_pcm.c codec_hr.c codec_fr.c codec_efr.c bin_PROGRAMS = gapk diff --git a/src/benchmark.c b/src/benchmark.c new file mode 100644 index 0000000..e2c14a6 --- /dev/null +++ b/src/benchmark.c @@ -0,0 +1,55 @@ +/* + * This file is part of gapk (GSM Audio Pocket Knife). + * + * gapk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gapk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gapk. If not, see <http://www.gnu.org/licenses/>. + * + * (C) 2014 Harald Welte <laforge@gnumonks.org> + */ + +#include <stdio.h> + +#include <gapk/benchmark.h> + +struct benchmark_cycles codec_cycles[_CODEC_MAX]; + +void benchmark_dump(void) +{ + int i; + + for (i = 0; i < _CODEC_MAX; i++) { + struct benchmark_cycles *bc = &codec_cycles[i]; + unsigned long long total; + int j; + + if (bc->enc_used) { + total = 0; + for (j = 0; j < bc->enc_used; j++) + total += bc->enc[j]; + + printf("Codec %u (ENC): %llu cycles for %u frames => " + "%llu cycles/frame\n", i, total, bc->enc_used, + total / bc->enc_used); + } + + if (bc->dec_used) { + total = 0; + for (j = 0; j < bc->dec_used; j++) + total += bc->dec[j]; + + printf("Codec %u (DEC): %llu cycles for %u frames => " + "%llu cycles/frame\n", i, total, bc->dec_used, + total / bc->dec_used); + } + } +} diff --git a/src/codec_efr.c b/src/codec_efr.c index 141dec1..55bbd11 100644 --- a/src/codec_efr.c +++ b/src/codec_efr.c @@ -18,6 +18,7 @@ */ #include <gapk/codecs.h> +#include <gapk/benchmark.h> #include "config.h" @@ -68,6 +69,7 @@ codec_efr_encode(void *state, uint8_t *cod, const uint8_t *pcm) struct codec_efr_state *st = state; int rv; + BENCHMARK_START; rv = Encoder_Interface_Encode( st->encoder, MR122, @@ -75,6 +77,7 @@ codec_efr_encode(void *state, uint8_t *cod, const uint8_t *pcm) (unsigned char*) cod, 1 ); + BENCHMARK_STOP(CODEC_EFR, 1); return rv != 32; } @@ -84,12 +87,14 @@ codec_efr_decode(void *state, uint8_t *pcm, const uint8_t *cod) { struct codec_efr_state *st = state; + BENCHMARK_START; Decoder_Interface_Decode( st->decoder, (const unsigned char*) cod, (short *) pcm, 0 ); + BENCHMARK_STOP(CODEC_EFR, 0); return 0; } diff --git a/src/codec_fr.c b/src/codec_fr.c index 3b1bb7c..1bda210 100644 --- a/src/codec_fr.c +++ b/src/codec_fr.c @@ -18,6 +18,7 @@ */ #include <gapk/codecs.h> +#include <gapk/benchmark.h> #include "config.h" @@ -54,7 +55,9 @@ codec_fr_encode(void *state, uint8_t *cod, const uint8_t *pcm) gsm gh = (gsm)state; uint8_t pcm_b[2*160]; /* local copy as libgsm src isn't const ! */ memcpy(pcm_b, pcm, 2*160); + BENCHMARK_START; gsm_encode(gh, (gsm_signal*)pcm, (gsm_byte*)cod); + BENCHMARK_STOP(CODEC_FR, 1); return 0; } @@ -63,8 +66,12 @@ codec_fr_decode(void *state, uint8_t *pcm, const uint8_t *cod) { gsm gh = (gsm)state; uint8_t cod_b[33]; /* local copy as libgsm src isn't const ! */ + int rc; memcpy(cod_b, cod, 33); - return gsm_decode(gh, (gsm_byte*)cod_b, (gsm_signal*)pcm); + BENCHMARK_START; + rc = gsm_decode(gh, (gsm_byte*)cod_b, (gsm_signal*)pcm); + BENCHMARK_STOP(CODEC_FR, 1); + return rc; } #endif /* HAVE_LIBGSM */ diff --git a/src/codec_hr.c b/src/codec_hr.c index 26a75a5..d0e09ce 100644 --- a/src/codec_hr.c +++ b/src/codec_hr.c @@ -18,6 +18,7 @@ */ #include <gapk/codecs.h> +#include <gapk/benchmark.h> #include "config.h" @@ -43,14 +44,22 @@ static int codec_hr_encode(void *_state, uint8_t *cod, const uint8_t *pcm) { struct gsmhr *state = _state; - return gsmhr_encode(state, (int16_t *)cod, (const int16_t *)pcm); + int rc; + BENCHMARK_START; + rc = gsmhr_encode(state, (int16_t *)cod, (const int16_t *)pcm); + BENCHMARK_STOP(CODEC_HR, 1); + return rc; } static int codec_hr_decode(void *_state, uint8_t *pcm, const uint8_t *cod) { struct gsmhr *state = _state; - return gsmhr_decode(state, (int16_t *)pcm, (const int16_t *)cod); + int rc; + BENCHMARK_START; + rc = gsmhr_decode(state, (int16_t *)pcm, (const int16_t *)cod); + BENCHMARK_STOP(CODEC_HR, 0); + return rc; } #endif /* HAVE_LIBGSMHR */ @@ -34,6 +34,7 @@ #include <gapk/codecs.h> #include <gapk/formats.h> #include <gapk/procqueue.h> +#include <gapk/benchmark.h> struct gapk_options @@ -557,6 +558,8 @@ error: /* Release processing queue */ pq_destroy(gs->pq); + + benchmark_dump(); return rv; } |