class_docstr: Magics related to code execution, debugging, profiling, etc.
  
      
docstr: Run a statement through the python code profiler.
  
  Usage, in line mode:
    %prun [options] statement
  
  Usage, in cell mode:
    %%prun [options] [statement]
    code...
    code...
  
  In cell mode, the additional code lines are appended to the (possibly
  empty) statement in the first line.  Cell mode allows you to easily
  profile multiline blocks without having to put them in a separate
  function.
  
  The given statement (which doesn't require quote marks) is run via the
  python profiler in a manner similar to the profile.run() function.
  Namespaces are internally managed to work correctly; profile.run
  cannot be used in IPython because it makes certain assumptions about
  namespaces which do not hold under IPython.
  
  Options:
  
  -l <limit>
    you can place restrictions on what or how much of the
    profile gets printed. The limit value can be:
  
       * A string: only information for function names containing this string
         is printed.
  
       * An integer: only these many lines are printed.
  
       * A float (between 0 and 1): this fraction of the report is printed
         (for example, use a limit of 0.4 to see the topmost 40% only).
  
    You can combine several limits with repeated use of the option. For
    example, ``-l __init__ -l 5`` will print only the topmost 5 lines of
    information about class constructors.
  
  -r
    return the pstats.Stats object generated by the profiling. This
    object has all the information about the profile in it, and you can
    later use it for further analysis or in other functions.
  
  -s <key>
    sort profile by given key. You can provide more than one key
    by using the option several times: '-s key1 -s key2 -s key3...'. The
    default sorting key is 'time'.
  
    The following is copied verbatim from the profile documentation
    referenced below:
  
    When more than one key is provided, additional keys are used as
    secondary criteria when the there is equality in all keys selected
    before them.
  
    Abbreviations can be used for any key names, as long as the
    abbreviation is unambiguous.  The following are the keys currently
    defined:
  
    ============  =====================
    Valid Arg     Meaning
    ============  =====================
    "calls"       call count
    "cumulative"  cumulative time
    "file"        file name
    "module"      file name
    "pcalls"      primitive call count
    "line"        line number
    "name"        function name
    "nfl"         name/file/line
    "stdname"     standard name
    "time"        internal time
    ============  =====================
  
    Note that all sorts on statistics are in descending order (placing
    most time consuming items first), where as name, file, and line number
    searches are in ascending order (i.e., alphabetical). The subtle
    distinction between "nfl" and "stdname" is that the standard name is a
    sort of the name as printed, which means that the embedded line
    numbers get compared in an odd way.  For example, lines 3, 20, and 40
    would (if the file names were the same) appear in the string order
    "20" "3" and "40".  In contrast, "nfl" does a numeric compare of the
    line numbers.  In fact, sort_stats("nfl") is the same as
    sort_stats("name", "file", "line").
  
  -T <filename>
    save profile results as shown on screen to a text
    file. The profile is still shown on screen.
  
  -D <filename>
    save (via dump_stats) profile statistics to given
    filename. This data is in a format understood by the pstats module, and
    is generated by a call to the dump_stats() method of profile
    objects. The profile is still shown on screen.
  
  -q
    suppress output to the pager.  Best used with -T and/or -D above.
  
  If you want to run complete programs under the profiler's control, use
  ``%run -p [prof_opts] filename.py [args to program]`` where prof_opts
  contains profiler specific options as described here.
  
  You can read the complete documentation for the profile module with::
  
    In [1]: import profile; profile.help()
docstr_tok: ["Run","a","statement","through","the","python","code","profiler",".","Usage",",","in","line","mode",":","%","prun","[","options","]","statement","Usage",",","in","cell","mode",":","%","%","prun","[","options","]","[","statement","]","code","...","code","...","In","cell","mode",",","the","additional","code","lines","are","appended","to","the","(","possibly","empty",")","statement","in","the","first","line",".","Cell","mode","allows","you","to","easily","profile","multiline","blocks","without","having","to","put","them","in","a","separate","function",".","The","given","statement","(","which","does","n't","require","quote","marks",")","is","run","via","the","python","profiler","in","a","manner","similar","to","the","profile.run","(",")","function",".","Namespaces","are","internally","managed","to","work","correctly",";","profile.run","can","not","be","used","in","IPython","because","it","makes","certain","assumptions","about","namespaces","which","do","not","hold","under","IPython",".","Options",":","-l","<","limit",">","you","can","place","restrictions","on","what","or","how","much","of","the","profile","gets","printed",".","The","limit","value","can","be",":","*","A","string",":","only","information","for","function","names","containing","this","string","is","printed",".","*","An","integer",":","only","these","many","lines","are","printed",".","*","A","float","(","between","0","and","1",")",":","this","fraction","of","the","report","is","printed","(","for","example",",","use","a","limit","of","0.4","to","see","the","topmost","40","%","only",")",".","You","can","combine","several","limits","with","repeated","use","of","the","option",".","For","example",",","``","-l","__init__","-l","5","``","will","print","only","the","topmost","5","lines","of","information","about","class","constructors",".","-r","return","the","pstats.Stats","object","generated","by","the","profiling",".","This","object","has","all","the","information","about","the","profile","in","it",",","and","you","can","later","use","it","for","further","analysis","or","in","other","functions",".","-s","<","key",">","sort","profile","by","given","key",".","You","can","provide","more","than","one","key","by","using","the","option","several","times",":","'-s","key1","-s","key2","-s","key3","...","'",".","The","default","sorting","key","is","'time","'",".","The","following","is","copied","verbatim","from","the","profile","documentation","referenced","below",":","When","more","than","one","key","is","provided",",","additional","keys","are","used","as","secondary","criteria","when","the","there","is","equality","in","all","keys","selected","before","them",".","Abbreviations","can","be","used","for","any","key","names",",","as","long","as","the","abbreviation","is","unambiguous",".","The","following","are","the","keys","currently","defined",":","============","=====================","Valid","Arg","Meaning","============","=====================","``","calls","''","call","count","``","cumulative","''","cumulative","time","``","file","''","file","name","``","module","''","file","name","``","pcalls","''","primitive","call","count","``","line","''","line","number","``","name","''","function","name","``","nfl","''","name\/file\/line","``","stdname","''","standard","name","``","time","''","internal","time","============","=====================","Note","that","all","sorts","on","statistics","are","in","descending","order","(","placing","most","time","consuming","items","first",")",",","where","as","name",",","file",",","and","line","number","searches","are","in","ascending","order","(","i.e.",",","alphabetical",")",".","The","subtle","distinction","between","``","nfl","''","and","``","stdname","''","is","that","the","standard","name","is","a","sort","of","the","name","as","printed",",","which","means","that","the","embedded","line","numbers","get","compared","in","an","odd","way",".","For","example",",","lines","3",",","20",",","and","40","would","(","if","the","file","names","were","the","same",")","appear","in","the","string","order","``","20","''","``","3","''","and","``","40","''",".","In","contrast",",","``","nfl","''","does","a","numeric","compare","of","the","line","numbers",".","In","fact",",","sort_stats","(","``","nfl","''",")","is","the","same","as","sort_stats","(","``","name","''",",","``","file","''",",","``","line","''",")",".","-T","<","filename",">","save","profile","results","as","shown","on","screen","to","a","text","file",".","The","profile","is","still","shown","on","screen",".","-D","<","filename",">","save","(","via","dump_stats",")","profile","statistics","to","given","filename",".","This","data","is","in","a","format","understood","by","the","pstats","module",",","and","is","generated","by","a","call","to","the","dump_stats","(",")","method","of","profile","objects",".","The","profile","is","still","shown","on","screen",".","-q","suppress","output","to","the","pager",".","Best","used","with","-T","and\/or","-D","above",".","If","you","want","to","run","complete","programs","under","the","profiler","'s","control",",","use","``","%","run","-p","[","prof_opts","]","filename.py","[","args","to","program","]","``","where","prof_opts","contains","profiler","specific","options","as","described","here",".","You","can","read","the","complete","documentation","for","the","profile","module","with",":",":","In","[","1","]",":","import","profile",";","profile.help","(",")"]
code: def prun(self, parameter_s="", cell=None):
      """Run a statement through the python code profiler.
  
      Usage, in line mode:
        %prun [options] statement
  
      Usage, in cell mode:
        %%prun [options] [statement]
        code...
        code...
  
      In cell mode, the additional code lines are appended to the (possibly
      empty) statement in the first line.  Cell mode allows you to easily
      profile multiline blocks without having to put them in a separate
      function.
  
      The given statement (which doesn't require quote marks) is run via the
      python profiler in a manner similar to the profile.run() function.
      Namespaces are internally managed to work correctly; profile.run
      cannot be used in IPython because it makes certain assumptions about
      namespaces which do not hold under IPython.
  
      Options:
  
      -l <limit>
        you can place restrictions on what or how much of the
        profile gets printed. The limit value can be:
  
           * A string: only information for function names containing this string
             is printed.
  
           * An integer: only these many lines are printed.
  
           * A float (between 0 and 1): this fraction of the report is printed
             (for example, use a limit of 0.4 to see the topmost 40% only).
  
        You can combine several limits with repeated use of the option. For
        example, ``-l __init__ -l 5`` will print only the topmost 5 lines of
        information about class constructors.
  
      -r
        return the pstats.Stats object generated by the profiling. This
        object has all the information about the profile in it, and you can
        later use it for further analysis or in other functions.
  
      -s <key>
        sort profile by given key. You can provide more than one key
        by using the option several times: '-s key1 -s key2 -s key3...'. The
        default sorting key is 'time'.
  
        The following is copied verbatim from the profile documentation
        referenced below:
  
        When more than one key is provided, additional keys are used as
        secondary criteria when the there is equality in all keys selected
        before them.
  
        Abbreviations can be used for any key names, as long as the
        abbreviation is unambiguous.  The following are the keys currently
        defined:
  
        ============  =====================
        Valid Arg     Meaning
        ============  =====================
        "calls"       call count
        "cumulative"  cumulative time
        "file"        file name
        "module"      file name
        "pcalls"      primitive call count
        "line"        line number
        "name"        function name
        "nfl"         name/file/line
        "stdname"     standard name
        "time"        internal time
        ============  =====================
  
        Note that all sorts on statistics are in descending order (placing
        most time consuming items first), where as name, file, and line number
        searches are in ascending order (i.e., alphabetical). The subtle
        distinction between "nfl" and "stdname" is that the standard name is a
        sort of the name as printed, which means that the embedded line
        numbers get compared in an odd way.  For example, lines 3, 20, and 40
        would (if the file names were the same) appear in the string order
        "20" "3" and "40".  In contrast, "nfl" does a numeric compare of the
        line numbers.  In fact, sort_stats("nfl") is the same as
        sort_stats("name", "file", "line").
  
      -T <filename>
        save profile results as shown on screen to a text
        file. The profile is still shown on screen.
  
      -D <filename>
        save (via dump_stats) profile statistics to given
        filename. This data is in a format understood by the pstats module, and
        is generated by a call to the dump_stats() method of profile
        objects. The profile is still shown on screen.
  
      -q
        suppress output to the pager.  Best used with -T and/or -D above.
  
      If you want to run complete programs under the profiler's control, use
      ``%run -p [prof_opts] filename.py [args to program]`` where prof_opts
      contains profiler specific options as described here.
  
      You can read the complete documentation for the profile module with::
  
        In [1]: import profile; profile.help()
      """
      opts, arg_str = self.parse_options(
          parameter_s, "D:l:rs:T:q", list_all=True, posix=False
      )
      if cell is not None:
          arg_str += "\n" + cell
      arg_str = self.shell.input_splitter.transform_cell(arg_str)
      return self._run_with_profiler(arg_str, opts, self.shell.user_ns)
  
imports: from __future__ import print_function
  from __future__ import absolute_import
  import ast
  import bdb
  import gc
  import itertools
  import os
  import sys
  import time
  import timeit
  from pdb import Restart
  from IPython.core import oinspect
  from IPython.core import magic_arguments
  from IPython.core import page
  from IPython.core.error import UsageError
  from IPython.core.macro import Macro
  from IPython.core.magic import Magics, magics_class, line_magic, cell_magic, line_cell_magic, on_off, needs_local_scope
  from IPython.testing.skipdoctest import skip_doctest
  from IPython.utils import py3compat
  from IPython.utils.py3compat import builtin_mod, iteritems, PY3
  from IPython.utils.contexts import preserve_keys
  from IPython.utils.capture import capture_output
  from IPython.utils.ipstruct import Struct
  from IPython.utils.module_paths import find_mod
  from IPython.utils.path import get_py_filename, shellglob
  from IPython.utils.timing import clock, clock2
  from warnings import warn
  from logging import error
label_desc: Use image node_id 3 for calling the ExecutionMagics obj's underlying member method code with example usage: obj.prun(parameter_s, cell) and returns: self