swaglog: add daemon name to context (#23518)
* cleanup first * add daemon name * add test * fix * daemon namepull/23520/head
parent
feae37541f
commit
8c53adf4ab
|
@ -35,10 +35,6 @@ LogState::~LogState() {
|
|||
|
||||
static LogState s = {};
|
||||
|
||||
static void cloudlog_bind_locked(const char* k, const char* v) {
|
||||
s.ctx_j[k] = v;
|
||||
}
|
||||
|
||||
static void cloudlog_init() {
|
||||
if (s.inited) return;
|
||||
s.ctx_j = json11::Json::object {};
|
||||
|
@ -65,18 +61,22 @@ static void cloudlog_init() {
|
|||
// openpilot bindings
|
||||
char* dongle_id = getenv("DONGLE_ID");
|
||||
if (dongle_id) {
|
||||
cloudlog_bind_locked("dongle_id", dongle_id);
|
||||
s.ctx_j["dongle_id"] = dongle_id;
|
||||
}
|
||||
cloudlog_bind_locked("version", COMMA_VERSION);
|
||||
char* daemon_name = getenv("MANAGER_DAEMON");
|
||||
if (daemon_name) {
|
||||
s.ctx_j["daemon"] = daemon_name;
|
||||
}
|
||||
s.ctx_j["version"] = COMMA_VERSION;
|
||||
s.ctx_j["dirty"] = !getenv("CLEAN");
|
||||
|
||||
// device type
|
||||
if (Hardware::EON()) {
|
||||
cloudlog_bind_locked("device", "eon");
|
||||
s.ctx_j["device"] = "eon";
|
||||
} else if (Hardware::TICI()) {
|
||||
cloudlog_bind_locked("device", "tici");
|
||||
s.ctx_j["device"] = "tici";
|
||||
} else {
|
||||
cloudlog_bind_locked("device", "pc");
|
||||
s.ctx_j["device"] = "pc";
|
||||
}
|
||||
|
||||
s.inited = true;
|
||||
|
@ -116,9 +116,3 @@ void cloudlog_e(int levelnum, const char* filename, int lineno, const char* func
|
|||
log(levelnum, filename, lineno, func, msg_buf, log_s);
|
||||
free(msg_buf);
|
||||
}
|
||||
|
||||
void cloudlog_bind(const char* k, const char* v) {
|
||||
std::lock_guard lk(s.lock);
|
||||
cloudlog_init();
|
||||
cloudlog_bind_locked(k, v);
|
||||
}
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
void cloudlog_e(int levelnum, const char* filename, int lineno, const char* func,
|
||||
const char* fmt, ...) /*__attribute__ ((format (printf, 6, 7)))*/;
|
||||
|
||||
void cloudlog_bind(const char* k, const char* v);
|
||||
|
||||
#define cloudlog(lvl, fmt, ...) cloudlog_e(lvl, __FILE__, __LINE__, \
|
||||
__func__, \
|
||||
fmt, ## __VA_ARGS__)
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "selfdrive/hardware/hw.h"
|
||||
|
||||
const char *SWAGLOG_ADDR = "ipc:///tmp/logmessage";
|
||||
std::string daemon_name = "testy";
|
||||
std::string dongle_id = "test_dongle_id";
|
||||
|
||||
void log_thread(int msg, int msg_cnt) {
|
||||
|
@ -43,9 +44,10 @@ void recv_log(void *zctx, int thread_cnt, int thread_msg_cnt) {
|
|||
REQUIRE(msg["levelnum"].int_value() == CLOUDLOG_DEBUG);
|
||||
REQUIRE_THAT(msg["filename"].string_value(), Catch::Contains("test_swaglog.cc"));
|
||||
REQUIRE(msg["funcname"].string_value() == "log_thread");
|
||||
REQUIRE(msg["lineno"].int_value() == 17);
|
||||
REQUIRE(msg["lineno"].int_value() == 18); // TODO: do this automatically
|
||||
|
||||
auto ctx = msg["ctx"];
|
||||
REQUIRE(ctx["daemon"].string_value() == daemon_name);
|
||||
REQUIRE(ctx["dongle_id"].string_value() == dongle_id);
|
||||
REQUIRE(ctx["version"].string_value() == COMMA_VERSION);
|
||||
REQUIRE(ctx["dirty"].bool_value() == true);
|
||||
|
@ -68,6 +70,7 @@ void recv_log(void *zctx, int thread_cnt, int thread_msg_cnt) {
|
|||
}
|
||||
|
||||
TEST_CASE("swaglog") {
|
||||
setenv("MANAGER_DAEMON", daemon_name.c_str(), 1);
|
||||
setenv("DONGLE_ID", dongle_id.c_str(), 1);
|
||||
setenv("dirty", "1", 1);
|
||||
const int thread_cnt = 5;
|
||||
|
|
|
@ -48,7 +48,9 @@ def launcher(proc: str, name: str) -> None:
|
|||
raise
|
||||
|
||||
|
||||
def nativelauncher(pargs: List[str], cwd: str) -> None:
|
||||
def nativelauncher(pargs: List[str], cwd: str, name: str) -> None:
|
||||
os.environ['MANAGER_DAEMON'] = name
|
||||
|
||||
# exec the process
|
||||
os.chdir(cwd)
|
||||
os.execvp(pargs[0], pargs)
|
||||
|
@ -203,7 +205,7 @@ class NativeProcess(ManagerProcess):
|
|||
|
||||
cwd = os.path.join(BASEDIR, self.cwd)
|
||||
cloudlog.info(f"starting process {self.name}")
|
||||
self.proc = Process(name=self.name, target=nativelauncher, args=(self.cmdline, cwd))
|
||||
self.proc = Process(name=self.name, target=nativelauncher, args=(self.cmdline, cwd, self.name))
|
||||
self.proc.start()
|
||||
self.watchdog_seen = False
|
||||
self.shutting_down = False
|
||||
|
|
Loading…
Reference in New Issue