summaryrefslogtreecommitdiff
path: root/apps/talk.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2013-07-02 08:24:00 +0200
committerThomas Martitz <kugel@rockbox.org>2014-02-02 19:40:39 +0100
commitdac40fdd60872da55b60ae9912b31e6549f1cf4a (patch)
tree76a0571260eb097d8936bd33edf15120dd2ef158 /apps/talk.c
parent57000b513bd54b9dba3b308b7734c88962b81ae3 (diff)
downloadrockbox-dac40fdd60872da55b60ae9912b31e6549f1cf4a.tar.gz
rockbox-dac40fdd60872da55b60ae9912b31e6549f1cf4a.zip
talk: Add debug menu entry to view statistics about talk engine.
This engine includes voicefile, memory usage and cache hits/misses for TALK_PARTIAL_LOAD. Change-Id: I331981ddda39ea30c57b4b74504accb3c556c3b9
Diffstat (limited to 'apps/talk.c')
-rw-r--r--apps/talk.c61
1 files changed, 59 insertions, 2 deletions
diff --git a/apps/talk.c b/apps/talk.c
index 88d9afab90..0904e41c3b 100644
--- a/apps/talk.c
+++ b/apps/talk.c
@@ -123,6 +123,7 @@ static uint8_t clip_age[QUEUE_SIZE];
123#if QUEUE_SIZE > 255 123#if QUEUE_SIZE > 255
124# error clip_age[] type too small 124# error clip_age[] type too small
125#endif 125#endif
126static int cache_hits, cache_misses;
126#endif 127#endif
127 128
128/* Multiple thumbnails can be loaded back-to-back in this buffer. */ 129/* Multiple thumbnails can be loaded back-to-back in this buffer. */
@@ -165,6 +166,7 @@ struct queue_entry /* one entry of the internal queue */
165 166
166static struct queue_entry queue[QUEUE_SIZE]; /* queue of scheduled clips */ 167static struct queue_entry queue[QUEUE_SIZE]; /* queue of scheduled clips */
167 168
169#define DEFAULT_VOICE_LANG "english"
168 170
169/***************** Private implementation *****************/ 171/***************** Private implementation *****************/
170 172
@@ -294,7 +296,7 @@ static struct buflib_callbacks index_ops = {
294static int open_voicefile(void) 296static int open_voicefile(void)
295{ 297{
296 char buf[64]; 298 char buf[64];
297 char* p_lang = "english"; /* default */ 299 char* p_lang = DEFAULT_VOICE_LANG; /* default */
298 300
299 if ( global_settings.lang_file[0] && 301 if ( global_settings.lang_file[0] &&
300 global_settings.lang_file[0] != 0xff ) 302 global_settings.lang_file[0] != 0xff )
@@ -344,6 +346,7 @@ static int get_clip(long id, long* p_size)
344 ssize_t ret; 346 ssize_t ret;
345 int fd, idx = 0; 347 int fd, idx = 0;
346 unsigned char *voicebuf; 348 unsigned char *voicebuf;
349 cache_misses++;
347 if (id == VOICE_PAUSE) { 350 if (id == VOICE_PAUSE) {
348 idx = QUEUE_SIZE; /* we keep VOICE_PAUSE loaded */ 351 idx = QUEUE_SIZE; /* we keep VOICE_PAUSE loaded */
349 } else { 352 } else {
@@ -397,6 +400,7 @@ static int get_clip(long id, long* p_size)
397 else 400 else
398 { /* clip is in memory already */ 401 { /* clip is in memory already */
399 /* Find where it was loaded */ 402 /* Find where it was loaded */
403 cache_hits++;
400 if (id == VOICE_PAUSE) { 404 if (id == VOICE_PAUSE) {
401 retval = QUEUE_SIZE * max_clipsize; 405 retval = QUEUE_SIZE * max_clipsize;
402 } else { 406 } else {
@@ -583,7 +587,6 @@ load_err_free:
583 return false; 587 return false;
584} 588}
585 589
586
587/* called in ISR context (on HWCODEC) if mp3 data got consumed */ 590/* called in ISR context (on HWCODEC) if mp3 data got consumed */
588static void mp3_callback(const void** start, size_t* size) 591static void mp3_callback(const void** start, size_t* size)
589{ 592{
@@ -1456,3 +1459,57 @@ void talk_time(const struct tm *tm, bool enqueue)
1456} 1459}
1457 1460
1458#endif /* CONFIG_RTC */ 1461#endif /* CONFIG_RTC */
1462
1463
1464bool talk_get_debug_data(struct talk_debug_data *data)
1465{
1466 char* p_lang = DEFAULT_VOICE_LANG; /* default */
1467
1468 memset(data, 0, sizeof(*data));
1469
1470 if (!has_voicefile || index_handle <= 0)
1471 return false;
1472
1473 if (global_settings.lang_file[0] && global_settings.lang_file[0] != 0xff)
1474 p_lang = (char *)global_settings.lang_file;
1475
1476 struct clip_entry *clips = core_get_data(index_handle);
1477#ifdef TALK_PARTIAL_LOAD
1478 int cached = 0;
1479#endif
1480 int real_clips = 0;
1481
1482 strlcpy(data->voicefile, p_lang, sizeof(data->voicefile));
1483 data->num_clips = voicefile.id1_max + voicefile.id2_max;
1484 data->avg_clipsize = data->max_clipsize = 0;
1485 data->min_clipsize = INT_MAX;
1486 for(int i = 0; i < data->num_clips; i++)
1487 {
1488 int size = clips[i].size & (~LOADED_MASK);
1489 if (!size) continue;
1490 real_clips += 1;
1491 if (size < data->min_clipsize)
1492 data->min_clipsize = size;
1493 if (size > data->max_clipsize)
1494 data->max_clipsize = size;
1495 data->avg_clipsize += size;
1496#ifdef TALK_PARTIAL_LOAD
1497 if (clips[i].size & LOADED_MASK)
1498 cached++;
1499#endif
1500 }
1501 data->avg_clipsize /= real_clips;
1502 data->num_empty_clips = data->num_clips - real_clips;
1503 data->memory_allocated = voicefile_size + size_for_thumbnail;
1504 data->memory_used = voicefile_size + thumbnail_buf_used;
1505#ifdef TALK_PARTIAL_LOAD
1506 data->cached_clips = cached;
1507 data->cache_hits = cache_hits;
1508 data->cache_misses = cache_misses;
1509#else
1510 data->cached_clips = real_clips;
1511 data->cache_hits = data->cache_misses = -1;
1512#endif
1513
1514 return true;
1515}