Save recent Widevine CDM logs am: 83ef9081d1
Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/13472557 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I2d46fa52ea2552df7f40ec634b4f82f438e70d94
This commit is contained in:
@@ -7,6 +7,11 @@
|
||||
#ifndef WVCDM_UTIL_LOG_H_
|
||||
#define WVCDM_UTIL_LOG_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "util_common.h"
|
||||
|
||||
namespace wvcdm {
|
||||
@@ -27,6 +32,24 @@ typedef enum {
|
||||
|
||||
extern LogPriority g_cutoff;
|
||||
|
||||
struct LogMessage {
|
||||
int64_t time_ms_;
|
||||
LogPriority priority_;
|
||||
std::string message_;
|
||||
};
|
||||
|
||||
class LogBuffer {
|
||||
public:
|
||||
static const int MAX_CAPACITY = 100;
|
||||
void addLog(const LogMessage& log);
|
||||
std::vector<LogMessage> getLogs();
|
||||
private:
|
||||
std::deque<LogMessage> buffer_;
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
extern LogBuffer g_logbuf;
|
||||
|
||||
// Enable/disable verbose logging (LOGV).
|
||||
// This function is supplied for cases where the system layer does not
|
||||
// initialize logging. This is also needed to initialize logging in
|
||||
|
||||
@@ -26,7 +26,9 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
@@ -38,8 +40,20 @@
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
namespace {
|
||||
int64_t GetCurrentTimeMs() {
|
||||
struct timeval tv{};
|
||||
gettimeofday(&tv, NULL);
|
||||
auto msec1 = static_cast<int64_t>(tv.tv_sec) * 1000;
|
||||
auto msec2 = static_cast<int64_t>(tv.tv_usec) / 1000;
|
||||
return msec1 + msec2;
|
||||
}
|
||||
}
|
||||
|
||||
LogPriority g_cutoff = LOG_VERBOSE;
|
||||
|
||||
LogBuffer g_logbuf;
|
||||
|
||||
void InitLogging() {}
|
||||
|
||||
void Log(const char* file, const char* function, int line, LogPriority level,
|
||||
@@ -86,6 +100,22 @@ void Log(const char* file, const char* function, int line, LogPriority level,
|
||||
}
|
||||
|
||||
__android_log_write(prio, LOG_TAG, buf);
|
||||
if (level <= LOG_INFO) {
|
||||
g_logbuf.addLog({GetCurrentTimeMs(), level, buf});
|
||||
}
|
||||
}
|
||||
|
||||
void LogBuffer::addLog(const LogMessage& log) {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
buffer_.push_back(log);
|
||||
while (buffer_.size() > MAX_CAPACITY) {
|
||||
buffer_.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<LogMessage> LogBuffer::getLogs() {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
return {buffer_.begin(), buffer_.end()};
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
Reference in New Issue
Block a user