forked from vmprof/vmprof-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_vmprof.h
53 lines (40 loc) · 1.64 KB
/
_vmprof.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include "vmprof.h"
#ifdef VMPROF_WINDOWS
#include <Python.h>
// CPython 3.6 defines all the inttypes for us, we do not need the msiinttypes
// library for that version or any newer!
#if (PY_VERSION_HEX < 0x3060000)
#include "msiinttypes/inttypes.h"
#include "msiinttypes/stdint.h"
#endif
#else
#include <inttypes.h>
#include <stdint.h>
#include <stddef.h>
#endif
/**
* This whole setup is very strange. There was just one C file called
* _vmprof.c which included all *.h files to copy code. Unsure what
* the goal was with this design, but I assume it just 'GREW'
*
* Thus I'm (plan_rich) slowly trying to separate this. *.h files
* should not have complex implementations (all of them currently have them)
*/
#define SINGLE_BUF_SIZE (8192 - 2 * sizeof(unsigned int))
#define ROUTINE_IS_PYTHON(RIP) ((unsigned long long)RIP & 0x1) == 0
#define ROUTINE_IS_C(RIP) ((unsigned long long)RIP & 0x1) == 1
/* This returns the address of the code object
as the identifier. The mapping from identifiers to string
representations of the code object is done elsewhere, namely:
* If the code object dies while vmprof is enabled,
PyCode_Type.tp_dealloc will emit it. (We don't handle nicely
for now the case where several code objects are created and die
at the same memory address.)
* When _vmprof.disable() is called, then we look around the
process for code objects and emit all the ones that we can
find (which we hope is very close to 100% of them).
*/
#define CODE_ADDR_TO_UID(co) (((intptr_t)(co)))
#define CPYTHON_HAS_FRAME_EVALUATION PY_VERSION_HEX >= 0x30600B0
int vmp_write_all(const char *buf, size_t bufsize);