Python* Code Analysis
Configure Python Data Collection
- Click theConfigure Analysisbutton on the toolbar.The Configure Analysis window opens.
- Choose a target system and target type. For example:Local HostandLaunch Application.Only Windows* and Linux* target systems are supported.
- In theLaunch Applicationconfiguration pane, specify a path to the installed Python interpreter in theApplicationfield and a path to your Python script in theApplication parametersfield.If you specify a relative path to your Python script in theApplication parametersfield, theVTuneproperly resolves full function or method names only for the imported modules, and does not resolve the names inside the main script. Consider specifying the absolute path to the script.ProfilerIn addition, you may select theAutomanaged code profiling mode, and theVTuneautomatically detects the type of target executable, managed or native, and switches to the corresponding mode. Optionally, you may selectProfilerAnalyze child processesoption to collect data on processes launched by the target process. For example, on Linux your configuration may look like this:In case your Python application needs to run before the profiling starts or cannot be launched at the start of this analysis, you may attach theVTuneto the Python process. To do this, select theProfilerAttach to Processtarget type and specify the Python process name or PID as follows:When you attach theVTuneto the Python process, make sure you initialize the Global Interpreter Lock (GIL) inside your script before you start the analysis. If GIL is not initialized, theProfilerVTunecollector initializes it only when a new Python function is called.Profiler
- From theHOWconfiguration pane on the right, select theHotspots,Threading, orMemory Consumptionanalysis type.
- Configure the following options, if required, or use the defaults:User-Mode SamplingmodeSelect to enable the user-mode sampling and tracing collection for hotspots and call stack analysis (formerly known as Basic Hotspots). This collection mode uses a fixed sampling interval of 10ms. If you need to change the interval, click theCopybutton and create a custom analysis configuration.Hardware Event-Based SamplingmodeSelect to enable hardware event-based sampling collection for hotspots analysis (formerly known as Advanced Hotspots).You can configure the following options for this collection mode:
When changing collection options, pay attention to theOverheaddiagram on the right. It dynamically changes to reflect the collection overhead incurred by the selected options.Show additional performance insightscheck boxGet additional performance insights, such as vectorization, and learn next steps. This option collects additional CPU events, which may enable the multiplexing mode.The option is enabled by default.DetailsbuttonExpand/collapse a section listing the default non-editable settings used for this analysis type. If you want to modify or enable additional settings for the analysis, you need to create a custom configuration by copying an existing predefined configuration.VTunecreates an editable copy of this analysis type configuration.Profiler
- CPU sampling interval, msto specify an interval (in milliseconds) between CPU samples. Possible values for thehardware event-based samplingmode are0.01-1000.1 msis used by default.
- Collect stacksto enable advanced collection of call stacks and thread context switches.
- Click theStartbutton to run the analysis.
- Only Python distribution 2.6 and later are supported.
- If you use Python extensions that compile Python code to the native language (JIT, C/C++), theVTunemay show incorrect analysis results. Consider using JIT Profiling API to solve this problem.Profiler
- Python code profiling is supported for Windows and Linux target systems only.
- In some cases, theVTunemay not resolve full names of Python functions and modules on Windows OS. It displays correct source information, so you can view the source directly from theProfilerVTune's viewpoints.Profiler
- Proper thread names are not always displayed in the Timeline pane.
- If your application has very low stack depth, which includes called functions and imported modules, theVTunedoes not collect Python data. Consider using deeper calls to enable the profiling.Profiler
- When collecting data remotely, theVTunemay not resolve full function or method names, and display the source code of your Python script.ProfilerTo solve this problem for Linux targets, copy the source files to a directory on your host system with a path identical to the path on your target system before running the analysis.