From b648b62bfeb4707666afb5ebdba2bf3c2e3b47a2 Mon Sep 17 00:00:00 2001 From: xiaosuGW Date: Wed, 4 Aug 2021 16:36:42 -0400 Subject: [PATCH] replace "assert" with "return" if FILE pointer is NULL in memlogging.c --- runtime/include/sandbox_functions.h | 3 +++ runtime/src/memlogging.c | 19 ++++++++----------- runtime/tests/debug.sh | 4 +++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/runtime/include/sandbox_functions.h b/runtime/include/sandbox_functions.h index ff53eb7..23a5ec3 100644 --- a/runtime/include/sandbox_functions.h +++ b/runtime/include/sandbox_functions.h @@ -203,6 +203,9 @@ sandbox_mem_print_perf(struct sandbox *sandbox) #ifndef LOG_RUNTIME_MEM_LOG return; #endif + /* If the log was not defined by an environment variable, early out */ + if (runtime_sandbox_perf_log == NULL) return; + uint32_t total_time_us = sandbox->total_time / runtime_processor_speed_MHz; uint32_t queued_us = (sandbox->allocation_timestamp - sandbox->enqueue_timestamp) / runtime_processor_speed_MHz; diff --git a/runtime/src/memlogging.c b/runtime/src/memlogging.c index e27f7f2..2c3e7b7 100644 --- a/runtime/src/memlogging.c +++ b/runtime/src/memlogging.c @@ -26,10 +26,6 @@ mem_log_init2(uint32_t log_size, FILE* file) log_obj.offset = 0; log_obj.fout = file; - if (!log_obj.fout) { - panic("failed to open log file:%s\n", strerror(errno)); - } - } /** @@ -51,11 +47,7 @@ mem_log_init(uint32_t log_size, char const* file) } log_obj.offset = 0; - log_obj.fout = fopen(file, "a+"); - if (!log_obj.fout) { - panic("failed to open log file:%s\n", strerror(errno)); - } - + log_obj.fout = fopen(file, "w"); } /** @@ -68,7 +60,9 @@ mem_log(char const * fmt, ...) return; #endif assert(log_obj.logger); - assert(log_obj.fout); + if (!log_obj.fout) { + return; + } va_list va; va_start(va, fmt); @@ -112,8 +106,11 @@ dump_log_to_file() #ifndef LOG_RUNTIME_MEM_LOG return; #endif + if (!log_obj.fout) { + return; + } + assert(log_obj.logger); - assert(log_obj.fout); uint32_t write_bytes = 0; while(write_bytes != log_obj.offset) { diff --git a/runtime/tests/debug.sh b/runtime/tests/debug.sh index b4db9f9..e01350c 100755 --- a/runtime/tests/debug.sh +++ b/runtime/tests/debug.sh @@ -8,11 +8,13 @@ declare project_path="$( cd "$(dirname "$1")/../.." pwd )" +path=`pwd` echo $project_path cd $project_path/runtime/bin +export SLEDGE_DISABLE_PREEMPTION=true export LD_LIBRARY_PATH="$(pwd):$LD_LIBRARY_PATH" gdb --eval-command="handle SIGUSR1 nostop" \ --eval-command="set pagination off" \ --eval-command="set substitute-path /sledge/runtime $project_path/runtime" \ - --eval-command="run ../tests/my_fibonacci.json" \ +# --eval-command="run ../tests/test_armcifar10.json" \ ./sledgert