Skip to content

Commit

Permalink
Issue #267 - Add a "progress bar" to specs using --progress switch (#268
Browse files Browse the repository at this point in the history
)

* Issue #267 - Add a "progress bar"  to specs using --progress switch

* Issue #267 - Make the output more readable using the pretty() function
  • Loading branch information
yoavnir authored Nov 15, 2024
1 parent b3ab532 commit 08265e6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ What's New:
* The unthreaded mode is now the default.
* While-guard to protect against endless loops in `while` statements.
* Improved @version.
* Tab-completion for `specs` command (Linux only).
* Tab-completion for the `specs` command (Linux only).
* A new `--progress` command-line switch to allow the user to monitor progress in reading records.
* Bug fixes

10-May-2024: Version 0.9.2 is here
Expand Down
4 changes: 4 additions & 0 deletions manpage
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,10 @@ Prints out detailed step-by-step information about the evaluation of expressions
Disables
.I while-guard,
allowing specifications to enter endless loops.
.IP "--progress" 3
While
.B specs
is running, will print once a second a message to stderr telling the user how many records have already been processed.
.IP "--config or -c" 3
Changes the configuration file from the default
.I ~/.specs
Expand Down
1 change: 1 addition & 0 deletions specs/docs/cliswitch.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Main Thread:
* `--debug-alu-comp` -- Prints out detailed information about the parsing and compiling of expressions (_only in debug build_).
* `--debug-alu-run` -- Prints out detailed step-by-step information about the evaluation of expressions (_only in debug build_).
* `--no-while-guard` -- Disables **while-guard**, allowing specifications to enter endless loops.
* `--progress` -- While **specs**is running, will print once a second a message to stderr telling the user how many records have already been processed.
* `--timezone` **name** -- convert to and from time-formatted strings using the selected timezone. Valid values are from the TZ database and look like `Africa/Dakar`, `America/Chicago`, `Asia/Calcutta`, `Australia/Sydney`, or `Europe/Berlin`. A full list of such timezones is available on [Wikipedia](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). Note that the same timezones can also be configured in the config
* `--config` **filename** or `-c` **filename** -- overrides the default configuration file which is `~/.specs` on POSIX-based operating systems (Mac OS and Linux) or `%HOME%\specs.cfg` on Windows.
* `--set` **name=value** or `-s` **name=value** -- sets the named string *name* to the value *value*.
Expand Down
2 changes: 2 additions & 0 deletions specs/docs/onepage.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Switches
* --inCmd or -C -- get the input records from the output of a command specified following this switch.
* --debug-alu-comp -- Prints out detailed information about the parsing and compiling of expressions (_only in debug build_).
* --debug-alu-run -- Prints out detailed step-by-step information about the evaluation of expressions (_only in debug build_).
* --no-while-guard -- Disables **while-guard**, allowing specifications to enter endless loops.
* --progress -- While **specs**is running, will print once a second a message to stderr telling the user how many records have already been processed.
* --help -- prints out some help information.
* --info -- prints out information about this build of **specs**.

Expand Down
1 change: 1 addition & 0 deletions specs/src/processing/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
X(bDebugAluCompile, bool, false, 0,debug-alu-comp, true) \
X(bDebugAluRun, bool, false, 0,debug-alu-run, true) \
X(bNoWhileGuard, bool, false, 0,no-while-guard, true) \
X(bShowProgress, bool, false, 0,progress, true) \
X(configurationFile, std::string, "", c,config, NEXTARG) \
X(timeZone, std::string, "", 0,timezone, NEXTARG) \
X(recfm, std::string, "", 0,recfm, NEXTARG) \
Expand Down
8 changes: 8 additions & 0 deletions specs/src/specitems/specItems.cc
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ bool itemGroup::processDo(StringBuilder& sb, ProcessingState& pState, Reader* pR

void itemGroup::process(StringBuilder& sb, ProcessingState& pState, Reader& rd, classifyingTimer& tmr)
{
static time_t progressTick = 0;
PSpecString ps;
unsigned int readerCounter = 1; // we only got 1.

Expand All @@ -588,6 +589,13 @@ void itemGroup::process(StringBuilder& sb, ProcessingState& pState, Reader& rd,
pState.setFirst();
pState.incrementCycleCounter();

if (g_bShowProgress && (time(nullptr)!=progressTick)) {
progressTick = time(nullptr);
auto pv = mkValue(pState.getRecordCount());
auto pvstr = AluFunc_pretty(pv, nullptr, nullptr, nullptr);
std::cerr << "\n\tspecs: Read " << pvstr->getStr() << " records.\n";
}

if (processDo(sb,pState, &rd, tmr, readerCounter)) {
bool bPrintSuppressed = pState.printSuppressed(g_printonly_rule);
if (bPrintSuppressed && g_keep_suppressed_record) {
Expand Down

0 comments on commit 08265e6

Please sign in to comment.