Revert changes to time formatting

This reverts commits:

2d9e51b43e8f0dd73a87e12f1abc74f99f8ff5f3
d1d9f147ec4cc82e0319da0ede642976e117034c
346ce8081ba8ac4460d4da27abd9fe6701ab7dcb

The box drawing because it's entangled with the rest and we don't
currently use this anywhere I know of. Nor was it gated on terminfo,
so it could have broken things, for subjectively little gain.

Fixes #8727.
This commit is contained in:
Fabian Homborg 2022-02-21 22:43:36 +01:00
parent e0bc944d5c
commit 6fcb6f77be
3 changed files with 43 additions and 55 deletions

View File

@ -6619,17 +6619,18 @@ static void test_timer_format() {
t2.cpu_children.ru_stime.tv_usec = 500;
t2.wall += std::chrono::microseconds(500);
auto expected =
L"\x1b(0qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\x1b(B\n"
"Executed in 500.00 μs fish external\n"
" usr time 1.00 sec 1.00 sec 1.00 ms\n"
" sys time 1.00 sec 1.00 sec 0.50 ms";
// (a) (b) (c)
LR"(
________________________________________________________
Executed in 500.00 micros fish external
usr time 1.00 secs 1.00 secs 1.00 millis
sys time 1.00 secs 1.00 secs 0.50 millis
)"; // (a) (b) (c)
// (a) remaining columns should align even if there are different units
// (b) carry to the next unit when it would overflow %6.2F
// (c) carry to the next unit when the larger one exceeds 1000
std::wstring actual = timer_snapshot_t::print_delta(t1, t2, true);
if (actual != expected) {
err(L"Failed to format timer snapshot\nExpected:\n %ls\nActual:\n %ls\n", expected,
err(L"Failed to format timer snapshot\nExpected: %ls\nActual:%ls\n", expected,
actual.c_str());
}
setlocale(LC_NUMERIC, saved_locale);

View File

@ -11,19 +11,6 @@
#include <cstddef>
#include <ctime>
#if HAVE_CURSES_H
#include <curses.h>
#elif HAVE_NCURSES_H
#include <ncurses.h>
#elif HAVE_NCURSES_CURSES_H
#include <ncurses/curses.h>
#endif
#if HAVE_TERM_H
#include <term.h>
#elif HAVE_NCURSES_TERM_H
#include <ncurses/term.h>
#endif
#include "builtin.h"
#include "common.h"
#include "exec.h"
@ -126,31 +113,31 @@ wcstring timer_snapshot_t::print_delta(const timer_snapshot_t &t1, const timer_s
auto unit_name = [](tunit unit) {
switch (unit) {
case tunit::minutes:
return L"minutes";
return "minutes";
case tunit::seconds:
return L"seconds";
return "seconds";
case tunit::milliseconds:
return L"milliseconds";
return "milliseconds";
case tunit::microseconds:
return L"microseconds";
return "microseconds";
}
// GCC does not recognize the exhaustive switch above
return L"";
return "";
};
auto unit_short_name = [](tunit unit) {
switch (unit) {
case tunit::minutes:
return L"min";
return "mins";
case tunit::seconds:
return L"sec";
return "secs";
case tunit::milliseconds:
return L"ms";
return "millis";
case tunit::microseconds:
return L"μs";
return "micros";
}
// GCC does not recognize the exhaustive switch above
return L"";
return "";
};
auto convert = [](int64_t micros, tunit unit) {
@ -176,9 +163,10 @@ wcstring timer_snapshot_t::print_delta(const timer_snapshot_t &t1, const timer_s
wcstring output;
if (!verbose) {
append_format(output, L"\nExecuted in %6.2F %ls"
L"\n usr time %6.2F %ls"
L"\n sys time %6.2F %ls"
append_format(output, L"\n_______________________________"
L"\nExecuted in %6.2F %s"
L"\n usr time %6.2F %s"
L"\n sys time %6.2F %s"
L"\n",
wall_time, unit_name(wall_unit),
usr_time, unit_name(cpu_unit),
@ -191,17 +179,16 @@ wcstring timer_snapshot_t::print_delta(const timer_snapshot_t &t1, const timer_s
double child_usr_time = convert(child_usr_micros, child_unit);
double child_sys_time = convert(child_sys_micros, child_unit);
int column2_unit_len = std::max(wcslen(unit_short_name(wall_unit)),
wcslen(unit_short_name(cpu_unit)));
// TODO: improve layout
int column2_unit_len = std::max(strlen(unit_short_name(wall_unit)),
strlen(unit_short_name(cpu_unit)));
append_format(output,
L"%s%s%s"
L"\nExecuted in %6.2F %-*ls %-*s %s"
L"\n usr time %6.2F %-*ls %6.2F %ls %6.2F %ls"
L"\n sys time %6.2F %-*ls %6.2F %ls %6.2F %ls",
enter_alt_charset_mode, std::string(45, 'q').c_str(), exit_alt_charset_mode,
L"\n________________________________________________________"
L"\nExecuted in %6.2F %-*s %-*s %s"
L"\n usr time %6.2F %-*s %6.2F %s %6.2F %s"
L"\n sys time %6.2F %-*s %6.2F %s %6.2F %s"
L"\n",
wall_time, column2_unit_len, unit_short_name(wall_unit),
static_cast<int>(wcslen(unit_short_name(fish_unit))) + 7, "fish", "external",
static_cast<int>(strlen(unit_short_name(fish_unit))) + 7, "fish", "external",
usr_time, column2_unit_len, unit_short_name(cpu_unit), fish_usr_time,
unit_short_name(fish_unit), child_usr_time, unit_short_name(child_unit),
sys_time, column2_unit_len, unit_short_name(cpu_unit), fish_sys_time,

View File

@ -3,37 +3,37 @@ time sleep 0
# These are a tad awkward because it picks the correct unit and adapts whitespace.
# The idea is that it's a table.
#CHECKERR: {{.*}}
#CHECKERR: Executed in {{[\d,.\s]*}} {{ms|μs|sec}} {{\s*}}fish {{\s*}}external
#CHECKERR: usr time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}}
#CHECKERR: sys time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}}
#CHECKERR: ________________________________________________________
#CHECKERR: Executed in {{[\d,.\s]*}} {{millis|micros|secs}} {{\s*}}fish {{\s*}}external
#CHECKERR: usr time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}}
#CHECKERR: sys time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}}
time for i in (seq 1 2)
echo banana
end
#CHECK: banana
#CHECK: banana
#CHECKERR: {{.*}}
#CHECKERR: Executed in {{[\d,.\s]*}} {{ms|μs|sec}} {{\s*}}fish {{\s*}}external
#CHECKERR: usr time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}}
#CHECKERR: sys time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}}
#CHECKERR: ________________________________________________________
#CHECKERR: Executed in {{[\d,.\s]*}} {{millis|micros|secs}} {{\s*}}fish {{\s*}}external
#CHECKERR: usr time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}}
#CHECKERR: sys time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}}
# Make sure we're not double-parsing
time echo 'foo -s bar'
#CHECK: foo -s bar
#CHECKERR: {{.*}}
#CHECKERR: Executed in {{[\d,.\s]*}} {{ms|μs|sec}} {{\s*}}fish {{\s*}}external
#CHECKERR: usr time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}}
#CHECKERR: sys time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}}
#CHECKERR: ________________________________________________________
#CHECKERR: Executed in {{[\d,.\s]*}} {{millis|micros|secs}} {{\s*}}fish {{\s*}}external
#CHECKERR: usr time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}}
#CHECKERR: sys time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}}
true && time a=b not builtin true | true
#CHECKERR: {{.*}}
#CHECKERR: ___{{.*}}
#CHECKERR: {{.*}}
#CHECKERR: {{.*}}
#CHECKERR: {{.*}}
not time true
#CHECKERR: {{.*}}
#CHECKERR: ___{{.*}}
#CHECKERR: {{.*}}
#CHECKERR: {{.*}}
#CHECKERR: {{.*}}