binutils-gdb/gdb/testsuite/print-ts.py

49 lines
1.5 KiB
Python
Raw Normal View History

Implement timestamp'ed output on "make check" It is unfortunately not uncommon to have tests hanging on some of the BuildBot workers. For example, the ppc64be/ppc64le+gdbserver builders are especially in a bad state when it comes to testing GDB/gdbserver, and we can have builds that take an absurd amount of time to finish (almost 1 week for one single build, for example). It may be hard to diagnose these failures, because sometimes we don't have access to the faulty systems, and other times we're just too busy to wait and check which test is actually hanging. During one of our conversations about the topic, someone proposed that it would be a good idea to have a timestamp put together with stdout output, so that we can come back later and examine which tests are taking too long to complete. Here's my proposal to do this. The very first thing I tried to do was to use "ts(1)" to achieve this feature, and it obviously worked, but the problem is that I'm afraid "ts(1)" may not be widely available on every system we support. Therefore, I decided to implement a *very* simple version of "ts(1)", in Python 3, which basically does the same thing: iterate over the stdin lines, and prepend a timestamp onto them. As for testsuite/Makefile.in, the user can now specify two new variables to enable timestamp'ed output: TS (which enables the output), and TS_FORMAT (optional, used to specify another timestamp format according to "strftime"). Here's an example of how the output looks like: ... [Nov 22 17:07:19] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/call-strs.exp ... [Nov 22 17:07:19] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/step-over-no-symbols.exp ... [Nov 22 17:07:20] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/all-architectures-6.exp ... [Nov 22 17:07:20] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/hashline3.exp ... [Nov 22 17:07:20] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/max-value-size.exp ... [Nov 22 17:07:20] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/quit-live.exp ... [Nov 22 17:07:46] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/paginate-bg-execution.exp ... [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/gcore-buffer-overflow.exp ... [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/gcore-relro.exp ... [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/watchpoint-delete.exp ... [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/breakpoint-in-ro-region.exp ... [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/vla-sideeffect.exp ... [Nov 22 17:07:57] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/unload.exp ... ... (What, gdb.base/quit-live.exp is taking 26 seconds to complete?!) Output to stderr is not timestamp'ed, but I don't think that will be a problem for us. If it is, we can revisit the solution and extend it. gdb/testsuite/ChangeLog: 2018-11-25 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (TIMESTAMP): New variable. (check-single): Add $(TIMESTAMP) to the end of $(DO_RUNTEST) command. (check-single-racy): Likewise. (check/%.exp): Likewise. (check-racy/%.exp): Likewise. (workers/%.worker): Likewise. (build-perf): Likewise. (check-perf): Likewise. * README: Describe new "TS" and "TS_FORMAT" variables. * print-ts.py: New file.
2018-11-22 22:45:33 +01:00
#!/usr/bin/env python
# Copyright (C) 2018-2020 Free Software Foundation, Inc.
Implement timestamp'ed output on "make check" It is unfortunately not uncommon to have tests hanging on some of the BuildBot workers. For example, the ppc64be/ppc64le+gdbserver builders are especially in a bad state when it comes to testing GDB/gdbserver, and we can have builds that take an absurd amount of time to finish (almost 1 week for one single build, for example). It may be hard to diagnose these failures, because sometimes we don't have access to the faulty systems, and other times we're just too busy to wait and check which test is actually hanging. During one of our conversations about the topic, someone proposed that it would be a good idea to have a timestamp put together with stdout output, so that we can come back later and examine which tests are taking too long to complete. Here's my proposal to do this. The very first thing I tried to do was to use "ts(1)" to achieve this feature, and it obviously worked, but the problem is that I'm afraid "ts(1)" may not be widely available on every system we support. Therefore, I decided to implement a *very* simple version of "ts(1)", in Python 3, which basically does the same thing: iterate over the stdin lines, and prepend a timestamp onto them. As for testsuite/Makefile.in, the user can now specify two new variables to enable timestamp'ed output: TS (which enables the output), and TS_FORMAT (optional, used to specify another timestamp format according to "strftime"). Here's an example of how the output looks like: ... [Nov 22 17:07:19] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/call-strs.exp ... [Nov 22 17:07:19] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/step-over-no-symbols.exp ... [Nov 22 17:07:20] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/all-architectures-6.exp ... [Nov 22 17:07:20] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/hashline3.exp ... [Nov 22 17:07:20] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/max-value-size.exp ... [Nov 22 17:07:20] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/quit-live.exp ... [Nov 22 17:07:46] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/paginate-bg-execution.exp ... [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/gcore-buffer-overflow.exp ... [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/gcore-relro.exp ... [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/watchpoint-delete.exp ... [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/breakpoint-in-ro-region.exp ... [Nov 22 17:07:56] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/vla-sideeffect.exp ... [Nov 22 17:07:57] [1234] Running binutils-gdb/gdb/testsuite/gdb.base/unload.exp ... ... (What, gdb.base/quit-live.exp is taking 26 seconds to complete?!) Output to stderr is not timestamp'ed, but I don't think that will be a problem for us. If it is, we can revisit the solution and extend it. gdb/testsuite/ChangeLog: 2018-11-25 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (TIMESTAMP): New variable. (check-single): Add $(TIMESTAMP) to the end of $(DO_RUNTEST) command. (check-single-racy): Likewise. (check/%.exp): Likewise. (check-racy/%.exp): Likewise. (workers/%.worker): Likewise. (build-perf): Likewise. (check-perf): Likewise. * README: Describe new "TS" and "TS_FORMAT" variables. * print-ts.py: New file.
2018-11-22 22:45:33 +01:00
#
# This file is part of GDB.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This is a simple program that can be used to print timestamps on
# standard output. The inspiration for it was ts(1)
# (<https://joeyh.name/code/moreutils/>). We have our own version
# because unfortunately ts(1) is or may not be available on all
# systems that GDB supports.
#
# The usage is simple:
#
# #> some_command | print-ts.py [FORMAT]
#
# FORMAT must be a string compatible with "strftime". If nothing is
# provided, we choose a reasonable format.
import fileinput
import datetime
import sys
import os
if len(sys.argv) > 1:
fmt = sys.argv[1]
else:
fmt = '[%b %d %H:%M:%S]'
mypid = os.getpid()
for line in fileinput.input('-'):
sys.stdout.write("{} [{}] {}".format(datetime.datetime.now().strftime(fmt),
mypid, line))
sys.stdout.flush()