Move swaglog to cpp + remove another lib (#1470)

old-commit-hash: 46f3665279
This commit is contained in:
Adeeb 2020-05-08 14:46:10 -07:00 committed by GitHub
parent 708d68722c
commit b1cbd898f1
8 changed files with 25 additions and 41 deletions

View File

@ -127,7 +127,6 @@ env = Environment(
"#phonelibs/bzip2",
"#phonelibs/libyuv/include",
"#phonelibs/openmax/include",
"#phonelibs/json/src",
"#phonelibs/json11",
"#phonelibs/eigen",
"#phonelibs/curl/include",
@ -212,7 +211,7 @@ Import('_common', '_visionipc', '_gpucommon', '_gpu_libs')
if SHARED:
common, visionipc, gpucommon = abspath(common), abspath(visionipc), abspath(gpucommon)
else:
common = [_common, 'json']
common = [_common, 'json11']
visionipc = _visionipc
gpucommon = [_gpucommon] + _gpu_libs

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a5934a6cb5c1dd3031adb8eccee3c6419c7c966882c02dd978e772130c8f397e
size 446
oid sha256:d1c7a88b02354d583772474d437fff10a191740d5f06d471a0b61ee9a7957f7a
size 366

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2eb191c6ab7a457fe54a1fa04597ead10876111ffdd936c9ccfca010c258bd11
size 80

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1e39e76315aa470f9a3f8b3bd0dfa56dd07bb9aa2daf36a6b37e7d84b9165e21
size 29298

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8e647e8960b76dd9b022132d9fb9aa115f07ba004ed41b7704add69fd8da5b66
size 3492

View File

@ -167,7 +167,8 @@ selfdrive/common/touch.[c,h]
selfdrive/common/visionipc.[c,h]
selfdrive/common/visionbuf_cl.c
selfdrive/common/ipc.[c,h]
selfdrive/common/swaglog.[c,h]
selfdrive/common/swaglog.h
selfdrive/common/swaglog.cc
selfdrive/common/util.[c,h]
selfdrive/common/efd.[c,h]
selfdrive/common/cqueue.[c,h]
@ -405,8 +406,6 @@ phonelibs/openmax/**
phonelibs/zmq/aarch64/lib/*
phonelibs/json/src/json.c
phonelibs/json/src/json.h
phonelibs/json11/json11.cpp
phonelibs/json11/json11.hpp

View File

@ -5,7 +5,7 @@ if SHARED:
else:
fxn = env.Library
_common = fxn('common', ['params.cc', 'swaglog.c', 'util.c', 'cqueue.c'], LIBS="json")
_common = fxn('common', ['params.cc', 'swaglog.cc', 'util.c', 'cqueue.c'], LIBS="json11")
_visionipc = fxn('visionipc', ['visionipc.c', 'ipc.c'])
files = [

View File

@ -1,15 +1,15 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
#include <string>
#include <string.h>
#include <assert.h>
#include <pthread.h>
#include <zmq.h>
#include <json.h>
#include "json11.hpp"
#include "common/timing.h"
#include "common/version.h"
@ -19,7 +19,7 @@
typedef struct LogState {
pthread_mutex_t lock;
bool inited;
JsonNode *ctx_j;
json11::Json::object ctx_j;
void *zctx;
void *sock;
int print_level;
@ -30,12 +30,12 @@ static LogState s = {
};
static void cloudlog_bind_locked(const char* k, const char* v) {
json_append_member(s.ctx_j, k, json_mkstring(v));
s.ctx_j[k] = v;
}
static void cloudlog_init() {
if (s.inited) return;
s.ctx_j = json_mkobject();
s.ctx_j = json11::Json::object {};
s.zctx = zmq_ctx_new();
s.sock = zmq_socket(s.zctx, ZMQ_PUSH);
zmq_connect(s.sock, "ipc:///tmp/logmessage");
@ -58,8 +58,7 @@ static void cloudlog_init() {
cloudlog_bind_locked("dongle_id", dongle_id);
}
cloudlog_bind_locked("version", COMMA_VERSION);
bool dirty = !getenv("CLEAN");
json_append_member(s.ctx_j, "dirty", json_mkbool(dirty));
s.ctx_j["dirty"] = !getenv("CLEAN");
s.inited = true;
}
@ -84,23 +83,19 @@ void cloudlog_e(int levelnum, const char* filename, int lineno, const char* func
printf("%s: %s\n", filename, msg_buf);
}
JsonNode *log_j = json_mkobject();
assert(log_j);
json11::Json log_j = json11::Json::object {
{"msg", msg_buf},
{"ctx", s.ctx_j},
{"levelnum", levelnum},
{"filename", filename},
{"lineno", lineno},
{"funcname", func},
{"created", seconds_since_epoch()}
};
json_append_member(log_j, "msg", json_mkstring(msg_buf));
json_append_member(log_j, "ctx", s.ctx_j);
json_append_member(log_j, "levelnum", json_mknumber(levelnum));
json_append_member(log_j, "filename", json_mkstring(filename));
json_append_member(log_j, "lineno", json_mknumber(lineno));
json_append_member(log_j, "funcname", json_mkstring(func));
json_append_member(log_j, "created", json_mknumber(seconds_since_epoch()));
char* log_s = json_encode(log_j);
char* log_s = strdup(log_j.dump().c_str());
assert(log_s);
json_remove_from_parent(s.ctx_j);
json_delete(log_j);
free(msg_buf);
char levelnum_c = levelnum;