diff options
| -rw-r--r-- | arch/salis-v1/arch.j2.c | 31 | ||||
| -rw-r--r-- | core.j2.c | 30 |
2 files changed, 34 insertions, 27 deletions
diff --git a/arch/salis-v1/arch.j2.c b/arch/salis-v1/arch.j2.c index 5d2f58a..9c3ea45 100644 --- a/arch/salis-v1/arch.j2.c +++ b/arch/salis-v1/arch.j2.c @@ -829,29 +829,6 @@ const char *arch_mnemonic(uint8_t inst) { } {% if data_push_path is defined %} -void _exec_sql(const char *sql) { - assert(sql); - - int sql_res; - char *sql_err; - - while ((sql_res = sqlite3_exec(g_sim_data, sql, NULL, NULL, &sql_err)) == SQLITE_BUSY) { - g_warn("SQLite database returned error '%d' with message:", sql_res); - g_warn(sql_err); - sqlite3_free(sql_err); - - switch (sql_res) { - case SQLITE_BUSY: - // Only handle busy database errors - g_info("Will retry query..."); - continue; - default: - // Application should fail on all other error conditions - assert(false); - } - } -} - void arch_push_data_header() { assert(g_sim_data); @@ -879,7 +856,7 @@ void arch_push_data_header() { ); g_info("Generating 'trend' table in SQLite database"); - _exec_sql(trend_sql); + salis_exec_sql(trend_sql); // Core-specific instruction data will be queried separately // A table is created for each core @@ -899,7 +876,7 @@ void arch_push_data_header() { ); g_info("Generating '{{ t }}_{{ i }}' table in SQLite database"); - _exec_sql({{ t }}_sql_{{ i }}); + salis_exec_sql({{ t }}_sql_{{ i }}); {% endfor %} {% endfor %} } @@ -992,7 +969,7 @@ void arch_push_data_line() { ); g_info("Pushing row to 'trend' table in SQLite database"); - _exec_sql(trend_sql); + salis_exec_sql(trend_sql); free(trend_sql); {% for t in ["pop", "exe", "wrt"] %} @@ -1037,7 +1014,7 @@ void arch_push_data_line() { ); g_info("Pushing row to '{{ t }}_{{ i }}' table in SQLite database"); - _exec_sql({{ t }}_sql_{{ i }}); + salis_exec_sql({{ t }}_sql_{{ i }}); free({{ t }}_sql_{{ i }}); {% endfor %} {% endfor %} @@ -609,6 +609,31 @@ void salis_auto_save() { } {% endif %} +{% if data_push_path is defined %} +void salis_exec_sql(const char *sql) { + assert(sql); + + int sql_res; + char *sql_err; + + while ((sql_res = sqlite3_exec(g_sim_data, sql, NULL, NULL, &sql_err)) == SQLITE_BUSY) { + g_warn("SQLite database returned error '%d' with message:", sql_res); + g_warn(sql_err); + sqlite3_free(sql_err); + + switch (sql_res) { + case SQLITE_BUSY: + // Only handle busy database errors + g_info("Will retry query..."); + continue; + default: + // Application should fail on all other error conditions + assert(false); + } + } +} +{% endif %} + {% if args.command in ["bench", "new"] %} void salis_init() { assert(g_info); @@ -631,6 +656,11 @@ void salis_init() { // Install busy handler to retry transactions if DB is locked sqlite3_busy_timeout(g_sim_data, {{ data_push_busy_timeout }}); + // Enable Write-Ahead Logging (WAL) + // This seems to help prevent DB locks when displaying live data + // See: https://sqlite.org/wal.html + salis_exec_sql("pragma journal_mode=wal;"); + arch_push_data_header(); arch_push_data_line(); {% endif %} |
