Nathanael Premillieu has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/49672 )
Change subject: misc: limit debug output file size
......................................................................
misc: limit debug output file size
Add an option (--debug-size-limit) to limit the debug output file size.
Change-Id: I6a1b02bf492351338bb9a8498a895246a060ef2c
---
M src/base/trace.cc
M src/base/trace.hh
M src/base/trace.test.cc
M src/python/m5/main.py
M src/python/pybind11/debug.cc
M util/systemc/gem5_within_systemc/main.cc
M util/systemc/gem5_within_systemc/sc_gem5_control.cc
M util/tlm/src/sim_control.cc
8 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/src/base/trace.cc b/src/base/trace.cc
index 1d2ab7d..bb34008 100644
--- a/src/base/trace.cc
+++ b/src/base/trace.cc
@@ -96,12 +96,14 @@
}
void
-setDebugLogger(Logger *logger)
+setDebugLogger(Logger *logger, uint64_t size_limit)
{
if (!logger)
warn("Trying to set debug logger to NULL\n");
else
debug_logger = logger;
+
+ file_size_limit = size_limit;
}
void
@@ -182,6 +184,12 @@
print_backtrace();
STATIC_ERR("\n");
}
+
+ if (file_size_limit && (uint64_t)stream.tellp() > file_size_limit) {
+ inform("Debug output has reached the file size limit (%ldB), "
+ "stopping the tracing.\n", file_size_limit);
+ disable();
+ }
}
} // namespace Trace
diff --git a/src/base/trace.hh b/src/base/trace.hh
index e923d7a..fbd1b75 100644
--- a/src/base/trace.hh
+++ b/src/base/trace.hh
@@ -132,7 +132,7 @@
std::ostream &output();
/** Delete the current global logger and assign a new one */
-void setDebugLogger(Logger *logger);
+void setDebugLogger(Logger *logger, uint64_t size_limit);
/** Enable/disable debug logging */
void enable();
diff --git a/src/base/trace.test.cc b/src/base/trace.test.cc
index 526e8dd..353580e 100644
--- a/src/base/trace.test.cc
+++ b/src/base/trace.test.cc
@@ -318,7 +318,7 @@
// NOTE: From now on getDebugLogger will use main_logger to avoid
// having to check cerr. This assumes that tests are run in the order
// they appear from line 1 to the last line of this file.
- Trace::setDebugLogger(&main_logger);
+ Trace::setDebugLogger(&main_logger, 0);
// Set message with local variable, and retrieve the string with
// the debug-logger getter
diff --git a/src/python/m5/main.py b/src/python/m5/main.py
index 57e53b2..953a3a1 100644
--- a/src/python/m5/main.py
+++ b/src/python/m5/main.py
@@ -147,6 +147,8 @@
option("--debug-file", metavar="FILE", default="cout",
help="Sets the output file for debug. Append '.gz' to the name for
it"
" to be compressed automatically [Default: %default]")
+ option("--debug-size-limit", metavar="EXPR", default = 'Unlimited',
+ help="Sets the limit for the output file size for debug")
option("--debug-ignore", metavar="EXPR", action='append', split=':',
help="Ignore EXPR sim objects")
option("--remote-gdb-port", type='int', default=7000,
@@ -225,7 +227,7 @@
from . import stats
from . import trace
- from .util import inform, fatal, panic, isInteractive
+ from .util import convert, inform, fatal, panic, isInteractive
from m5.util.terminal_formatter import TerminalFormatter
if len(args) == 0:
@@ -424,6 +426,19 @@
if options.debug_with_stats:
trace.setWithStats(True)
+ # 0 for the debug file size limit is the same as unlimited
+ debug_file_size_limit = (0 if (options.debug_size_limit == "Unlimited")
+ else convert.toMemorySize(
+ options.debug_size_limit))
+ # Only print the debug file size message if debug mode is activated
+ if options.debug_flags:
+ if (debug_file_size_limit != 0):
+ print(f"Debug file size is limited to:
{options.debug_size_limit}"
+ f" ({debug_file_size_limit} Bytes)\n")
+ else:
+ print(f"Debug file size is unlimited!\n")
+ trace.output(options.debug_file, debug_file_size_limit)
+
for ignore in options.debug_ignore:
_check_tracing()
trace.ignore(ignore)
diff --git a/src/python/pybind11/debug.cc b/src/python/pybind11/debug.cc
index 65e1e56..5110cbf 100644
--- a/src/python/pybind11/debug.cc
+++ b/src/python/pybind11/debug.cc
@@ -63,14 +63,15 @@
} // namespace debug
static void
-output(const char *filename)
+output(const char *filename, uint64_t size_limit)
{
OutputStream *file_stream = simout.find(filename);
if (!file_stream)
file_stream = simout.create(filename);
- Trace::setDebugLogger(new
Trace::OstreamLogger(*file_stream->stream()));
+ Trace::setDebugLogger(new Trace::OstreamLogger(*file_stream->stream()),
+ size_limit);
}
static void
diff --git a/util/systemc/gem5_within_systemc/main.cc
b/util/systemc/gem5_within_systemc/main.cc
index e9e2dd5..19c2769 100644
--- a/util/systemc/gem5_within_systemc/main.cc
+++ b/util/systemc/gem5_within_systemc/main.cc
@@ -159,7 +159,7 @@
cxxConfigInit();
/* Pass DPRINTF messages to SystemC */
- Trace::setDebugLogger(&logger);
+ Trace::setDebugLogger(&logger, 0);
/* @todo need this as an option */
Gem5SystemC::setTickFrequency();
diff --git a/util/systemc/gem5_within_systemc/sc_gem5_control.cc
b/util/systemc/gem5_within_systemc/sc_gem5_control.cc
index 18aec6a..24e71b1 100644
--- a/util/systemc/gem5_within_systemc/sc_gem5_control.cc
+++ b/util/systemc/gem5_within_systemc/sc_gem5_control.cc
@@ -217,7 +217,7 @@
gem5::cxxConfigInit();
/* Pass DPRINTF messages to SystemC */
- gem5::Trace::setDebugLogger(&logger);
+ gem5::Trace::setDebugLogger(&logger, 0);
/* @todo need this as an option */
Gem5SystemC::setTickFrequency();
diff --git a/util/tlm/src/sim_control.cc b/util/tlm/src/sim_control.cc
index c706fd9..4d89cd4 100644
--- a/util/tlm/src/sim_control.cc
+++ b/util/tlm/src/sim_control.cc
@@ -80,7 +80,7 @@
gem5::ExternalMaster::registerHandler("tlm_master",
new SCMasterPortHandler(*this));
- gem5::Trace::setDebugLogger(&logger);
+ gem5::Trace::setDebugLogger(&logger, 0);
Gem5SystemC::setTickFrequency();
assert(sc_core::sc_get_time_resolution()
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/49672
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I6a1b02bf492351338bb9a8498a895246a060ef2c
Gerrit-Change-Number: 49672
Gerrit-PatchSet: 1
Gerrit-Owner: Nathanael Premillieu <nathanael.premill...@huawei.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s