diff options
Diffstat (limited to 'hifi/xaf/hifi-dpf/include/xa_profiler.h')
-rw-r--r-- | hifi/xaf/hifi-dpf/include/xa_profiler.h | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/hifi/xaf/hifi-dpf/include/xa_profiler.h b/hifi/xaf/hifi-dpf/include/xa_profiler.h new file mode 100644 index 00000000..675ff15c --- /dev/null +++ b/hifi/xaf/hifi-dpf/include/xa_profiler.h @@ -0,0 +1,156 @@ +/******************************************************************************* +* Copyright (C) 2018 Cadence Design Systems, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to use this Software with Cadence processor cores only and +* not with any other processors and platforms, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +******************************************************************************/ + +#ifndef __XA_PROFILER_H__ +#define __XA_PROFILER_H__ + +#if !defined(PROFILE) && __XCC__ +#define PROFILE 1 +#endif + +#if !defined(PREFETCH_CTL) && __XCC__ +#define PREFETCH_CTL 1 +#endif + +#ifdef PROFILE +#include <xtensa/hal.h> +#include <sys/times.h> + +#include "xa_type_def.h" +#include "xa_timer.h" + +TRACE_TAG(MCPS,1); + +typedef struct XA_PROFILER { +#if 1 + unsigned long cstart; + unsigned long cstop; + unsigned long cycles; + unsigned long g_output_bytes; + unsigned long Peak; + unsigned long Sum; + + unsigned long sample_rate; + unsigned long channels; + unsigned long pcm_width; +#else + struct tms start; + struct tms stop; + double Peak; + double Sum; + long long cycles; +#endif + int Peak_frame; + int frame_count; + long long output_bytes; + long long total_cycles; + long long total_samples; + char *id; +} xa_profiler; + +extern xa_profiler prof; + +static inline void xa_compute_mcps(xa_profiler *p_prof, WORD32 samples_decoded, UWORD32 samp_freq, long long gen_strm_pos) +{ + double Ave=0.0, Curr; + + if (samples_decoded <= 0) + return; + + p_prof->total_samples += samples_decoded; + p_prof->frame_count++; + + clock_t cycles = p_prof->cycles; + p_prof->total_cycles = 0; + Curr = ((double) cycles / samples_decoded * samp_freq / 1000000); + + if (p_prof->frame_count > 1) { + p_prof->Sum += Curr; + Ave = p_prof->Sum / (p_prof->frame_count-1); + + if (p_prof->Peak < Curr) { + p_prof->Peak = Curr; + p_prof->Peak_frame = (p_prof->frame_count); + } + } + + unsigned long long total_msec = + (unsigned long long)((double)p_prof->total_samples / samp_freq * 1000.0); + int msec = (int)(total_msec % 1000); + unsigned long long total_seconds = total_msec / 1000; + int seconds = (int)(total_seconds % 60); + int minutes = (int)(total_seconds / 60); + +#if 1 + TRACE(MCPS, _b("[%d] %d:%d.%d MCPS: %d Average: %d samples: %d\n"), + p_prof->frame_count, (uint32_t)minutes, (uint32_t)seconds, (uint32_t)msec, + (uint32_t)Curr, (uint32_t)Ave, samples_decoded); +#else + TRACE(MCPS, _b("[%d|%lld] %d:%02d.%03d MCPS: %.2f Average: %.2f Peak: %.2f @ [%d] %s\n"), + p_prof->frame_count, gen_strm_pos, minutes, seconds, msec, + Curr, Ave, p_prof->Peak, p_prof->Peak_frame, p_prof->id); +#endif + + /* reset counters */ + p_prof->g_output_bytes = 0; + p_prof->cycles = 0; +} + +#define INIT_XA_PROFILER(x, a) do { memset(&x, 0, sizeof(xa_profiler)); \ + x.sample_rate = 48000;\ + x.channels = 2;\ + x.pcm_width = 16;\ + x.id = a; } while(0) + +#define START_TIME_XA_PROFILER(x) do { set_ccount(0); \ + x.cstart=read_ccount(); } while(0) +#define STOP_TIME_XA_PROFILER(x) do { x.cstop =read_ccount(); \ + x.cycles += (x.cstop - x.cstart); } while(0) +#define COMPUTE_MHZ_XA_PROFILER(x, a, b, c) do { xa_compute_mcps(&x, a, b, c); } while(0) +#define SUMMARY_XA_PROFILER(x) do { fprintf(stdout,"\n%5s Peak MCPS = %f\n", x.id, x.Peak); \ + fprintf(stdout,"%5s Peak frame = %d\n", x.id, x.Peak_frame); \ + fprintf(stdout,"%5s Average MCPS = %f\n", x.id, (x.frame_count < 2) ? 0 : (x.Sum/(x.frame_count-1))); } while(0) + +#else + +typedef struct XA_PROFILER { + int place_holder; +} xa_profiler; + +#define INIT_XA_PROFILER(x, a) do {} while(0) +#define START_TIME_XA_PROFILER(x) do {} while(0) +#define STOP_TIME_XA_PROFILER(x) do {} while(0) +#define COMPUTE_MHZ_XA_PROFILER(x, a, b) do {} while(0) +#define SUMMARY_XA_PROFILER(x) do {} while(0) +#endif + +#ifdef PREFETCH_CTL +#define PREFETCH_AGGRESSIVE(x) do { x = xthal_set_cache_prefetch ((XTHAL_DCACHE_PREFETCH_HIGH | XTHAL_ICACHE_PREFETCH_HIGH)); \ + } while(0) +#define PREFETCH_RESTORE(x) do { xthal_set_cache_prefetch (x); } while(0) +#else +#define PREFETCH_AGGRESSIVE(x) do {} while(0) +#define PREFETCH_RESTORE(x) do {} while(0) +#endif + +#endif /* __XA_PROFILER_H__ */ + |