aboutsummaryrefslogtreecommitdiff
path: root/core/salis.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/salis.c')
-rw-r--r--core/salis.c193
1 files changed, 81 insertions, 112 deletions
diff --git a/core/salis.c b/core/salis.c
index 135fa4a..ed96944 100644
--- a/core/salis.c
+++ b/core/salis.c
@@ -27,10 +27,10 @@
#if defined(DATA_PUSH)
#define DATA_PUSH_BUSY_TIMEOUT 600000
-#define EVENT_ARRAYS \
- EVENT_ARRAY(0, aev) /* allocation events array */ \
- EVENT_ARRAY(1, eev) /* executions events array */ \
- EVENT_ARRAY(2, bev) /* birth events array */
+#define EVENT_ARRAYS(core) \
+ EVENT_ARRAY(core, 0, aev) /* allocation events array */ \
+ EVENT_ARRAY(core, 1, eev) /* executions events array */ \
+ EVENT_ARRAY(core, 2, bev) /* birth events array */
#define EVENT_ARRAYS_COUNT 3
#endif
@@ -65,8 +65,8 @@ struct Core {
uint64_t eliv; // executions within not-owned live code counter (parasites)
uint64_t edea; // executions within dead code counter
-#define EVENT_ARRAY(_, ev) uint64_t ev##a[MVEC_SIZE];
- EVENT_ARRAYS
+#define EVENT_ARRAY(core, index, ev) uint64_t ev##a[MVEC_SIZE];
+ EVENT_ARRAYS(core)
#undef EVENT_ARRAY
#define CORE_DATA_FIELD(type, name) type name;
@@ -459,9 +459,9 @@ void core_save(FILE *f, const struct Core *core) {
fwrite(core->pvec, sizeof(struct Proc), core->pcap, f);
fwrite(core->mvec, sizeof(uint8_t), MVEC_SIZE, f);
#if defined(DATA_PUSH)
-#define EVENT_ARRAY(_, ev) \
+#define EVENT_ARRAY(core, index, ev) \
fwrite(core->ev##a, sizeof(uint64_t), MVEC_SIZE, f);
- EVENT_ARRAYS
+ EVENT_ARRAYS(core)
#undef EVENT_ARRAY
#endif
@@ -557,9 +557,9 @@ void core_load(FILE *f, struct Core *core) {
fread(core->pvec, sizeof(struct Proc), core->pcap, f);
fread(core->mvec, sizeof(uint8_t), MVEC_SIZE, f);
#if defined(DATA_PUSH)
-#define EVENT_ARRAY(_, ev) \
+#define EVENT_ARRAY(core, index, ev) \
fread(core->ev##a, sizeof(uint64_t), MVEC_SIZE, f);
- EVENT_ARRAYS
+ EVENT_ARRAYS(core)
#undef EVENT_ARRAY
#endif
@@ -744,6 +744,10 @@ void salis_exec_sql(int blob_cnt, const void **blobs, const int *blob_sizes, con
vsprintf(sql_str, sql_format, args);
va_end(args);
+ FILE *temp = fopen("/tmp/salis.temp", "a");
+ fprintf(temp, "EXECUTING SQL: %s\n", sql_str);
+ fclose(temp);
+
int sql_res;
sqlite3_stmt *sql_stmt;
@@ -784,10 +788,13 @@ void salis_exec_sql(int blob_cnt, const void **blobs, const int *blob_sizes, con
void salis_push_data_header(void) {
assert(g_sim_data);
- g_info("Creating general table in SQLite database");
+ g_info("Creating core table in SQLite database");
salis_exec_sql(
0, NULL, NULL,
- "create table general ("
+ "create table core ("
+#define EVENT_ARRAY(core, index, ev) \
+ #ev "_size_" #core " int not null, " \
+ #ev "_" #core " blob not null, "
#define FOR_CORE(i) \
"cycl_" #i " int not null, " \
"mall_" #i " int not null, " \
@@ -799,42 +806,15 @@ void salis_push_data_header(void) {
"emb0_" #i " int not null, " \
"emb1_" #i " int not null, " \
"eliv_" #i " int not null, " \
- "edea_" #i " int not null, "
+ "edea_" #i " int not null, " \
+ EVENT_ARRAYS(i)
FOR_CORES
#undef FOR_CORE
+#undef EVENT_ARRAY
"step int not null"
");"
);
- // Memory events
- for (int i = 0; i < CORES; ++i) {
- for (int j = 0; j < EVENT_ARRAYS_COUNT; ++j) {
- char *pref = NULL;
-
- switch (j) {
-#define EVENT_ARRAY(idx, ev) \
- case idx: pref = #ev; break;
- EVENT_ARRAYS
-#undef EVENT_ARRAY
- default: assert(false);
- }
-
- g_info("Creating %s_%d table in SQLite database", pref, i);
- salis_exec_sql(
- 0, NULL, NULL,
- "create table %s_%d ("
-#define FOR_CORE(i) "cycl_" #i " int not null, "
- FOR_CORES
-#undef FOR_CORE
- "size int not null, "
- "evts blob not null ,"
- "step int not null"
- ");",
- pref, i
- );
- }
- }
-
arch_push_data_header();
}
#endif
@@ -858,10 +838,50 @@ void salis_push_data_line(void) {
amb1[i] /= core->pnum;
}
- g_info("Pushing row to general table in SQLite database");
+ // 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];
+
+ for (int i = 0; i < CORES; ++i) {
+ for (int j = 0; j < EVENT_ARRAYS_COUNT; ++j) {
+ uint64_t *in = NULL;
+
+ switch (j) {
+#define EVENT_ARRAY(core, idx, ev) \
+ case idx: in = g_cores[i].ev##a; break;
+ EVENT_ARRAYS(core)
+#undef EVENT_ARRAY
+ default: assert(false);
+ }
+
+ // Compress event data
+ struct DeflateParams *params = &g_eva_deflate_params[i][j];
+ params->size = EVA_SIZE,
+ params->in = (Bytef *)in,
+ params->out = (Bytef *)malloc(EVA_SIZE),
+ thrd_create(&g_eva_thrds[i][j], (thrd_start_t)salis_deflate, params);
+ }
+ }
+
+ 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;
+ }
+ }
+
+ g_info("Pushing row to core table in SQLite database");
salis_exec_sql(
- 0, NULL, NULL,
- "insert into general ("
+ CORES * EVENT_ARRAYS_COUNT, (const void **)blobs, (int *)blob_sizes,
+ "insert into core ("
+#define EVENT_ARRAY(core, index, ev) \
+ #ev "_size_" #core ", " \
+ #ev "_" #core ", "
#define FOR_CORE(i) \
"cycl_" #i ", " \
"mall_" #i ", " \
@@ -873,16 +893,25 @@ void salis_push_data_line(void) {
"emb0_" #i ", " \
"emb1_" #i ", " \
"eliv_" #i ", " \
- "edea_" #i ", "
+ "edea_" #i ", " \
+ EVENT_ARRAYS(i)
FOR_CORES
#undef FOR_CORE
+#undef EVENT_ARRAY
"step"
") values ("
-#define FOR_CORE(i) "%ld, %ld, %ld, %ld, %ld, %f, %f, %ld, %ld, %ld, %ld, "
+#define EVENT_ARRAY(core, index, ev) \
+ "%ld, ?,"
+#define FOR_CORE(i) \
+ "%ld, %ld, %ld, %ld, %ld, %f, %f, %ld, %ld, %ld, %ld, " \
+ EVENT_ARRAYS(i)
FOR_CORES
#undef FOR_CORE
+#undef EVENT_ARRAY
"%ld"
");",
+#define EVENT_ARRAY(core, index, ev) \
+ blob_sizes[core][index],
#define FOR_CORE(i) \
g_cores[i].cycl, \
g_cores[i].mall, \
@@ -894,77 +923,17 @@ void salis_push_data_line(void) {
g_cores[i].emb0, \
g_cores[i].emb1, \
g_cores[i].eliv, \
- g_cores[i].edea,
+ g_cores[i].edea, \
+ EVENT_ARRAYS(i)
FOR_CORES
#undef FOR_CORE
+#undef EVENT_ARRAY
g_steps
);
- // Insert generic memory events
- // Compression (deflation) is CPU intensive so it is done in parallel
- memset(&g_eva_deflate_params, 0, sizeof(struct DeflateParams) * CORES * EVENT_ARRAYS_COUNT);
-
for (int i = 0; i < CORES; ++i) {
for (int j = 0; j < EVENT_ARRAYS_COUNT; ++j) {
- uint64_t *in = NULL;
-
- switch (j) {
-#define EVENT_ARRAY(idx, ev) \
- case idx: in = g_cores[i].ev##a; break;
- EVENT_ARRAYS
-#undef EVENT_ARRAY
- default: assert(false);
- }
-
- // Compress event data
struct DeflateParams *params = &g_eva_deflate_params[i][j];
- params->size = EVA_SIZE,
- params->in = (Bytef *)in,
- params->out = (Bytef *)malloc(EVA_SIZE),
- thrd_create(&g_eva_thrds[i][j], (thrd_start_t)salis_deflate, params);
- }
- }
-
- for (int i = 0; i < CORES; ++i) {
- for (int j = 0; j < EVENT_ARRAYS_COUNT; ++j) {
- char *pref = NULL;
-
- switch (j) {
-#define EVENT_ARRAY(idx, ev) \
- case idx: pref = #ev; break;
- EVENT_ARRAYS
-#undef EVENT_ARRAY
- default: assert(false);
- }
-
- thrd_join(g_eva_thrds[i][j], NULL);
-
- // Insert blob
- struct DeflateParams *params = &g_eva_deflate_params[i][j];
- const void *blob = params->out;
- int blob_size = params->strm.total_out;
-
- g_info("Pushing row to %s_%d table in SQLite database", pref, i);
- salis_exec_sql(
- 1, &blob, &blob_size,
- "insert into %s_%d ("
-#define FOR_CORE(i) "cycl_" #i ", "
- FOR_CORES
-#undef FOR_CORE
- "size, evts, step"
- ") values ("
-#define FOR_CORE(i) "%ld, "
- FOR_CORES
-#undef FOR_CORE
- "%ld, ?, %ld"
- ");",
- pref, i,
-#define FOR_CORE(i) g_cores[i].cycl,
- FOR_CORES
-#undef FOR_CORE
- blob_size, g_steps
- );
-
salis_deflate_end(params);
free(params->out);
}
@@ -979,9 +948,9 @@ void salis_push_data_line(void) {
core->eliv = 0;
core->edea = 0;
-#define EVENT_ARRAY(_, ev) \
+#define EVENT_ARRAY(core, index, ev) \
memset(core->ev##a, 0, EVA_SIZE);
- EVENT_ARRAYS
+ EVENT_ARRAYS(core)
#undef EVENT_ARRAY
}