Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/43266 )
Change subject: util: Add a logroll utility.
......................................................................
util: Add a logroll utility.
This utility receives input from stdin or a file, buffers up to "n"
lines of it, and prints those lines either when it reaches the end of
the file/stdin, or when it receives a SIGUSR1 which can be sent to it
using the "kill" utility. When it receives a SIGUSR1, it keeps running
and tracking the input.
Change-Id: I9eca4514378cf24a31002d37e10e58cc3ee63b5d
---
A util/logroll.py
1 file changed, 65 insertions(+), 0 deletions(-)
diff --git a/util/logroll.py b/util/logroll.py
new file mode 100755
index 0000000..425de82
--- /dev/null
+++ b/util/logroll.py
@@ -0,0 +1,65 @@
+#! /usr/bin/env python3
+#
+# Copyright 2021 Google Inc.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import argparse
+import signal
+import sys
+
+parser = argparse.ArgumentParser(description='Circular buffer for text
output')
+parser.add_argument('-n', '--lines', default=10, type=int,
+ help='Maximum number of lines to buffer at a time.')
+parser.add_argument('file', nargs='?', default=sys.stdin,
+ type=argparse.FileType('r', encoding='UTF-8'),
+ help='File to read from, default is stdin')
+
+args = parser.parse_args()
+
+target = args.lines
+incoming = args.file
+
+idx = 0
+line_buffer = []
+
+def dump_lines():
+ for line in line_buffer[idx:]:
+ print(line, end='')
+ for line in line_buffer[:idx]:
+ print(line, end='')
+
+for line in incoming:
+ line_buffer.append(line)
+ idx += 1
+ if idx == target:
+ idx = 0
+ break
+
+signal.signal(signal.SIGUSR1, lambda num, frame: dump_lines())
+
+for line_buffer[idx] in incoming:
+ idx = (idx + 1) % target
+
+dump_lines()
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/43266
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: I9eca4514378cf24a31002d37e10e58cc3ee63b5d
Gerrit-Change-Number: 43266
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s