refactor: sandbox perf log

master
Sean McBride 3 years ago
parent fb7f657db4
commit f3326dc929

@ -27,7 +27,6 @@ enum RUNTIME_SIGALRM_HANDLER
extern bool runtime_preemption_enabled;
extern uint32_t runtime_processor_speed_MHz;
extern uint32_t runtime_quantum_us;
extern FILE * runtime_sandbox_perf_log;
extern enum RUNTIME_SIGALRM_HANDLER runtime_sigalrm_handler;
extern pthread_t * runtime_worker_threads;
extern uint32_t runtime_worker_threads_count;

@ -0,0 +1,70 @@
#pragma once
#include "runtime.h"
#include "sandbox_types.h"
extern FILE *sandbox_perf_log;
/**
* @brief Prints headers for the per-sandbox perf logs
*/
static inline void
sandbox_perf_log_print_header()
{
if (sandbox_perf_log == NULL) { perror("sandbox perf log"); }
fprintf(sandbox_perf_log,
"id,module,port,state,deadline,actual,queued,uninitialized,allocated,initialized,runnable,preempted,"
"running_sys,running_user,asleep,returned,complete,error,proc_MHz,memory\n");
}
/**
* Prints key performance metrics for a sandbox to sandbox_perf_log
* This is defined by an environment variable
* @param sandbox
*/
static inline void
sandbox_perf_log_print_entry(struct sandbox *sandbox)
{
/* If the log was not defined by an environment variable, early out */
if (sandbox_perf_log == NULL) return;
uint64_t queued_duration = sandbox->timestamp_of.allocation - sandbox->timestamp_of.request_arrival;
/*
* Assumption: A sandbox is never able to free pages. If linear memory management
* becomes more intelligent, then peak linear memory size needs to be tracked
* seperately from current linear memory size.
*/
fprintf(sandbox_perf_log, "%lu,%s,%d,%s,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%u,%u\n",
sandbox->id, sandbox->module->name, sandbox->module->port, sandbox_state_stringify(sandbox->state),
sandbox->module->relative_deadline, sandbox->total_time, queued_duration,
sandbox->duration_of_state[SANDBOX_UNINITIALIZED], sandbox->duration_of_state[SANDBOX_ALLOCATED],
sandbox->duration_of_state[SANDBOX_INITIALIZED], sandbox->duration_of_state[SANDBOX_RUNNABLE],
sandbox->duration_of_state[SANDBOX_PREEMPTED], sandbox->duration_of_state[SANDBOX_RUNNING_SYS],
sandbox->duration_of_state[SANDBOX_RUNNING_USER], sandbox->duration_of_state[SANDBOX_ASLEEP],
sandbox->duration_of_state[SANDBOX_RETURNED], sandbox->duration_of_state[SANDBOX_COMPLETE],
sandbox->duration_of_state[SANDBOX_ERROR], runtime_processor_speed_MHz, sandbox->memory.size);
}
static inline void
sandbox_perf_log_init()
{
char *sandbox_perf_log_path = getenv("SLEDGE_SANDBOX_PERF_LOG");
if (sandbox_perf_log_path != NULL) {
printf("\tSandbox Performance Log: %s\n", sandbox_perf_log_path);
sandbox_perf_log = fopen(sandbox_perf_log_path, "w");
if (sandbox_perf_log == NULL) perror("sandbox_perf_log_init\n");
sandbox_perf_log_print_header();
} else {
printf("\tSandbox Performance Log: Disabled\n");
}
}
static inline void
sandbox_perf_log_cleanup()
{
if (sandbox_perf_log != NULL) {
fflush(sandbox_perf_log);
fclose(sandbox_perf_log);
}
}

@ -1,34 +0,0 @@
#pragma once
#include "runtime.h"
#include "sandbox_types.h"
/**
* Prints key performance metrics for a sandbox to runtime_sandbox_perf_log
* This is defined by an environment variable
* @param sandbox
*/
static inline void
sandbox_print_perf(struct sandbox *sandbox)
{
/* If the log was not defined by an environment variable, early out */
if (runtime_sandbox_perf_log == NULL) return;
uint64_t queued_duration = sandbox->timestamp_of.allocation - sandbox->timestamp_of.request_arrival;
/*
* Assumption: A sandbox is never able to free pages. If linear memory management
* becomes more intelligent, then peak linear memory size needs to be tracked
* seperately from current linear memory size.
*/
fprintf(runtime_sandbox_perf_log,
"%lu,%s,%d,%s,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%u,%u\n", sandbox->id,
sandbox->module->name, sandbox->module->port, sandbox_state_stringify(sandbox->state),
sandbox->module->relative_deadline, sandbox->total_time, queued_duration,
sandbox->duration_of_state[SANDBOX_UNINITIALIZED], sandbox->duration_of_state[SANDBOX_ALLOCATED],
sandbox->duration_of_state[SANDBOX_INITIALIZED], sandbox->duration_of_state[SANDBOX_RUNNABLE],
sandbox->duration_of_state[SANDBOX_PREEMPTED], sandbox->duration_of_state[SANDBOX_RUNNING_SYS],
sandbox->duration_of_state[SANDBOX_RUNNING_USER], sandbox->duration_of_state[SANDBOX_ASLEEP],
sandbox->duration_of_state[SANDBOX_RETURNED], sandbox->duration_of_state[SANDBOX_COMPLETE],
sandbox->duration_of_state[SANDBOX_ERROR], runtime_processor_speed_MHz, sandbox->memory.size);
}

@ -7,7 +7,7 @@
#include "panic.h"
#include "local_completion_queue.h"
#include "sandbox_functions.h"
#include "sandbox_print_perf.h"
#include "sandbox_perf_log.h"
#include "sandbox_state.h"
#include "sandbox_state_history.h"
#include "sandbox_summarize_page_allocations.h"
@ -51,7 +51,7 @@ sandbox_set_as_complete(struct sandbox *sandbox, sandbox_state_t last_state)
admissions_control_subtract(sandbox->admissions_estimate);
/* Terminal State Logging */
sandbox_print_perf(sandbox);
sandbox_perf_log_print_entry(sandbox);
sandbox_summarize_page_allocations(sandbox);
/* Do not touch sandbox state after adding to completion queue to avoid use-after-free bugs */

@ -8,7 +8,7 @@
#include "local_runqueue.h"
#include "sandbox_state.h"
#include "sandbox_functions.h"
#include "sandbox_print_perf.h"
#include "sandbox_perf_log.h"
#include "sandbox_state_history.h"
#include "sandbox_summarize_page_allocations.h"
#include "panic.h"
@ -58,7 +58,7 @@ sandbox_set_as_error(struct sandbox *sandbox, sandbox_state_t last_state)
admissions_control_subtract(sandbox->admissions_estimate);
/* Terminal State Logging */
sandbox_print_perf(sandbox);
sandbox_perf_log_print_entry(sandbox);
sandbox_summarize_page_allocations(sandbox);
/* Do not touch sandbox after adding to completion queue to avoid use-after-free bugs */

@ -31,9 +31,6 @@ uint32_t runtime_processor_speed_MHz = 0;
uint32_t runtime_total_online_processors = 0;
uint32_t runtime_worker_threads_count = 0;
FILE *runtime_sandbox_perf_log = NULL;
enum RUNTIME_SIGALRM_HANDLER runtime_sigalrm_handler = RUNTIME_SIGALRM_HANDLER_BROADCAST;
int runtime_worker_core_count;
@ -218,17 +215,7 @@ runtime_configure()
}
printf("\tQuantum: %u us\n", runtime_quantum_us);
/* Runtime Perf Log */
char *runtime_sandbox_perf_log_path = getenv("SLEDGE_SANDBOX_PERF_LOG");
if (runtime_sandbox_perf_log_path != NULL) {
printf("\tSandbox Performance Log: %s\n", runtime_sandbox_perf_log_path);
runtime_sandbox_perf_log = fopen(runtime_sandbox_perf_log_path, "w");
if (runtime_sandbox_perf_log == NULL) { perror("sandbox perf log"); }
fprintf(runtime_sandbox_perf_log, "id,module,port,state,deadline,actual,queued,initializing,runnable,"
"running,asleep,returned,proc_MHz,memory\n");
} else {
printf("\tSandbox Performance Log: Disabled\n");
}
sandbox_perf_log_init();
}
void

@ -40,7 +40,7 @@ uint64_t *runtime_worker_threads_deadline;
void
runtime_cleanup()
{
if (runtime_sandbox_perf_log != NULL) fflush(runtime_sandbox_perf_log);
sandbox_perf_log_cleanup();
if (runtime_worker_threads_deadline) free(runtime_worker_threads_deadline);
if (runtime_worker_threads_argument) free(runtime_worker_threads_argument);

@ -0,0 +1,3 @@
#include "sandbox_perf_log.h"
FILE *sandbox_perf_log = NULL;

@ -14,7 +14,7 @@ const char *sandbox_state_labels[SANDBOX_STATE_COUNT] = {
[SANDBOX_INITIALIZED] = "Initialized",
[SANDBOX_RUNNABLE] = "Runnable",
[SANDBOX_PREEMPTED] = "Preempted",
[SANDBOX_RUNNING_SYS] = "Running Kernel",
[SANDBOX_RUNNING_SYS] = "Running Sys",
[SANDBOX_RUNNING_USER] = "Running User",
[SANDBOX_ASLEEP] = "Asleep",
[SANDBOX_RETURNED] = "Returned",

Loading…
Cancel
Save