Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 051222c2 authored by Mark Salyzyn's avatar Mark Salyzyn Committed by Gerrit Code Review
Browse files

Merge changes I12d6aa4e,I9e802113,I2b30e0fc,Iaf387b9e

* changes:
  logcat: remove dead label code
  logcat: do not stop on unexpected log ID
  Revert "logd: Add minimum time bucket statistics"
  liblog: Instrument logging of logd write drops
parents e53d17c1 5f6738af
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@
LOCAL_PATH := $(my-dir)
include $(CLEAR_VARS)

liblog_cflags := $(shell sed -n 's/^\([0-9]*\)[ \t]*liblog[ \t].*/-DLIBLOG_LOG_TAG=\1/p' $(LOCAL_PATH)/event.logtags)

ifneq ($(TARGET_USES_LOGD),false)
liblog_sources := logd_write.c
else
@@ -45,7 +47,7 @@ else
        uio.c
endif

liblog_host_sources := $(liblog_sources) fake_log_device.c
liblog_host_sources := $(liblog_sources) fake_log_device.c event.logtags
liblog_target_sources := $(liblog_sources) log_time.cpp log_is_loggable.c
ifneq ($(TARGET_USES_LOGD),false)
liblog_target_sources += log_read.c
@@ -57,7 +59,7 @@ endif
# ========================================================
LOCAL_MODULE := liblog
LOCAL_SRC_FILES := $(liblog_host_sources)
LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -Werror
LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -Werror $(liblog_cflags)
LOCAL_MULTILIB := both
include $(BUILD_HOST_STATIC_LIBRARY)

@@ -76,13 +78,13 @@ include $(BUILD_HOST_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := liblog
LOCAL_SRC_FILES := $(liblog_target_sources)
LOCAL_CFLAGS := -Werror
LOCAL_CFLAGS := -Werror $(liblog_cflags)
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := liblog
LOCAL_WHOLE_STATIC_LIBRARIES := liblog
LOCAL_CFLAGS := -Werror
LOCAL_CFLAGS := -Werror $(liblog_cflags)
include $(BUILD_SHARED_LIBRARY)

include $(call first-makefiles-under,$(LOCAL_PATH))
+27 −0
Original line number Diff line number Diff line
@@ -131,6 +131,33 @@ DESCRIPTION
       when  opening  the  sub-log.    It  is  recommended  to  open  the  log
       ANDROID_LOG_RDONLY in these cases.

ERRORS
       If messages fail, a negative error code will be returned to the caller.

       The -ENOTCONN return code indicates that the logger daemon is stopped.

       The  -EBADF return code indicates that the log access point can not be
       opened, or the log buffer id is out of range.

       For the  -EAGAIN  return code,  this means that the logging message was
       temporarily backed-up either because of Denial Of Service (DOS) logging
       pressure from some chatty application or service in the Android system,
       or if too small of a value is set in /proc/sys/net/unix/max_dgram_qlen.
       To aid in diagnosing the occurence of this,  a binary event from liblog
       will be sent to the  log  daemon  once a  new  message  can get through
       indicating how many  messages were  dropped  as a result.   Please take
       action to resolve the structural problems at the source.

       It is generally not advised for the caller to retry the  -EAGAIN return
       code as  this  will  only  make the  problem(s)  worse  and  cause your
       application to temporarily drop to the  logger daemon  priority,  BATCH
       scheduling policy and background task cgroup. If you require a group of
       messages to be passed atomically,  merge  them  into  one  message with
       embedded newlines to the maximum length LOGGER_ENTRY_MAX_PAYLOAD.

       Other return codes  from  writing operation can be returned.  Since the
       library retries on EINTR, -EINTR should never be returned.

SEE ALSO
       syslogd(8)

liblog/event.logtags

0 → 100644
+36 −0
Original line number Diff line number Diff line
# The entries in this file map a sparse set of log tag numbers to tag names.
# This is installed on the device, in /system/etc, and parsed by logcat.
#
# Tag numbers are decimal integers, from 0 to 2^31.  (Let's leave the
# negative values alone for now.)
#
# Tag names are one or more ASCII letters and numbers or underscores, i.e.
# "[A-Z][a-z][0-9]_".  Do not include spaces or punctuation (the former
# impacts log readability, the latter makes regex searches more annoying).
#
# Tag numbers and names are separated by whitespace.  Blank lines and lines
# starting with '#' are ignored.
#
# Optionally, after the tag names can be put a description for the value(s)
# of the tag. Description are in the format
#    (<name>|data type[|data unit])
# Multiple values are separated by commas.
#
# The data type is a number from the following values:
# 1: int
# 2: long
# 3: string
# 4: list
#
# The data unit is a number taken from the following list:
# 1: Number of objects
# 2: Number of bytes
# 3: Number of milliseconds
# 4: Number of allocations
# 5: Id
# 6: Percent
# Default value for data of type int/long is 2 (bytes).
#
# TODO: generate ".java" and ".h" files with integer constants from this file.

1005  liblog (dropped|1)
+27 −1
Original line number Diff line number Diff line
@@ -13,12 +13,14 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#if !defined(_WIN32)
#include <pthread.h>
#endif
#include <stdarg.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -172,6 +174,7 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec *vec, size_t nr)
    size_t i, payload_size;
    static uid_t last_uid = AID_ROOT; /* logd *always* starts up as AID_ROOT */
    static pid_t last_pid = (pid_t) -1;
    static atomic_int_fast32_t dropped;

    if (last_uid == AID_ROOT) { /* have we called to get the UID yet? */
        last_uid = getuid();
@@ -206,7 +209,6 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec *vec, size_t nr)
    pmsg_header.uid = last_uid;
    pmsg_header.pid = last_pid;

    header.id = log_id;
    header.tid = gettid();
    header.realtime.tv_sec = ts.tv_sec;
    header.realtime.tv_nsec = ts.tv_nsec;
@@ -216,6 +218,28 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec *vec, size_t nr)
    newVec[1].iov_base   = (unsigned char *) &header;
    newVec[1].iov_len    = sizeof(header);

    if (logd_fd > 0) {
        int32_t snapshot = atomic_exchange_explicit(&dropped, 0, memory_order_relaxed);
        if (snapshot) {
            android_log_event_int_t buffer;

            header.id = LOG_ID_EVENTS;
            buffer.header.tag = htole32(LIBLOG_LOG_TAG);
            buffer.payload.type = EVENT_TYPE_INT;
            buffer.payload.data = htole32(snapshot);

            newVec[2].iov_base = &buffer;
            newVec[2].iov_len  = sizeof(buffer);

            ret = TEMP_FAILURE_RETRY(writev(logd_fd, newVec + 1, 2));
            if (ret != (ssize_t)(sizeof(header) + sizeof(buffer))) {
                atomic_fetch_add_explicit(&dropped, snapshot, memory_order_relaxed);
            }
        }
    }

    header.id = log_id;

    for (payload_size = 0, i = header_length; i < nr + header_length; i++) {
        newVec[i].iov_base = vec[i - header_length].iov_base;
        payload_size += newVec[i].iov_len = vec[i - header_length].iov_len;
@@ -281,6 +305,8 @@ static int __write_to_log_daemon(log_id_t log_id, struct iovec *vec, size_t nr)

    if (ret > (ssize_t)sizeof(header)) {
        ret -= sizeof(header);
    } else if (ret == -EAGAIN) {
        atomic_fetch_add_explicit(&dropped, 1, memory_order_relaxed);
    }
#endif

+22 −38
Original line number Diff line number Diff line
@@ -38,14 +38,12 @@ struct log_device_t {
    struct logger *logger;
    struct logger_list *logger_list;
    bool printed;
    char label;

    log_device_t* next;

    log_device_t(const char* d, bool b, char l) {
    log_device_t(const char* d, bool b) {
        device = d;
        binary = b;
        label = l;
        next = NULL;
        printed = false;
    }
@@ -61,9 +59,7 @@ static int g_maxRotatedLogs = DEFAULT_MAX_ROTATED_LOGS; // 0 means "unbounded"
static int g_outFD = -1;
static off_t g_outByteCount = 0;
static int g_printBinary = 0;
static int g_devCount = 0;

static EventTagMap* g_eventTagMap = NULL;
static int g_devCount = 0;                              // >1 means multiple

static int openLogFile (const char *pathname)
{
@@ -133,8 +129,15 @@ static void processBuffer(log_device_t* dev, struct log_msg *buf)
    char binaryMsgBuf[1024];

    if (dev->binary) {
        static bool hasOpenedEventTagMap = false;
        static EventTagMap *eventTagMap = NULL;

        if (!eventTagMap && !hasOpenedEventTagMap) {
            eventTagMap = android_openEventTagMap(EVENT_TAG_MAP_FILE);
            hasOpenedEventTagMap = true;
        }
        err = android_log_processBinaryLogBuffer(&buf->entry_v1, &entry,
                                                 g_eventTagMap,
                                                 eventTagMap,
                                                 binaryMsgBuf,
                                                 sizeof(binaryMsgBuf));
        //printf(">>> pri=%d len=%d msg='%s'\n",
@@ -147,16 +150,6 @@ static void processBuffer(log_device_t* dev, struct log_msg *buf)
    }

    if (android_log_shouldPrintLine(g_logformat, entry.tag, entry.priority)) {
        if (false && g_devCount > 1) {
            binaryMsgBuf[0] = dev->label;
            binaryMsgBuf[1] = ' ';
            bytesWritten = write(g_outFD, binaryMsgBuf, 2);
            if (bytesWritten < 0) {
                perror("output error");
                exit(-1);
            }
        }

        bytesWritten = android_log_printLogLine(g_logformat, g_outFD, &entry);

        if (bytesWritten < 0) {
@@ -331,7 +324,6 @@ int main(int argc, char **argv)
    const char *forceFilters = NULL;
    log_device_t* devices = NULL;
    log_device_t* dev;
    bool needBinary = false;
    bool printDividers = false;
    struct logger_list *logger_list;
    unsigned int tail_lines = 0;
@@ -469,7 +461,6 @@ int main(int argc, char **argv)

                    devices = dev = NULL;
                    android::g_devCount = 0;
                    needBinary = false;
                    for(int i = LOG_ID_MIN; i < LOG_ID_MAX; ++i) {
                        const char *name = android_log_id_to_name((log_id_t)i);
                        log_id_t log_id = android_name_to_log_id(name);
@@ -479,7 +470,7 @@ int main(int argc, char **argv)
                        }

                        bool binary = strcmp(name, "events") == 0;
                        log_device_t* d = new log_device_t(name, binary, *name);
                        log_device_t* d = new log_device_t(name, binary);

                        if (dev) {
                            dev->next = d;
@@ -488,26 +479,20 @@ int main(int argc, char **argv)
                            devices = dev = d;
                        }
                        android::g_devCount++;
                        if (binary) {
                            needBinary = true;
                        }
                    }
                    break;
                }

                bool binary = strcmp(optarg, "events") == 0;
                if (binary) {
                    needBinary = true;
                }

                if (devices) {
                    dev = devices;
                    while (dev->next) {
                        dev = dev->next;
                    }
                    dev->next = new log_device_t(optarg, binary, optarg[0]);
                    dev->next = new log_device_t(optarg, binary);
                } else {
                    devices = new log_device_t(optarg, binary, optarg[0]);
                    devices = new log_device_t(optarg, binary);
                }
                android::g_devCount++;
            }
@@ -641,14 +626,14 @@ int main(int argc, char **argv)
    }

    if (!devices) {
        dev = devices = new log_device_t("main", false, 'm');
        dev = devices = new log_device_t("main", false);
        android::g_devCount = 1;
        if (android_name_to_log_id("system") == LOG_ID_SYSTEM) {
            dev = dev->next = new log_device_t("system", false, 's');
            dev = dev->next = new log_device_t("system", false);
            android::g_devCount++;
        }
        if (android_name_to_log_id("crash") == LOG_ID_CRASH) {
            dev = dev->next = new log_device_t("crash", false, 'c');
            dev = dev->next = new log_device_t("crash", false);
            android::g_devCount++;
        }
    }
@@ -848,17 +833,15 @@ int main(int argc, char **argv)
    //LOG_EVENT_LONG(11, 0x1122334455667788LL);
    //LOG_EVENT_STRING(0, "whassup, doc?");

    if (needBinary)
        android::g_eventTagMap = android_openEventTagMap(EVENT_TAG_MAP_FILE);

    dev = NULL;
    log_device_t unexpected("unexpected", false);
    while (1) {
        struct log_msg log_msg;
        log_device_t* d;
        int ret = android_logger_list_read(logger_list, &log_msg);

        if (ret == 0) {
            fprintf(stderr, "read: Unexpected EOF!\n");
            fprintf(stderr, "read: unexpected EOF!\n");
            exit(EXIT_FAILURE);
        }

@@ -868,7 +851,7 @@ int main(int argc, char **argv)
            }

            if (ret == -EIO) {
                fprintf(stderr, "read: Unexpected EOF!\n");
                fprintf(stderr, "read: unexpected EOF!\n");
                exit(EXIT_FAILURE);
            }
            if (ret == -EINVAL) {
@@ -885,8 +868,9 @@ int main(int argc, char **argv)
            }
        }
        if (!d) {
            fprintf(stderr, "read: Unexpected log ID!\n");
            exit(EXIT_FAILURE);
            android::g_devCount = 2; // set to Multiple
            d = &unexpected;
            d->binary = log_msg.id() == LOG_ID_EVENTS;
        }

        if (dev != d) {
Loading