logstack module

class src.core.logstack.LogStack(trace)

Bases: object

A per-variable index into the execution trace.

rev x and revtrace x n reach a single variable’s history, so they need to find that variable’s changes without scanning everything that has happened. This class keeps, for each variable, the positions of the trace events that changed it. The values themselves live in the trace, which stays the single source of truth: keeping them in both places would double the memory a reversible program spends on its own history.

Positions already undone are skipped rather than removed, so that a variable reversed as part of a whole block is not reversed a second time by a later rev naming it directly.

trace

The trace the recorded positions point into.

Type:

ExecutionTrace

log

A dictionary of variable names to lists of trace positions.

Type:

dict

get_memory_usage()

Calculates the memory usage of the index and the trace it points into.

Returns:

The total memory usage in megabytes (MB).

Return type:

float

peek(var_name, index=1)

Returns a previous change to a variable without reversing it.

The index parameter specifies how far back to look (1 for the most recent, 2 for the one before it, and so on). Changes already undone are skipped, so the numbering always describes the states still reachable.

Parameters:
  • var_name (str) – The name of the variable to peek at.

  • index (int) – How many steps back to look.

Returns:

The trace position of that change, or None if out of range.

Return type:

int

pop(var_name)

Removes and returns the most recent outstanding change to a variable.

Positions whose events have already been undone are discarded on the way past, so a variable reversed as part of a block is not reversed twice.

Parameters:

var_name (str) – The name of the variable to reverse.

Returns:

The trace position of the change, or None if there is none.

Return type:

int

positions(var_name)

Lists the outstanding changes to a variable, most recent first.

Parameters:

var_name (str) – The variable to list changes for.

Returns:

Trace positions of the changes not yet undone.

Return type:

list

prune(retention_time=50000)

Prunes the underlying trace of values that have already been reversed.

Parameters:

retention_time (int, optional) – The age in seconds past which a reversed event’s payload is released. Defaults to 50,000.

push(var_name, position)

Records that a trace event at the given position changed a variable.

Parameters:
  • var_name (str) – The name of the variable that changed.

  • position (int) – The position of the event in the trace.