refactor: Manage all py plugins (md and exe) in one class
All calls to/from python are performed on one thread via a simple message queue (necessary because of the global interpreter lock).
This commit is contained in:
1 parent
c7db105533
commit
8c23665d65
29 files changed
+855
-602
No files matched your search
@@ -0,0 +1,116 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
#include "spark/core/TimeSpan.h"
|
||||
#include "spark/logging/trace_log.h"
|
||||
#include "spark/os/os.h"
|
||||
#include "spark/utils/thread_id.h"
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
|
||||
namespace python_interop::logs {
|
||||
|
||||
struct StartingLog {
|
||||
std::string instance_name;
|
||||
std::string thread_name;
|
||||
std::int64_t thread_id;
|
||||
|
||||
StartingLog(std::string instance_name)
|
||||
: instance_name(std::move(instance_name)),
|
||||
thread_name(bts::os::get_thread_name()),
|
||||
thread_id(BTS_THIS_THREAD_ID) {}
|
||||
};
|
||||
|
||||
struct StartedLog {
|
||||
std::string instance_name;
|
||||
std::string thread_name;
|
||||
std::int64_t thread_id;
|
||||
bts::core::TimeSpan duration;
|
||||
|
||||
StartedLog(std::string instance_name, bts::core::TimeSpan duration)
|
||||
: instance_name(std::move(instance_name)),
|
||||
thread_name(bts::os::get_thread_name()), thread_id(BTS_THIS_THREAD_ID),
|
||||
duration(duration) {}
|
||||
};
|
||||
|
||||
struct InvokingLog {
|
||||
int count;
|
||||
std::string thread_name;
|
||||
std::int64_t thread_id;
|
||||
|
||||
InvokingLog(int count)
|
||||
: count(count), thread_name(bts::os::get_thread_name()),
|
||||
thread_id(BTS_THIS_THREAD_ID) {}
|
||||
};
|
||||
|
||||
struct InvokedLog {
|
||||
int count;
|
||||
bts::core::TimeSpan duration;
|
||||
std::string thread_name;
|
||||
std::int64_t thread_id;
|
||||
|
||||
InvokedLog(int count, bts::core::TimeSpan dequeue_duration)
|
||||
: count(count), duration(dequeue_duration),
|
||||
thread_name(bts::os::get_thread_name()),
|
||||
thread_id(BTS_THIS_THREAD_ID) {}
|
||||
};
|
||||
|
||||
} // namespace python_interop::logs
|
||||
|
||||
FMT_IMPL(
|
||||
python_interop::logs::StartingLog,
|
||||
l,
|
||||
R"({{ "name": "{}", "ev": "STARTING", "tn": "{}", "tid": "{}" }})",
|
||||
l.instance_name,
|
||||
l.thread_name,
|
||||
l.thread_id);
|
||||
|
||||
FMT_IMPL(
|
||||
python_interop::logs::StartedLog,
|
||||
l,
|
||||
R"({{ "name": "{}", "ev": "STARTED", "dur": "{:.3f}ms", "tn": "{}", "tid": "{}" }})",
|
||||
l.instance_name,
|
||||
l.duration.total_millis(),
|
||||
l.thread_name,
|
||||
l.thread_id);
|
||||
|
||||
FMT_IMPL(
|
||||
python_interop::logs::InvokingLog,
|
||||
l,
|
||||
R"({{ "ev": "INVOKING", "count": {}, "tn": "{}", "tid": "{}" }})",
|
||||
l.count,
|
||||
l.thread_name,
|
||||
l.thread_id);
|
||||
|
||||
FMT_IMPL(
|
||||
python_interop::logs::InvokedLog,
|
||||
l,
|
||||
R"({{ "ev": "INVOKED", "count": {}, "dur": "{:.3f}ms", "tn": "{}", "tid": "{}" }})",
|
||||
l.count,
|
||||
l.duration.total_millis(),
|
||||
l.thread_name,
|
||||
l.thread_id);
|
||||
|
||||
#define LOG_STARTING(type_name, instance_name) \
|
||||
LOG_TRACE_PARAMS( \
|
||||
Gen, bts::Info, string("py_plugin"), string("start_" type_name), \
|
||||
python_interop::logs::StartingLog{instance_name})
|
||||
|
||||
#define LOG_STARTED(type_name, instance_name, dur) \
|
||||
LOG_TRACE_PARAMS( \
|
||||
Gen, bts::Info, string("py_plugin"), string("start_" type_name), \
|
||||
python_interop::logs::StartedLog(instance_name, dur))
|
||||
|
||||
#define LOG_INVOKING(count) \
|
||||
LOG_TRACE_PARAMS( \
|
||||
Gen, bts::Info, string("py_plugin"), string("work"), \
|
||||
python_interop::logs::InvokingLog(count))
|
||||
|
||||
#define LOG_INVOKED(count, duration) \
|
||||
LOG_TRACE_PARAMS( \
|
||||
Gen, bts::Info, string("py_plugin"), string("work"), \
|
||||
python_interop::logs::InvokedLog(count, duration))
|
||||
|
||||
#define LOG_WORK_ERROR(subsystem, params) \
|
||||
LOG_TRACE_PARAMS(subsystem, bts::Error, string("py_plugin"), string("work"), params)
|
||||
Reference in new issue
Block a user