### Publisher Setup Example Source: https://github.com/bloomberg/memray/blob/main/benchmarks/benchmarking/cases/docutils_data/docs/dev/todo.txt Illustrates a potential setup sequence for the Publisher class, distinguishing between setting I/O classes and options before initializing I/O objects. ```python Publisher.get_settings() Publisher.set_io() Publisher.set_options() ``` -------------------------------- ### Install Docutils using setup.py Source: https://github.com/bloomberg/memray/blob/main/benchmarks/benchmarking/cases/docutils_data/docs/dev/repository.txt This command installs the Docutils package using its setup script. This is a standard method for installing Python packages, especially during development. ```bash python3 setup.py install ``` -------------------------------- ### Install Tutorial Dependencies Source: https://github.com/bloomberg/memray/blob/main/docs/tutorials/1.md Install all necessary dependencies for the tutorial using pip within the activated virtual environment. ```shell python3 -m pip install -r requirements-tutorial.txt ``` -------------------------------- ### Test Installation from Test PyPI Source: https://github.com/bloomberg/memray/blob/main/benchmarks/benchmarking/cases/docutils_data/docs/dev/release.txt Install Docutils from the test PyPI repository in a virtual environment to verify the build and installation process. Remember to clean up the virtual environment afterward. ```bash python3 -m venv du3 ; cd du3 export PYTHONPATH= ; . bin/activate python -m pip install --index-url https://test.pypi.org/simple/ --no-deps docutils cp -Lr ../docutils-code/docutils/test . python test/alltests.py python -m pip uninstall docutils deactivate ; cd .. ; rm -r du3 ``` -------------------------------- ### Install debuginfod client (Debian/Ubuntu) Source: https://github.com/bloomberg/memray/blob/main/docs/native_mode.md Install the debuginfod client library on Debian or Ubuntu systems using apt. ```shell $ sudo apt install debuginfod ``` -------------------------------- ### Install debuginfod client (Fedora) Source: https://github.com/bloomberg/memray/blob/main/docs/native_mode.md Install the debuginfod client library on Fedora systems using dnf. ```shell $ sudo dnf install elfutils-debuginfod ``` -------------------------------- ### Install and Configure Pyenv for Multiple Python Versions Source: https://github.com/bloomberg/memray/blob/main/benchmarks/benchmarking/cases/docutils_data/docs/dev/testing.txt Install and configure pyenv to manage multiple Python versions. This example installs Python 3.7.12, 3.8.12, and 3.10.1 and sets them as global versions. ```bash # assuming your system runs 3.9.x pyenv install 3.7.12 pyenv install 3.8.12 pyenv install 3.10.1 pyenv global system 3.7.12 3.8.12 3.10.1 # reset your shims rm -rf ~/.pyenv/shims && pyenv rehash ``` -------------------------------- ### Navigate to Tutorial Directory Source: https://github.com/bloomberg/memray/blob/main/docs/tutorials/1.md Change the current directory to the docs/tutorials folder to run the exercises. ```shell cd docs/tutorials/ ``` -------------------------------- ### File-Specific Configuration Example Source: https://github.com/bloomberg/memray/blob/main/benchmarks/benchmarking/cases/docutils_data/docs/dev/todo.txt Demonstrates how to specify configuration settings for individual files within a configuration file. ```ini [file index.txt] compact-lists: no ``` -------------------------------- ### Python Property Get - property_descr_get Source: https://github.com/bloomberg/memray/blob/main/docs/_static/flamegraphs/memray-flamegraph-mandelbrot.html This example shows the `property_descr_get` function, which is involved in accessing properties of Python objects. It's a key part of descriptor protocol implementation. ```json {"import_system": true, "interesting": true, "location": ["property_descr_get", "/opt/bb/src/python/python3.11/Objects/descrobject.c", "1630"], "n_allocations": 1, "name": " return PyObject_CallOneArg(gs->prop_get, obj);\n", "thread_id": "0x1", "value": 104} ``` -------------------------------- ### Shell Session Block Example Source: https://github.com/bloomberg/memray/blob/main/benchmarks/benchmarking/cases/docutils_data/docs/dev/todo.txt Demonstrates how a block starting with '$ ' is interpreted as a shell session interactive block. The block ends with the first blank line and does not require indentation. ```text $ cat example1.txt A block beginning with a "$ " prompt is interpreted as a shell session interactive block. As with Doctest blocks, the interactive block ends with the first blank line, and wouldn't have to be indented. ``` -------------------------------- ### Publisher Initialization with Settings Source: https://github.com/bloomberg/memray/blob/main/benchmarks/benchmarking/cases/docutils_data/docs/dev/runtime-settings-processing.txt Illustrates how a Publisher instance is created with settings during programmatic publishing. ```python pub = core.Publisher(…, settings) ``` -------------------------------- ### Numpy Imag Function Example Source: https://github.com/bloomberg/memray/blob/main/docs/_static/flamegraphs/memray-flamegraph-mandelbrot.html This snippet shows the definition of the 'imag' function in NumPy, which is used to get the imaginary part of a number. It's captured in the flamegraph for memory allocation analysis. ```python def imag(val): ``` -------------------------------- ### Root Shell Session Block Example Source: https://github.com/bloomberg/memray/blob/main/benchmarks/benchmarking/cases/docutils_data/docs/dev/todo.txt Shows how a block starting with '# ' is recognized as a root shell session interactive block. Similar to standard shell sessions, it concludes with a blank line. ```text # cat example2.txt A block beginning with a "# " prompt is interpreted as a root shell session (the user is or has to be logged in as root) interactive block. Again, the block ends with a blank line. ``` -------------------------------- ### Test Installation from Production PyPI Source: https://github.com/bloomberg/memray/blob/main/benchmarks/benchmarking/cases/docutils_data/docs/dev/release.txt Verify the installation from the production PyPI in a virtual environment. This step is similar to testing from test PyPI but uses the live repository. ```bash python3 -m venv du3 ; cd du3 export PYTHONPATH= ; . bin/activate pip install --no-deps docutils cp -Lr ../docutils-code/docutils/test . python test/alltests.py deactivate ; cd .. ; rm -r du3 ``` -------------------------------- ### Python Object Allocation Example Source: https://github.com/bloomberg/memray/blob/main/docs/_static/flamegraphs/memray-flamegraph-mandelbrot.html This snippet shows a typical memory allocation path in Python, starting from object creation and involving memory allocation functions. It's useful for understanding how Python manages memory internally. ```python return PyObject_Malloc(size);\n ``` ```python m = (PyModuleObject *)_PyType_AllocNoTrack(mt, 0);\n ``` ```python PyObject *m = (PyObject *)new_module_notrack(mt);\n ``` ```python return _PyObject.malloc(_PyObject.ctx, size);\n ``` ```python PyObject *obj = _PyType_AllocNoTrack(type, nitems);\n ``` ```python PyObject *obj = type->tp_alloc(type, 0);\n ``` ```python uint8_t *mem = PyMem_Malloc(n);\n ``` ```python return _PyMem.malloc(_PyMem.ctx, size);\n ``` -------------------------------- ### Run Memray in Live Mode Source: https://github.com/bloomberg/memray/blob/main/docs/live.md Start your Python application with Memray's live mode enabled to get a real-time TUI view of memory usage. This command launches the application in the background and connects a Text User Interface (TUI) to it. ```shell memray run --live application.py ``` -------------------------------- ### Example of adding stylesheets in rstpep2html.py Source: https://github.com/bloomberg/memray/blob/main/benchmarks/benchmarking/cases/docutils_data/docs/dev/todo.txt Demonstrates how to use --add-stylesheet and --add-stylesheet-path to include custom CSS files, accumulating them with existing settings. ```bash rstpep2html.py --add-stylesheet-path custom.css \ --add-stylesheet https://www.example.org/external.css ... ``` ```bash rstpep2html.py --add-stylesheet-path custom.css \ --stylesheet-path second.css ... ``` ```bash rstpep2html.py --stylesheet-path custom.css ... ``` ```bash rstpep2html.py --add-stylesheet-path custom.css ... ```