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 <assert.h> |
||||||
#include <string> |
#include <string> |
||||||
|
#include <cstdio> |
||||||
|
|
||||||
|
#include <bzlib.h> |
||||||
|
|
||||||
#include "common/swaglog.h" |
#include "common/swaglog.h" |
||||||
#include "common/util.h" |
#include "common/util.h" |
||||||
#include "logger.h" |
|
||||||
#include "messaging.hpp" |
#include "messaging.hpp" |
||||||
|
#include "logger.h" |
||||||
|
|
||||||
int main(int argc, char** argv) { |
int main(int argc, char** argv) { |
||||||
LoggerState logger; |
char filename[64] = {'\0'}; |
||||||
logger_init(&logger, "bootlog", false); |
|
||||||
|
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; |
// Open bootlog
|
||||||
auto boot = msg.initEvent().initBoot(); |
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"); |
// Open as bz2
|
||||||
boot.setLastKmsg(capnp::Data::Reader((const kj::byte*)lastKmsg.data(), lastKmsg.size())); |
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"); |
// Write initdata
|
||||||
boot.setLastPmsg(capnp::Data::Reader((const kj::byte*)lastPmsg.data(), lastPmsg.size())); |
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"); |
// Write bootlog
|
||||||
boot.setLaunchLog(capnp::Text::Reader(launchLog.data(), launchLog.size())); |
bytes = boot_msg.toBytes(); |
||||||
|
BZ2_bzWrite(&bzerror, bz_file, bytes.begin(), bytes.size()); |
||||||
|
assert(bzerror == BZ_OK); |
||||||
|
|
||||||
auto bytes = msg.toBytes(); |
// Close bz2 and file
|
||||||
logger_log(&logger, bytes.begin(), bytes.size(), false); |
BZ2_bzWriteClose(&bzerror, bz_file, 0, NULL, NULL); |
||||||
|
assert(bzerror == BZ_OK); |
||||||
|
|
||||||
logger_close(&logger); |
fclose(file); |
||||||
return 0; |
return 0; |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue