Merge "logd: liblog: 64-bit issues"
This commit is contained in:
commit
bb0fbdbefd
9 changed files with 81 additions and 25 deletions
|
@ -19,21 +19,38 @@
|
|||
|
||||
#include <time.h>
|
||||
|
||||
/* struct log_time is a wire-format variant of struct timespec */
|
||||
#define NS_PER_SEC 1000000000ULL
|
||||
#ifdef __cplusplus
|
||||
struct log_time : public timespec {
|
||||
struct log_time {
|
||||
public:
|
||||
uint32_t tv_sec; // good to Feb 5 2106
|
||||
uint32_t tv_nsec;
|
||||
|
||||
log_time(const timespec &T)
|
||||
{
|
||||
tv_sec = T.tv_sec;
|
||||
tv_nsec = T.tv_nsec;
|
||||
}
|
||||
log_time(const log_time &T)
|
||||
{
|
||||
tv_sec = T.tv_sec;
|
||||
tv_nsec = T.tv_nsec;
|
||||
}
|
||||
log_time(uint32_t sec, uint32_t nsec)
|
||||
{
|
||||
tv_sec = sec;
|
||||
tv_nsec = nsec;
|
||||
}
|
||||
log_time()
|
||||
{
|
||||
}
|
||||
log_time(clockid_t id)
|
||||
{
|
||||
clock_gettime(id, (timespec *) this);
|
||||
timespec T;
|
||||
clock_gettime(id, &T);
|
||||
tv_sec = T.tv_sec;
|
||||
tv_nsec = T.tv_nsec;
|
||||
}
|
||||
log_time(const char *T)
|
||||
{
|
||||
|
@ -41,6 +58,8 @@ public:
|
|||
tv_sec = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24);
|
||||
tv_nsec = c[4] | (c[5] << 8) | (c[6] << 16) | (c[7] << 24);
|
||||
}
|
||||
|
||||
// timespec
|
||||
bool operator== (const timespec &T) const
|
||||
{
|
||||
return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
|
||||
|
@ -67,13 +86,45 @@ public:
|
|||
{
|
||||
return !(*this > T);
|
||||
}
|
||||
|
||||
// log_time
|
||||
bool operator== (const log_time &T) const
|
||||
{
|
||||
return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
|
||||
}
|
||||
bool operator!= (const log_time &T) const
|
||||
{
|
||||
return !(*this == T);
|
||||
}
|
||||
bool operator< (const log_time &T) const
|
||||
{
|
||||
return (tv_sec < T.tv_sec)
|
||||
|| ((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec));
|
||||
}
|
||||
bool operator>= (const log_time &T) const
|
||||
{
|
||||
return !(*this < T);
|
||||
}
|
||||
bool operator> (const log_time &T) const
|
||||
{
|
||||
return (tv_sec > T.tv_sec)
|
||||
|| ((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec));
|
||||
}
|
||||
bool operator<= (const log_time &T) const
|
||||
{
|
||||
return !(*this > T);
|
||||
}
|
||||
|
||||
uint64_t nsec() const
|
||||
{
|
||||
return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
|
||||
}
|
||||
};
|
||||
} __attribute__((__packed__));
|
||||
#else
|
||||
typedef struct timespec log_time;
|
||||
typedef struct log_time {
|
||||
uint32_t tv_sec;
|
||||
uint32_t tv_nsec;
|
||||
} __attribute__((__packed__)) log_time;
|
||||
#endif
|
||||
|
||||
#endif /* define _LIBS_LOG_LOG_READ_H */
|
||||
|
|
|
@ -30,7 +30,7 @@ struct logger_entry {
|
|||
int32_t sec; /* seconds since Epoch */
|
||||
int32_t nsec; /* nanoseconds */
|
||||
char msg[0]; /* the entry's payload */
|
||||
};
|
||||
} __attribute__((__packed__));
|
||||
|
||||
/*
|
||||
* The userspace structure for version 2 of the logger_entry ABI.
|
||||
|
@ -46,18 +46,18 @@ struct logger_entry_v2 {
|
|||
int32_t nsec; /* nanoseconds */
|
||||
uint32_t euid; /* effective UID of logger */
|
||||
char msg[0]; /* the entry's payload */
|
||||
};
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct logger_entry_v3 {
|
||||
uint16_t len; /* length of the payload */
|
||||
uint16_t hdr_size; /* sizeof(struct logger_entry_v2) */
|
||||
uint16_t hdr_size; /* sizeof(struct logger_entry_v3) */
|
||||
int32_t pid; /* generating process's pid */
|
||||
int32_t tid; /* generating process's tid */
|
||||
int32_t sec; /* seconds since Epoch */
|
||||
int32_t nsec; /* nanoseconds */
|
||||
uint32_t lid; /* log id of the payload */
|
||||
char msg[0]; /* the entry's payload */
|
||||
};
|
||||
} __attribute__((__packed__));
|
||||
|
||||
/*
|
||||
* The maximum size of the log entry payload that can be
|
||||
|
|
|
@ -117,8 +117,11 @@ static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr)
|
|||
newVec[0].iov_base = (unsigned char *) &log_id_buf;
|
||||
newVec[0].iov_len = sizeof_log_id_t;
|
||||
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
log_time realtime_ts;
|
||||
clock_gettime(CLOCK_REALTIME, &realtime_ts);
|
||||
realtime_ts.tv_sec = ts.tv_sec;
|
||||
realtime_ts.tv_nsec = ts.tv_nsec;
|
||||
|
||||
newVec[1].iov_base = (unsigned char *) &realtime_ts;
|
||||
newVec[1].iov_len = sizeof(log_time);
|
||||
|
|
|
@ -143,7 +143,7 @@ static void BM_log_latency(int iters) {
|
|||
for (int j = 0, i = 0; i < iters && j < 10*iters; ++i, ++j) {
|
||||
log_time ts;
|
||||
LOG_FAILURE_RETRY((
|
||||
clock_gettime(CLOCK_REALTIME, &ts),
|
||||
ts = log_time(CLOCK_REALTIME),
|
||||
android_btWriteLog(0, EVENT_TYPE_LONG, &ts, sizeof(ts))));
|
||||
|
||||
for (;;) {
|
||||
|
|
|
@ -171,7 +171,7 @@ static void caught_blocking(int signum)
|
|||
|
||||
++signaled;
|
||||
if ((signal_time.tv_sec == 0) && (signal_time.tv_nsec == 0)) {
|
||||
clock_gettime(CLOCK_MONOTONIC, &signal_time);
|
||||
signal_time = log_time(CLOCK_MONOTONIC);
|
||||
signal_time.tv_sec += 2;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ LogBuffer::LogBuffer(LastLogTimes *times)
|
|||
pthread_mutex_init(&mLogElementsLock, NULL);
|
||||
}
|
||||
|
||||
void LogBuffer::log(log_id_t log_id, struct timespec realtime,
|
||||
void LogBuffer::log(log_id_t log_id, log_time realtime,
|
||||
uid_t uid, pid_t pid, const char *msg,
|
||||
unsigned short len) {
|
||||
if ((log_id >= LOG_ID_MAX) || (log_id < 0)) {
|
||||
|
@ -182,8 +182,8 @@ unsigned long LogBuffer::getSize(log_id_t /*id*/) {
|
|||
return LOG_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
struct timespec LogBuffer::flushTo(
|
||||
SocketClient *reader, const struct timespec start, bool privileged,
|
||||
log_time LogBuffer::flushTo(
|
||||
SocketClient *reader, const log_time start, bool privileged,
|
||||
bool (*filter)(const LogBufferElement *element, void *arg), void *arg) {
|
||||
LogBufferElementCollection::iterator it;
|
||||
log_time max = start;
|
||||
|
|
|
@ -40,12 +40,12 @@ public:
|
|||
|
||||
LogBuffer(LastLogTimes *times);
|
||||
|
||||
void log(log_id_t log_id, struct timespec realtime,
|
||||
void log(log_id_t log_id, log_time realtime,
|
||||
uid_t uid, pid_t pid, const char *msg, unsigned short len);
|
||||
struct timespec flushTo(SocketClient *writer, const struct timespec start,
|
||||
bool privileged,
|
||||
bool (*filter)(const LogBufferElement *element, void *arg) = NULL,
|
||||
void *arg = NULL);
|
||||
log_time flushTo(SocketClient *writer, const log_time start,
|
||||
bool privileged,
|
||||
bool (*filter)(const LogBufferElement *element, void *arg) = NULL,
|
||||
void *arg = NULL);
|
||||
|
||||
void clear(log_id_t id);
|
||||
unsigned long getSize(log_id_t id);
|
||||
|
|
|
@ -24,9 +24,11 @@
|
|||
#include "LogBufferElement.h"
|
||||
#include "LogReader.h"
|
||||
|
||||
const struct timespec LogBufferElement::FLUSH_ERROR = { 0, 0 };
|
||||
const log_time LogBufferElement::FLUSH_ERROR(0, 0);
|
||||
|
||||
LogBufferElement::LogBufferElement(log_id_t log_id, struct timespec realtime, uid_t uid, pid_t pid, const char *msg, unsigned short len)
|
||||
LogBufferElement::LogBufferElement(log_id_t log_id, log_time realtime,
|
||||
uid_t uid, pid_t pid, const char *msg,
|
||||
unsigned short len)
|
||||
: mLogId(log_id)
|
||||
, mUid(uid)
|
||||
, mPid(pid)
|
||||
|
@ -41,7 +43,7 @@ LogBufferElement::~LogBufferElement() {
|
|||
delete [] mMsg;
|
||||
}
|
||||
|
||||
struct timespec LogBufferElement::flushTo(SocketClient *reader) {
|
||||
log_time LogBufferElement::flushTo(SocketClient *reader) {
|
||||
struct logger_entry_v3 entry;
|
||||
memset(&entry, 0, sizeof(struct logger_entry_v3));
|
||||
entry.hdr_size = sizeof(struct logger_entry_v3);
|
||||
|
|
|
@ -32,7 +32,7 @@ class LogBufferElement {
|
|||
const log_time mRealTime;
|
||||
|
||||
public:
|
||||
LogBufferElement(log_id_t log_id, struct timespec realtime,
|
||||
LogBufferElement(log_id_t log_id, log_time realtime,
|
||||
uid_t uid, pid_t pid, const char *msg, unsigned short len);
|
||||
virtual ~LogBufferElement();
|
||||
|
||||
|
@ -43,8 +43,8 @@ public:
|
|||
log_time getMonotonicTime(void) const { return mMonotonicTime; }
|
||||
log_time getRealTime(void) const { return mRealTime; }
|
||||
|
||||
static const struct timespec FLUSH_ERROR;
|
||||
struct timespec flushTo(SocketClient *writer);
|
||||
static const log_time FLUSH_ERROR;
|
||||
log_time flushTo(SocketClient *writer);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue