info about shared memory, calls, events and log files.
This commit is contained in:
@@ -48,6 +48,9 @@ typedef struct {
|
||||
|
||||
bool rkt_webview_prg_started;
|
||||
bool valid;
|
||||
int function_calls;
|
||||
int events;
|
||||
std::string log_file;
|
||||
} Handle_t;
|
||||
|
||||
Handle_t *handler = nullptr;
|
||||
@@ -98,6 +101,7 @@ bool runRktWebview(Handle_t *handler)
|
||||
if (td == nullptr) { td = "C:\\"; }
|
||||
std::string tmpdir = td;
|
||||
std::string logfile = tmpdir + "\\" + "rktwebview.log"; //handler->name + ".log";
|
||||
handler->log_file = logfile;
|
||||
|
||||
SECURITY_ATTRIBUTES sa;
|
||||
sa.nLength = sizeof(sa);
|
||||
@@ -105,10 +109,10 @@ bool runRktWebview(Handle_t *handler)
|
||||
sa.bInheritHandle = TRUE;
|
||||
|
||||
HANDLE h = CreateFile(logfile.c_str(),
|
||||
0, //FILE_APPEND_DATA,
|
||||
FILE_WRITE_DATA, //FILE_APPEND_DATA,
|
||||
FILE_SHARE_WRITE | FILE_SHARE_READ,
|
||||
&sa,
|
||||
OPEN_ALWAYS,
|
||||
CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL);
|
||||
|
||||
@@ -145,6 +149,7 @@ bool runRktWebview(Handle_t *handler)
|
||||
const char *homedir = pw->pw_dir;
|
||||
|
||||
std::string log_file = std::string(homedir) + "/.racket-webview.log";
|
||||
handler->log_file = log_file;
|
||||
|
||||
posix_spawn_file_actions_t action;
|
||||
posix_spawn_file_actions_init(&action);
|
||||
@@ -174,25 +179,6 @@ void rkt_webview_cleanup()
|
||||
// So we would need to cleanup at exit of racket/drracket.
|
||||
// Cleaning up when exiting the current custodian is not enough.
|
||||
|
||||
/*
|
||||
QApplication *app = handler->app();
|
||||
if (app != nullptr) {
|
||||
// testing with #:custodian (current-custodian)
|
||||
QTimer t;
|
||||
QObject::connect(&t, &QTimer::timeout, app, [app]() {
|
||||
fprintf(stderr, "Quitting\n");
|
||||
app->quit();
|
||||
});
|
||||
t.setSingleShot(true);
|
||||
t.start(250);
|
||||
fprintf(stderr, "Executing app\n");
|
||||
app->exec();
|
||||
fprintf(stderr, "App exited\n");
|
||||
delete handler;
|
||||
handler = nullptr;
|
||||
}
|
||||
*/
|
||||
|
||||
if (handler->valid) {
|
||||
INFO0("Sending quit message\n");
|
||||
handler->command_queue->enqueue(CMD_QUIT);
|
||||
@@ -240,6 +226,8 @@ void rkt_webview_init()
|
||||
handler = new Handle_t;
|
||||
handler->valid = true;
|
||||
handler->name = buf;
|
||||
handler->function_calls = 0;
|
||||
handler->events = 0;
|
||||
|
||||
handler->shm_size = SHM_SIZE;
|
||||
handler->shm = new Shm(handler->name.data(), handler->shm_size, true);
|
||||
@@ -253,6 +241,8 @@ void rkt_webview_init()
|
||||
handler->rkt_webview_prg_started = runRktWebview(handler);
|
||||
if (!handler->rkt_webview_prg_started) { handler->valid = false; }
|
||||
#endif
|
||||
} else {
|
||||
handler->function_calls++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,6 +270,7 @@ static inline bool validHandle()
|
||||
#define FAIL_WV if (!validHandle()) { return 0; }
|
||||
#define NOOP_HANDLE if (!validHandle()) { return; }
|
||||
#define FAIL_CALL_JS if (!validHandle()) { return nullptr; }
|
||||
#define FAIL_INFO FAIL_CALL_JS
|
||||
|
||||
rkt_wv_context_t rkt_webview_new_context(const char *boilerplate_js, const char *optional_server_cert_pem)
|
||||
{
|
||||
@@ -512,19 +503,7 @@ void rkt_webview_set_ou_token(rktwebview_t wv, const char *token)
|
||||
|
||||
void rkt_webview_free_data(rkt_data_t *d)
|
||||
{
|
||||
if (d == nullptr) { return; }
|
||||
|
||||
if (d->kind == version) {
|
||||
free(d);
|
||||
} else if (d->kind == event) {
|
||||
free(d->data.event.event);
|
||||
free(d);
|
||||
} else if (d->kind == js_result) {
|
||||
free(d->data.js_result.value);
|
||||
free(d);
|
||||
} else {
|
||||
ERROR1("UNEXPECTED: data kind %d cannot be freed\n", d->kind);
|
||||
}
|
||||
do_free_data(d);
|
||||
}
|
||||
|
||||
rkt_data_t *rkt_webview_version()
|
||||
@@ -557,6 +536,7 @@ rkt_data_t *rkt_webview_get_event()
|
||||
rkt_data_t *d = reinterpret_cast<rkt_data_t *>(malloc(sizeof(rkt_data_t)));
|
||||
d->kind = rkt_data_kind_t::event;
|
||||
|
||||
handler->events += 1;
|
||||
size_t ds = data.size();
|
||||
d->data.event.event = reinterpret_cast<char *>(malloc(ds + 1));
|
||||
memcpy(d->data.event.event, data.c_str(), ds);
|
||||
@@ -581,3 +561,33 @@ void rkt_webview_env(const char *env_cmds[])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rkt_data_t *rkt_webview_info()
|
||||
{
|
||||
rkt_webview_init();
|
||||
FAIL_INFO
|
||||
|
||||
rkt_data_t *d = new rkt_data_t();
|
||||
d->kind = metrics;
|
||||
|
||||
handler->shm->info(d->data.metrics.shm_usage,
|
||||
d->data.metrics.shm_free_depth,
|
||||
d->data.metrics.shm_free_size,
|
||||
d->data.metrics.shm_item_depth,
|
||||
d->data.metrics.shm_item_size,
|
||||
d->data.metrics.shm_item_usage_factor);
|
||||
|
||||
JSON j;
|
||||
handler->command_queue->enqueue(CMD_INFO, j.dump());
|
||||
|
||||
int open_windows_result;
|
||||
std::string none;
|
||||
handler->command_result_queue->dequeue(open_windows_result, none, true);
|
||||
|
||||
d->data.metrics.open_windows = open_windows_result;
|
||||
d->data.metrics.function_calls = handler->function_calls;
|
||||
d->data.metrics.log_file = strdup(handler->log_file.c_str());
|
||||
d->data.metrics.events = handler->events + handler->event_queue->depth();
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user