Home | History | Annotate | Download | only in jni
      1 // Copyright 2017 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef LOGGING_H_
      6 #define LOGGING_H_
      7 
      8 #include <android/log.h>
      9 #include <errno.h>
     10 #include <stdio.h>
     11 #include <stdlib.h>
     12 
     13 #define CHECK_ARGS(COND, ERR)                                          \
     14   "FAILED CHECK(%s) @ %s:%d (errno: %s)\n", #COND, __FILE__, __LINE__, \
     15       strerror(ERR)
     16 
     17 #define CHECK(x)                                              \
     18   do {                                                        \
     19     if (!(x)) {                                               \
     20       const int e = errno;                                    \
     21       __android_log_print(ANDROID_LOG_FATAL, "atrace_helper", \
     22                           CHECK_ARGS(x, e));                  \
     23       fprintf(stderr, "\n" CHECK_ARGS(x, e));                 \
     24       fflush(stderr);                                         \
     25       abort();                                                \
     26     }                                                         \
     27   } while (0)
     28 
     29 inline void LogError(const char* message) {
     30   __android_log_write(ANDROID_LOG_ERROR, "atrace_helper", message);
     31   fprintf(stderr, "\n%s\n", message);
     32   fflush(stderr);
     33 }
     34 
     35 #endif  // LOGGING_H_
     36