{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "remove-input",
     "active-ipynb",
     "remove-output"
    ]
   },
   "outputs": [],
   "source": [
    "try:\n",
    "    from openmdao.utils.notebook_utils import notebook_mode\n",
    "except ImportError:\n",
    "    !python -m pip install openmdao[notebooks]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Profiling and Tracing\n",
    "\n",
    "* [Instance-based Profiling](inst_profile.ipynb)\n",
    "* [Memory Profiling](inst_mem_profile.ipynb)\n",
    "* [Instance-based Call Tracing](inst_call_tracing.ipynb)\n",
    "\n",
    "The profiling and call tracing tools mentioned above have a similar programmatic interface, even though most of the time they will only be used in command-line mode. However, if you really want to customize the set of methods that are to be profiled or traced, see the following example.\n",
    "\n",
    "``` python\n",
    "    # for performance profiling\n",
    "    from openmdao.devtools import iprofile as tool\n",
    "\n",
    "    # OR for call tracing\n",
    "    # from openmdao.devtools import itrace as tool\n",
    "\n",
    "    # First, make sure that the classes I use to define my method set exist in this\n",
    "    # namespace.\n",
    "    from mystuff import MyClass, MyOtherClass\n",
    "\n",
    "    # Let's say I only want to track methods with 'foo' or 'bar' in the name that belong to\n",
    "    # MyClass and ones with 'baz' in the name that belong to either MyClass or MyOtherClass.\n",
    "    # I use the following glob patterns and tuples of classes to specify this.\n",
    "    methods = [\n",
    "        ('*foo*', (MyClass,)),\n",
    "        ('*bar*', (MyClass,)),\n",
    "        ('*baz*', (MyClass, MyOtherClass))\n",
    "    ]\n",
    "\n",
    "    # set up the tool using my custom method set\n",
    "    tool.setup(methods=methods)\n",
    "\n",
    "    tool.start()\n",
    "\n",
    "    # run the code I want to profile/trace...\n",
    "\n",
    "    tool.stop()\n",
    "\n",
    "    # do some other stuff that I don't want to profile/trace...\n",
    "```"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "orphan": true
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
