diff options
Diffstat (limited to 'core/salis.c')
| -rw-r--r-- | core/salis.c | 71 |
1 files changed, 45 insertions, 26 deletions
diff --git a/core/salis.c b/core/salis.c index bf7ec44..11c6efb 100644 --- a/core/salis.c +++ b/core/salis.c @@ -24,8 +24,9 @@ #include <threads.h> #include <zlib.h> -#include "logger.c" +#include "common.c" #include "compress.c" +#include "logger.c" #include "sql.c" // ---------------------------------------------------------------------------- @@ -103,6 +104,7 @@ const struct Proc g_dead_proc; #if defined(COMMAND_NEW) || defined(COMMAND_LOAD) char g_asav_pbuf[AUTOSAVE_NAME_LEN]; +char g_eva_pbuf[EVA_SAVE_NAME_LEN]; #endif thrd_t g_eva_thrds[CORES][EVENT_ARRAYS_COUNT]; @@ -145,7 +147,7 @@ const char *arch_mnemonic(uint8_t inst); #if defined(COMMAND_NEW) void arch_push_data_header(void); #endif -void arch_push_data_line(void); +void arch_push_data_line(FILE *eva_file); // ---------------------------------------------------------------------------- // [section] memory vector functions @@ -725,11 +727,11 @@ void salis_push_data_header(void) { log_info("Creating core table in SQLite database"); sql_exec( - 0, NULL, NULL, NULL, NULL, + NULL, NULL, "create table core (" #define EVENT_ARRAY(core, index, ev) \ - #ev "_size_" #core " int not null, " \ - #ev "_" #core " blob not null, " + #ev EVENT_ARRAYS_SIZE_COL_MARKER #core " int not null, " \ + #ev "_" #core " blob, " #define FOR_CORE(i) \ "cycl_" #i " int not null, " \ "mall_" #i " int not null, " \ @@ -776,8 +778,7 @@ void salis_push_data_line(void) { // Compress event arrays // Compression (deflation) is CPU intensive so it's done in parallel memset(&g_eva_deflate_params, 0, sizeof(struct DeflateParams) * CORES * EVENT_ARRAYS_COUNT); - const void *blobs[CORES][EVENT_ARRAYS_COUNT]; - int blob_sizes[CORES][EVENT_ARRAYS_COUNT]; + uint64_t blob_sizes[CORES][EVENT_ARRAYS_COUNT]; for (int i = 0; i < CORES; ++i) { for (int j = 0; j < EVENT_ARRAYS_COUNT; ++j) { @@ -793,30 +794,45 @@ void salis_push_data_line(void) { // Compress event data struct DeflateParams *params = &g_eva_deflate_params[i][j]; - params->size = EVA_SIZE, + params->size = EVENT_ARRAYS_SIZE, params->in = (Bytef *)in, - params->out = (Bytef *)malloc(EVA_SIZE), + params->out = (Bytef *)malloc(EVENT_ARRAYS_SIZE), thrd_create(&g_eva_thrds[i][j], (thrd_start_t)comp_deflate, params); } } + int rem = snprintf( + g_eva_pbuf, + EVA_SAVE_NAME_LEN, + "%s/evas-%#018lx", + SIM_EDIR, + g_steps + ); + + assert(rem >= 0); + assert(rem < EVA_SAVE_NAME_LEN); + (void)rem; + + log_info("Saving event-array data to file: %s", g_eva_pbuf); + FILE *eva_file = fopen(g_eva_pbuf, "wb"); + for (int i = 0; i < CORES; ++i) { for (int j = 0; j < EVENT_ARRAYS_COUNT; ++j) { thrd_join(g_eva_thrds[i][j], NULL); - struct DeflateParams *params = &g_eva_deflate_params[i][j]; - blobs[i][j] = params->out; blob_sizes[i][j] = params->strm.total_out; + fwrite(params->out, sizeof(char), blob_sizes[i][j], eva_file); + comp_deflate_end(params); + free(params->out); } } log_info("Pushing row to core table in SQLite database"); sql_exec( - CORES * EVENT_ARRAYS_COUNT, (const void **)blobs, (int *)blob_sizes, NULL, NULL, + NULL, NULL, "insert into core (" #define EVENT_ARRAY(core, index, ev) \ - #ev "_size_" #core ", " \ - #ev "_" #core ", " + #ev EVENT_ARRAYS_SIZE_COL_MARKER #core ", " #define FOR_CORE(i) \ "cycl_" #i ", " \ "mall_" #i ", " \ @@ -836,9 +852,19 @@ void salis_push_data_line(void) { "step" ") values (" #define EVENT_ARRAY(core, index, ev) \ - "%ld, ?," + "%ld, " #define FOR_CORE(i) \ - "%ld, %ld, %ld, %ld, %ld, %f, %f, %ld, %ld, %ld, %ld, " \ + "%ld, " \ + "%ld, " \ + "%ld, " \ + "%ld, " \ + "%ld, " \ + "%f, " \ + "%f, " \ + "%ld, " \ + "%ld, " \ + "%ld, " \ + "%ld, " \ EVENT_ARRAYS(i) FOR_CORES #undef FOR_CORE @@ -866,14 +892,6 @@ void salis_push_data_line(void) { g_steps ); - for (int i = 0; i < CORES; ++i) { - for (int j = 0; j < EVENT_ARRAYS_COUNT; ++j) { - struct DeflateParams *params = &g_eva_deflate_params[i][j]; - comp_deflate_end(params); - free(params->out); - } - } - // Reset data aggregation fields for (int i = 0; i < CORES; ++i) { struct Core *core = &g_cores[i]; @@ -884,13 +902,14 @@ void salis_push_data_line(void) { core->edea = 0; #define EVENT_ARRAY(core, index, ev) \ - memset(core->ev##a, 0, EVA_SIZE); + memset(core->ev##a, 0, EVENT_ARRAYS_SIZE); EVENT_ARRAYS(core) #undef EVENT_ARRAY } // Push arch-specific data - arch_push_data_line(); + arch_push_data_line(eva_file); + fclose(eva_file); } #if defined(COMMAND_NEW) |
