pygsti.baseobjs.profiler.Profiler#
- class Profiler(comm=None, default_print_memcheck=False)#
Bases:
objectProfiler objects are used for tracking both time and memory usage.
- Parameters:
comm (mpi4py.MPI.Comm optional) – The active MPI communicator.
default_print_memcheck (bool, optional) – Whether to print memory checks.
Construct a new Profiler instance.
- Parameters:
comm (mpi4py.MPI.Comm, optional) – MPI communicator so only profile and print messages on root proc.
Methods
__init__([comm, default_print_memcheck])Construct a new Profiler instance.
add_count(name[, inc, prefix])Adds a given value to a named "counter"-type accumulator.
add_time(name, start_time[, prefix])Adds an elapsed time to a named "timer"-type accumulator.
memory_check(name[, printme, prefix])Record the memory usage at this point and tag with a name.
print_memory(name[, show_minmax])Prints the current memory usage (but doesn't store it).
print_message(msg[, all_ranks])Prints a message to stdout, possibly from all ranks.
- add_count(name, inc=1, prefix=0)#
Adds a given value to a named “counter”-type accumulator.
- Parameters:
name (string) – The name of the counter to add val into (if the name doesn’t exist, one is created and initialized to val).
inc (int, optional) – The increment (the value to add to the counter).
prefix (int, optional) – Prefix to the timer name the current stack depth and this number of function names, starting with the current function and moving the call stack. When zero, no prefix is added. For example, with prefix == 1, “Total” might map to “ 3: myFunc: Total”.
- Return type:
None
- add_time(name, start_time, prefix=0)#
Adds an elapsed time to a named “timer”-type accumulator.
- Parameters:
name (string) – The name of the timer to add elapsed time into (if the name doesn’t exist, one is created and initialized to the elapsed time).
start_time (float) – The starting time used to compute the elapsed, i.e. the value time.time()-start_time, which is added to the named timer.
prefix (int, optional) – Prefix to the timer name the current stack depth and this number of function names, starting with the current function and moving the call stack. When zero, no prefix is added. For example, with prefix == 1, “Total” might map to “ 3: myFunc: Total”.
- Return type:
None
- memory_check(name, printme=None, prefix=0)#
Record the memory usage at this point and tag with a name.
- Parameters:
name (string) – The name of the memory checkpoint. (Later, memory information can be organized by checkpoint name.)
printme (bool, optional) – Whether or not to print the memory usage during this function call (if None, the default, then the value of default_print_memcheck specified during Profiler construction is used).
prefix (int, optional) – Prefix to the timer name the current stack depth and this number of function names, starting with the current function and moving the call stack. When zero, no prefix is added. For example, with prefix == 1, “Total” might map to “ 3: myFunc: Total”.
- Return type:
None
- print_memory(name, show_minmax=False)#
Prints the current memory usage (but doesn’t store it).
Useful for debugging, this function prints the current memory usage - optionally giving the minimum, maximum, and average across all the processors.
- Parameters:
name (string) – A label to print before the memory usage number(s).
show_minmax (bool, optional) – If True and there are multiple processors, print the min, average, and max memory usage from among the processors. Note that this will invoke MPI collective communication and so this print_memory call must be executed by all the processors. If False and there are multiple processors, only the rank 0 processor prints output.
- Return type:
None
- print_message(msg, all_ranks=False)#
Prints a message to stdout, possibly from all ranks.
A utility function used in debugging, this function offers a convenient way to print a message on only the root processor or on all processors.
- Parameters:
msg (string) – The message to print.
all_ranks (bool, optional) – If True, all processors will print msg, preceded by their rank label (e.g. “Rank4: “). If False, only the rank 0 processor will print the message.
- Return type:
None