Log new ErrorReporter and old nnapi delegate errors to logcat.

On Android stderr is not captured for applications, so developers do not see
the errors from tflite. This adds logcat output.

Output to stderr is kept, as it is convenient for unit tests run through the
shell.

PiperOrigin-RevId: 208463170
This commit is contained in:
A. Unique TensorFlower 2018-08-13 05:02:45 -07:00 committed by TensorFlower Gardener
parent 9b44e8bd7b
commit 2c623eaa7c
2 changed files with 26 additions and 6 deletions
tensorflow/contrib/lite

View File

@ -16,6 +16,10 @@ limitations under the License.
#include <cstdarg>
#include <cstdio>
#ifdef __ANDROID__
#include <android/log.h>
#endif
namespace tflite {
ErrorReporter::~ErrorReporter() {}
@ -39,6 +43,15 @@ int ErrorReporter::ReportError(void*, const char* format, ...) {
}
int StderrReporter::Report(const char* format, va_list args) {
#ifdef __ANDROID__
// On Android stderr is not captured for applications, only for code run from
// the shell. Rather than assume all users will set up a custom error
// reporter, let's output to logcat here
va_list args_for_log;
va_copy(args_for_log, args);
__android_log_vprint(ANDROID_LOG_ERROR, "tflite", format, args_for_log);
va_end(args_for_log);
#endif
const int result = vfprintf(stderr, format, args);
fputc('\n', stderr);
return result;

View File

@ -24,20 +24,27 @@ limitations under the License.
#include "tensorflow/contrib/lite/nnapi/NeuralNetworksShim.h"
#ifdef __ANDROID__
#include <android/log.h>
#include <sys/system_properties.h>
#endif
namespace tflite {
void logError(const char* format, ...) {
// TODO(mikie): use android logging, stderr is not captured for Java
// applications
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
// stderr is convenient for native tests, but is not captured for apps
va_list args_for_stderr;
va_start(args_for_stderr, format);
vfprintf(stderr, format, args_for_stderr);
va_end(args_for_stderr);
fprintf(stderr, "\n");
fflush(stderr);
#ifdef __ANDROID__
// produce logcat output for general consumption
va_list args_for_log;
va_start(args_for_log, format);
__android_log_vprint(ANDROID_LOG_ERROR, "tflite", format, args_for_log);
va_end(args_for_log);
#endif
}
#define FATAL(...) \