Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Philippe_C_
Beginner
179 Views

Analyse python file from embedded python

Hi, I would like have a python analysis for Python files executed from the C python API, like in this sample code adapted from https://docs.python.org/3/extending/embedding.html :

#define PY_SSIZE_T_CLEAN
#include <Python.h>

int
main(int argc, char *argv[])
{
	printf("before\n");
	wchar_t *program = Py_DecodeLocale(argv[0], NULL);
	if (program == NULL) {
		fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
		exit(1);
	}
	Py_SetProgramName(program); 
	Py_Initialize();
	auto* f = fopen("f.py", "rb");
	auto r = PyRun_SimpleFile(f, "f.py");
	if (Py_FinalizeEx() < 0) {
		exit(120);
	}
	PyMem_RawFree(program);
	return 0;
}

When I use Hostspots analysis with user mode sampling and managed mode set to any of (auto, native, mixed), I only get the C/C++ functions. 

python37_d.dll ! PyEval_EvalFrameDefault - ceval.c
python37_d.dll ! PyEval_EvalCodeWithName + 0xaf3 - ceval.c:3930
python37_d.dll ! PyEval_EvalCodeEx + 0x95 - ceval.c:3959
python37_d.dll ! PyEval_EvalCode + 0x2d - ceval.c:524
python37_d.dll ! run_mod + 0x69 - pythonrun.c:1035
python37_d.dll ! PyRun_FileExFlags + 0x111 - pythonrun.c:988
python37_d.dll ! PyRun_SimpleFileExFlags + 0x4df - pythonrun.c:429
embed1.exe ! [embed1.exe] + 0x11a2f - [unknown source file]

It is possible to have the python file/stack analysis, and how ? Thank you

I use vtune 2020-60519 with Visual Studio 2017 on Windows.

0 Kudos
4 Replies
ArunJ_Intel
Moderator
177 Views

Hi Philippe

Vtune usually tend to point to cpp code abstracted beneath the python code. So it is expected behavior to get ony the  the C/C++ functions. We will check with experts on the possibility of a python file/stack analysis and get back to you.

 

Arun Jose

Mayank_T_Intel
Employee
177 Views

Hi Philippe.

 

There are some limitations with Python profiling in VTune. You can refer this https://software.intel.com/en-us/vtune-help-python-code-analysis for more details. I saw you are using Python 3. The best support from VTune is currently available for Python 2.6. Also, your application should have at least 2 Python functions in the stack otherwise VTune may show only native code profile data. If still you are having issues, please feel free to respond to the thread.

 

Thanks,

Mayank

Mayank_T_Intel
Employee
177 Views

Hi Philippe,

Has your issue been resolved? Can we close the thread?

Thanks,

Mayank

Philippe_C_
Beginner
177 Views

Hi Mayank,

You can close this thread, although my issue is not solved, as I must use Python 3. I will stay tuned for updated about Python 3 support. My final use case is to profile a Blender plugin. I just checked and I can confirm that vTune insists in showing only the C frames, although the Python stack is at least 6 python functions deep.

Philippe

Reply