Various Handy Tools for Experimentation

versuchung.execute.shell(*args, **kwargs)
Executes args[0] % args[:1] in a shell.
Keyword Arguments are passed through to the corresponding Popen() call.
By default the following kwargs are passed:
Keyword Value
shell True
stdout subprocess.PIPE
stderr subprocess.STDOUT
universal_newlines True

Note

The following command enables capturing stderr, stdout and runtime information (with /usr/bin/time):

shell.track(experiment.path)

Note

Tracking is enabled automatically after setup. It can be disabled and re-enabled while running the experiment with:

>> shell.track.disable()
>> shell.track.enable()

The tracking feature creates files like shell_0_time, shell_0_stderr, and so on. These files are created in the experiment.path directory.

Note

To write the results of the tracking feature into the experiment output folder, use self.path within a run() method of an experiment:

shell.track(experiment.path)
Return type:a tuple with:
  1. the command’s standard output as list of lines
  2. the exitcode
Raises:CommandFailed if the returncode is != 0
versuchung.execute.shell_failok(*args, **kwargs)

Like shell(), but the throws no exception

exception versuchung.execute.CommandFailed(command, returncode, stdout='')[source]

Indicates that some command failed

Attributes:

command: the command that failed

returncode: the exitcode of the failed command

class versuchung.execute.MachineMonitor(default_filename='', tick_interval=100, capture=['cpu', 'mem', 'net', 'disk'])[source]

Can be used as: input parameter and output parameter

With this parameter the systems status during the experiment can be monitored. The tick interval can specified on creation and also what values should be captured.

This parameter creates a CSV_File with the given name. When the experiment starts the monitor fires up a thread which will every tick_interval milliseconds capture the status of the system and store the information as a row in the normal csv.

A short example:

class SimpleExperiment(Experiment):
    outputs = {"ps": MachineMonitor("ps_monitor", tick_interval=100)}

    def run(self):
        shell("sleep 1")
        shell("seq 1 100000 | while read a; do echo > /dev/null; done")
        shell("sleep 1")

experiment = SimpleExperiment()
experiment(sys.argv)
>>> experiment.o.ps.extract(["time", "net_send"])
[[1326548338.701827, 0],
 [1326548338.810422, 3],
 [1326548338.913667, 0],
 [1326548339.016836, 0],
 [1326548339.119982, 2],
 ....
extract(keys=['time', 'cpu_percentage'])[source]

Extract single columns from the captured information. Useful keys are defined in sample_keys

sample_keys = ['time', 'cpu_percentage', 'phymem_total', 'phymem_used', 'phymem_free', 'virtmem_total', 'virtmem_used', 'virtmem_free', 'cached', 'buffers', 'net_send', 'net_recv', 'disk_read', 'disk_write']

The various fields in the csv file are organized like the strings in this list. E.g. The unix time is the first field of the csv file.

class versuchung.events.EventLog(default_filename='', **csv_args)[source]

Log events with timestamp

event(event, key, value='')[source]

Log a event to the event log. There the event and the description together with the time of the event is stored

Returns:float – UNIX Time of the Event
shell(command, *args)[source]

Like shell(), but logs the start and stop of the process in the ".events"-file.