Put bootlog in own folder (#19939)
* put bootlog in own folder * fix uploader * remove print statements * update test * remove comment * also write initddata * remove sentinels from testpull/19941/head
parent
92754cc808
commit
87119aebe2
6 changed files with 85 additions and 33 deletions
@ -1,37 +1,60 @@ |
||||
#include <assert.h> |
||||
#include <string> |
||||
#include <cstdio> |
||||
|
||||
#include <bzlib.h> |
||||
|
||||
#include "common/swaglog.h" |
||||
#include "common/util.h" |
||||
#include "logger.h" |
||||
#include "messaging.hpp" |
||||
#include "logger.h" |
||||
|
||||
int main(int argc, char** argv) { |
||||
LoggerState logger; |
||||
logger_init(&logger, "bootlog", false); |
||||
char filename[64] = {'\0'}; |
||||
|
||||
time_t rawtime = time(NULL); |
||||
struct tm timeinfo; |
||||
|
||||
localtime_r(&rawtime, &timeinfo); |
||||
strftime(filename, sizeof(filename), |
||||
"%Y-%m-%d--%H-%M-%S.bz2", &timeinfo); |
||||
|
||||
std::string path = LOG_ROOT + "/boot/" + std::string(filename); |
||||
LOGW("bootlog to %s", path.c_str()); |
||||
|
||||
MessageBuilder boot_msg; |
||||
logger_build_boot(boot_msg); |
||||
|
||||
MessageBuilder init_msg; |
||||
logger_build_init_data(init_msg); |
||||
|
||||
char segment_path[4096]; |
||||
int err = logger_next(&logger, LOG_ROOT.c_str(), segment_path, sizeof(segment_path), nullptr); |
||||
assert(err == 0); |
||||
LOGW("bootlog to %s", segment_path); |
||||
|
||||
MessageBuilder msg; |
||||
auto boot = msg.initEvent().initBoot(); |
||||
// Open bootlog
|
||||
int r = logger_mkpath((char*)path.c_str()); |
||||
assert(r == 0); |
||||
|
||||
boot.setWallTimeNanos(nanos_since_epoch()); |
||||
FILE * file = fopen(path.c_str(), "wb"); |
||||
assert(file != nullptr); |
||||
|
||||
std::string lastKmsg = util::read_file("/sys/fs/pstore/console-ramoops"); |
||||
boot.setLastKmsg(capnp::Data::Reader((const kj::byte*)lastKmsg.data(), lastKmsg.size())); |
||||
// Open as bz2
|
||||
int bzerror; |
||||
BZFILE* bz_file = BZ2_bzWriteOpen(&bzerror, file, 9, 0, 30); |
||||
assert(bzerror == BZ_OK); |
||||
|
||||
std::string lastPmsg = util::read_file("/sys/fs/pstore/pmsg-ramoops-0"); |
||||
boot.setLastPmsg(capnp::Data::Reader((const kj::byte*)lastPmsg.data(), lastPmsg.size())); |
||||
// Write initdata
|
||||
auto bytes = init_msg.toBytes(); |
||||
BZ2_bzWrite(&bzerror, bz_file, bytes.begin(), bytes.size()); |
||||
assert(bzerror == BZ_OK); |
||||
|
||||
std::string launchLog = util::read_file("/tmp/launch_log"); |
||||
boot.setLaunchLog(capnp::Text::Reader(launchLog.data(), launchLog.size())); |
||||
// Write bootlog
|
||||
bytes = boot_msg.toBytes(); |
||||
BZ2_bzWrite(&bzerror, bz_file, bytes.begin(), bytes.size()); |
||||
assert(bzerror == BZ_OK); |
||||
|
||||
auto bytes = msg.toBytes(); |
||||
logger_log(&logger, bytes.begin(), bytes.size(), false); |
||||
// Close bz2 and file
|
||||
BZ2_bzWriteClose(&bzerror, bz_file, 0, NULL, NULL); |
||||
assert(bzerror == BZ_OK); |
||||
|
||||
logger_close(&logger); |
||||
fclose(file); |
||||
return 0; |
||||
} |
||||
|
Loading…
Reference in new issue