Path: blob/21.2-virgl/include/android_stub/log/log_read.h
4547 views
/*1* Copyright (C) 2005-2017 The Android Open Source Project2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516#pragma once1718#include <stdint.h>19#include <sys/types.h>2021#include <android/log.h>22#include <log/log_time.h>2324#ifdef __cplusplus25extern "C" {26#endif2728#define ANDROID_LOG_WRAP_DEFAULT_TIMEOUT 7200 /* 2 hour default */2930/*31* Native log reading interface section. See logcat for sample code.32*33* The preferred API is an exec of logcat. Likely uses of this interface34* are if native code suffers from exec or filtration being too costly,35* access to raw information, or parsing is an issue.36*/3738struct logger_entry {39uint16_t len; /* length of the payload */40uint16_t hdr_size; /* sizeof(struct logger_entry) */41int32_t pid; /* generating process's pid */42uint32_t tid; /* generating process's tid */43uint32_t sec; /* seconds since Epoch */44uint32_t nsec; /* nanoseconds */45uint32_t lid; /* log id of the payload, bottom 4 bits currently */46uint32_t uid; /* generating process's uid */47};4849/*50* The maximum size of a log entry which can be read.51* An attempt to read less than this amount may result52* in read() returning EINVAL.53*/54#define LOGGER_ENTRY_MAX_LEN (5 * 1024)5556struct log_msg {57union {58unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1];59struct logger_entry entry;60} __attribute__((aligned(4)));61#ifdef __cplusplus62uint64_t nsec() const {63return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec;64}65log_id_t id() {66return static_cast<log_id_t>(entry.lid);67}68char* msg() {69unsigned short hdr_size = entry.hdr_size;70if (hdr_size >= sizeof(struct log_msg) - sizeof(entry)) {71return nullptr;72}73return reinterpret_cast<char*>(buf) + hdr_size;74}75unsigned int len() { return entry.hdr_size + entry.len; }76#endif77};7879struct logger;8081log_id_t android_logger_get_id(struct logger* logger);8283/* Clears the given log buffer. */84int android_logger_clear(struct logger* logger);85/* Return the allotted size for the given log buffer. */86long android_logger_get_log_size(struct logger* logger);87/* Set the allotted size for the given log buffer. */88int android_logger_set_log_size(struct logger* logger, unsigned long size);89/* Return the actual, uncompressed size that can be read from the given log buffer. */90long android_logger_get_log_readable_size(struct logger* logger);91/* Return the actual, compressed size that the given log buffer is consuming. */92long android_logger_get_log_consumed_size(struct logger* logger);93/* Deprecated. Always returns '4' regardless of input. */94int android_logger_get_log_version(struct logger* logger);9596struct logger_list;9798ssize_t android_logger_get_statistics(struct logger_list* logger_list,99char* buf, size_t len);100ssize_t android_logger_get_prune_list(struct logger_list* logger_list,101char* buf, size_t len);102int android_logger_set_prune_list(struct logger_list* logger_list, const char* buf, size_t len);103104/* The below values are used for the `mode` argument of the below functions. */105/* Note that 0x00000003 were previously used and should be considered reserved. */106#define ANDROID_LOG_NONBLOCK 0x00000800107#define ANDROID_LOG_WRAP 0x40000000 /* Block until buffer about to wrap */108#define ANDROID_LOG_PSTORE 0x80000000109110struct logger_list* android_logger_list_alloc(int mode, unsigned int tail,111pid_t pid);112struct logger_list* android_logger_list_alloc_time(int mode, log_time start,113pid_t pid);114void android_logger_list_free(struct logger_list* logger_list);115/* In the purest sense, the following two are orthogonal interfaces */116int android_logger_list_read(struct logger_list* logger_list,117struct log_msg* log_msg);118119/* Multiple log_id_t opens */120struct logger* android_logger_open(struct logger_list* logger_list, log_id_t id);121/* Single log_id_t open */122struct logger_list* android_logger_list_open(log_id_t id, int mode,123unsigned int tail, pid_t pid);124#define android_logger_list_close android_logger_list_free125126#ifdef __cplusplus127}128#endif129130131