mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
Introduce logging to disk feature into rockbox.
Logs information, errors, etc to disk using the register_storage_idle_func mechanism to write to the disk when available. Currently, this is disabled in normal builds, but can be enabled by adding ROCKBOX_HAS_LOGDISKF to the config file. By default, it uses a 2KB buffer and drops text if the buffer overflows. The system includes a simple warning level mechanism that can be used to by default exclude non-serious errors from logging on release builds. Change-Id: I0a3d186a93625c7c93dae37b993a0d37e5a3a925 Reviewed-on: http://gerrit.rockbox.org/288 Reviewed-by: Jonathan Gordon <rockbox@jdgordon.info> Tested-by: Michael Giacomelli <mgiacomelli@gmail.com> Reviewed-by: Michael Giacomelli <mgiacomelli@gmail.com>
This commit is contained in:
parent
7c31ff2fb0
commit
d46b090771
4 changed files with 190 additions and 27 deletions
|
@ -76,6 +76,7 @@
|
||||||
#include "skin_engine/skin_engine.h"
|
#include "skin_engine/skin_engine.h"
|
||||||
#include "statusbar-skinned.h"
|
#include "statusbar-skinned.h"
|
||||||
#include "bootchart.h"
|
#include "bootchart.h"
|
||||||
|
#include "logdiskf.h"
|
||||||
#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
|
#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
|
||||||
#include "notification.h"
|
#include "notification.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -489,6 +490,10 @@ static void init(void)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ROCKBOX_HAS_LOGDISKF
|
||||||
|
init_logdiskf();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if CONFIG_RTC
|
#if CONFIG_RTC
|
||||||
rtc_init();
|
rtc_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,7 +26,7 @@ target/hosted/debug-hosted.c
|
||||||
#endif
|
#endif
|
||||||
system.c
|
system.c
|
||||||
usb.c
|
usb.c
|
||||||
#ifdef ROCKBOX_HAS_LOGF
|
#if defined(ROCKBOX_HAS_LOGF) || defined(ROCKBOX_HAS_LOGDISKF)
|
||||||
logf.c
|
logf.c
|
||||||
#endif /* ROCKBOX_HAS_LOGF */
|
#endif /* ROCKBOX_HAS_LOGF */
|
||||||
kernel.c
|
kernel.c
|
||||||
|
|
81
firmware/export/logdiskf.h
Normal file
81
firmware/export/logdiskf.h
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* __________ __ ___.
|
||||||
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012 by Michael Giacomelli
|
||||||
|
*
|
||||||
|
* This program 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 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef LOGDISKF_H
|
||||||
|
#define LOGDISKF_H
|
||||||
|
#include <config.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "gcc_extensions.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
#ifdef ROCKBOX_HAS_LOGDISKF
|
||||||
|
|
||||||
|
void init_logdiskf(void);
|
||||||
|
|
||||||
|
#ifndef __PCTOOL__
|
||||||
|
|
||||||
|
/*large memory devices spin up the disk much less often*/
|
||||||
|
#if MEMORYSIZE > 32
|
||||||
|
#define MAX_LOGDISKF_SIZE 8192
|
||||||
|
#elif MEMORYSIZE > 8
|
||||||
|
#define MAX_LOGDISKF_SIZE 4096
|
||||||
|
#else
|
||||||
|
#define MAX_LOGDISKF_SIZE 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern unsigned char logdiskfbuffer[MAX_LOGDISKF_SIZE];
|
||||||
|
extern int logfdiskindex;
|
||||||
|
#endif /* __PCTOOL__ */
|
||||||
|
|
||||||
|
|
||||||
|
#define LOGDISK_LEVEL 1
|
||||||
|
|
||||||
|
#if LOGDISK_LEVEL > 0 /*serious errors or problems*/
|
||||||
|
#define ERRORF(...) _logdiskf(__func__,'E', __VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define ERRORF(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if LOGDISK_LEVEL > 1 /*matters of concern*/
|
||||||
|
#define WARNF(...) _logdiskf(__func__, 'W', __VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define WARNF(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if LOGDISK_LEVEL > 2 /*useful for debug only*/
|
||||||
|
#define NOTEF(...) _logdiskf(__func__, 'N', __VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define NOTEF(...) /*TODO: rename DEBUGF later*/
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*__FILE__ would be better but is difficult to make work with the build system*/
|
||||||
|
//#define logdiskf(...) _logdiskf(__func__, 1, __VA_ARGS__)
|
||||||
|
|
||||||
|
void _logdiskf(const char* file, const char level,
|
||||||
|
const char *format, ...) ATTRIBUTE_PRINTF(3, 4);
|
||||||
|
|
||||||
|
#else /* !ROCKBOX_HAS_LOGF */
|
||||||
|
|
||||||
|
/* built without logdiskf() support enabled, replace logdiskf() by DEBUGF() */
|
||||||
|
#define logdiskf(f,args...) DEBUGF(f"\n",##args)
|
||||||
|
|
||||||
|
#endif /* !ROCKBOX_HAS_LOGDISKF */
|
||||||
|
|
||||||
|
#endif /* LOGDISKF_H */
|
|
@ -44,6 +44,16 @@
|
||||||
#include "usbstack/usb_serial.h"
|
#include "usbstack/usb_serial.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ROCKBOX_HAS_LOGDISKF
|
||||||
|
#include "logdiskf.h"
|
||||||
|
#include "file.h"
|
||||||
|
#include "rbpaths.h"
|
||||||
|
#include "ata_idle_notify.h"
|
||||||
|
|
||||||
|
unsigned char logdiskfbuffer[MAX_LOGDISKF_SIZE];
|
||||||
|
int logdiskfindex;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Only provide all this if asked to */
|
/* Only provide all this if asked to */
|
||||||
#ifdef ROCKBOX_HAS_LOGF
|
#ifdef ROCKBOX_HAS_LOGF
|
||||||
|
|
||||||
|
@ -245,3 +255,70 @@ void _logf(const char *fmt, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ROCKBOX_HAS_LOGDISKF
|
||||||
|
static int logdiskf_push(void *userp, unsigned char c)
|
||||||
|
{
|
||||||
|
(void)userp;
|
||||||
|
|
||||||
|
/*just stop logging if out of space*/
|
||||||
|
if(logdiskfindex>=MAX_LOGDISKF_SIZE-1)
|
||||||
|
{
|
||||||
|
strcpy(&logdiskfbuffer[logdiskfindex-8], "LOGFULL");
|
||||||
|
logdiskfindex=MAX_LOGDISKF_SIZE;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
logdiskfbuffer[logdiskfindex++] = c;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _logdiskf(const char* file, const char level, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
int len =strlen(file);
|
||||||
|
if(logdiskfindex +len + 4 > MAX_LOGDISKF_SIZE-1)
|
||||||
|
{
|
||||||
|
strcpy(&logdiskfbuffer[logdiskfindex-8], "LOGFULL");
|
||||||
|
logdiskfindex=MAX_LOGDISKF_SIZE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logdiskf_push(NULL, level);
|
||||||
|
logdiskf_push(NULL, ' ');
|
||||||
|
logdiskf_push(NULL, '[');
|
||||||
|
strcpy(&logdiskfbuffer[logdiskfindex], file);
|
||||||
|
logdiskfindex += len;
|
||||||
|
logdiskf_push(NULL, ']');
|
||||||
|
|
||||||
|
vuprintf(logdiskf_push, NULL, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
static void flush_buffer(void* data)
|
||||||
|
{
|
||||||
|
(void)data;
|
||||||
|
int fd;
|
||||||
|
if(logdiskfindex < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fd = open(HOME_DIR"/rockbox_log.txt", O_RDWR | O_CREAT | O_APPEND, 0666);
|
||||||
|
if (fd < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
write(fd, logdiskfbuffer, logdiskfindex);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
logdiskfindex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_logdiskf()
|
||||||
|
{
|
||||||
|
register_storage_idle_func(flush_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue