Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
Python profiling libraries measure where a program spends its time or memory, down to the function or line. A sampling profiler records the call stack at intervals rather than timing every function call. These libraries let developers find the code that slows down a service or exhausts its memory.
Popularity
py-spy has the most monthly downloads in this comparison, at 21.3M.
@contextmanager
def memory_reporting() -> Generator[Tuple[Tracker, bool], None, None]:
# Restore the original function. This is needed because some # pytest plugins (e.g. flaky) will call our pytest_pyfunc_call # hook again with whatever is here, which will cause the wrapper # to be wrapped again. pyfuncitem.obj = func
result_file = _build_bin_path()
tracker_kwargs = {
"native_traces": native,
"trace_python_allocators": trace_python_allocators,
"file_format": FileFormat.AGGREGATED_ALLOCATIONS,
}
# Add track_object_lifetimes if tracking objects if track_objects: # pragma: no cover
tracker_kwargs["track_object_lifetimes"] = True
# mypy can't resolve the overload when using **kwargs unpacking tracker = Tracker(result_file, **tracker_kwargs) # type: ignore[call-overload]
yield (tracker, track_objects)
# Get surviving objects if tracking was enabled surviving_objects = None
if track_objects: # pragma: no cover
surviving_objects = list(tracker.get_surviving_objects())
try:
metadata = FileReader(result_file).metadata
except OSError:
return
result = Result(pyfuncitem.nodeid, metadata.peak_memory, result_file)
with NamedTemporaryFile(
dir=self.result_metadata_path,
delete=False,
) as tmp_file:
tmp_file.write(
json.dumps(
{
"test_id": result.test_id,
"peak_memory": result.peak_memory,
"result_file": str(result.result_file),
}
).encode("utf-8")
)
metadata_filename = result_file.with_suffix(".metadata").name
os.replace(tmp_file.name, self.result_metadata_path / metadata_filename)
self.results[pyfuncitem.nodeid] = result
# Store surviving objects separately (they can't be serialized) if surviving_objects is not None: # pragma: no cover
self.surviving_objects[pyfuncitem.nodeid] = surviving_objects
Pyinstrument
Samples Python call stacks to explain elapsed time across nested application work.
Downloads / mo
9.5M
Stars
8.0K
Last release
5.1.3
License
BSD-3-Clause
Strengths
Shows the full call stack.Trace elapsed time through callers and nested function work.
Renders browser-readable reports.Export HTML or JSON reports through its renderer interface.
Limitations
Elapsed time includes I/O waits.Waiting for network, files, or databases contributes to reported duration.
Sampling omits exact call counts.Sampled stacks describe elapsed activity rather than every function invocation.
def max_memory(self, dataset, repeat):
"""Compute average max memory consumed by model inference. Units are MiB"""
logger.info("Starting memory benchmarking")
total_memory = 0
for i, sample in enumerate(dataset):
for _r in range(repeat):
total_memory += max(memory_usage((self.forward, (sample,), {})))
if i % 100 == 0:
logger.info(f"Benchmarked memory for {i}/{len(dataset)} samples")
total_memory = total_memory / (repeat * len(dataset))
return total_memory
Yappi
Traces Python function calls with CPU or wall clocks and thread-aware profiling statistics.
Downloads / mo
3.0M
Stars
1.7K
Last release
1.7.6
License
MIT
Strengths
Chooses CPU or wall time.Switch clocks to separate CPU consumption from elapsed waiting.
Separates work by thread.Filter function statistics by thread context identifiers.
Limitations
CPU timing omits blocked waits.Choose wall time when blocked I/O belongs in the measurement.
Results persist until explicitly cleared.Call yappi.clear_stats between independent profiling sessions.
def stop(self):
if not yappi.is_running():
raise UsageError("CPU profiler is not running")
logging.info("Stopping CPU profiling")
yappi.stop()
stats = yappi.get_func_stats()
stats.save(self.filename, self.format)
yappi.clear_stats()
py-spy suits profiling a running process without changing its code. Pyinstrument suits readable call-stack reports from inside the program. Memray suits tracking down memory allocations.
Scalene samples CPU time, memory, and GPU activity and attributes them to Python and native code.
py-spy is a sampling profiler that attaches to a running Python process from outside it. It needs no changes to the application and may require extra permissions to attach.
Memray is a memory profiler that tracks allocations from Python, the interpreter, and native code, with the stack that made each one.
Memray records each allocation and the code that made it. memory_profiler samples memory usage line by line or for a whole process.
For coding agents
Found your profiling library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.