Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
vmprof-python/src/vmprof_main_win32.h at remove-click · vmprof/vmprof-python · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
vmprof
/
vmprof-python
Public
Notifications
You must be signed in to change notification settings
Fork
55
Star
439
Code
Issues
54
Pull requests
5
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
remove-click
Breadcrumbs
vmprof-python
/
src
/
vmprof_main_win32.h
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
133 lines (118 loc) · 3.29 KB
remove-click
Breadcrumbs
vmprof-python
/
src
/
vmprof_main_win32.h
Copy path
Top
File metadata and controls
Code
Blame
133 lines (118 loc) · 3.29 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include
"windows.h"
HANDLE
write_mutex
;
int
prepare_concurrent_bufs
(
void
)
{
if
(!(
write_mutex
=
CreateMutex
(
NULL
, FALSE,
NULL
)))
return
-1
;
return
0
;
}
#include
"vmprof_common.h"
#include
<tlhelp32.h>
// This file has been inspired (but not copied from since the LICENSE
// would not allow it) from verysleepy profiler
volatile
int
thread_started
=
0
;
volatile
int
enabled
=
0
;
static
int
_write_all
(
const
char
*
buf
,
size_t
bufsize
)
{
int
res
;
res
=
WaitForSingleObject
(
write_mutex
,
INFINITE
);
if
(
profile_file
==
-1
) {
ReleaseMutex
(
write_mutex
);
return
-1
;
}
while
(
bufsize
>
0
) {
ssize_t
count
=
write
(
profile_file
,
buf
,
bufsize
);
if
(
count
<=
0
) {
ReleaseMutex
(
write_mutex
);
return
-1
;
/* failed */
}
buf
+=
count
;
bufsize
-=
count
;
}
ReleaseMutex
(
write_mutex
);
return
0
;
}
RPY_EXTERN
int
vmprof_register_virtual_function
(
char
*
code_name
,
long
code_uid
,
int
auto_retry
)
{
char
buf
[
2048
];
int
namelen
=
strnlen
(
code_name
,
1023
);
buf
[
0
]
=
MARKER_VIRTUAL_IP
;
*
(
long
*
)(
buf
+
1
)
=
code_uid
;
*
(
long
*
)(
buf
+
1
+
sizeof
(
long
))
=
namelen
;
memcpy
(
buf
+
1
+
2
*
sizeof
(
long
),
code_name
,
namelen
);
_write_all
(
buf
,
namelen
+
2
*
sizeof
(
long
)
+
1
);
return
0
;
}
int
vmprof_snapshot_thread
(
DWORD
thread_id
,
PyThreadState
*
tstate
,
prof_stacktrace_s
*
stack
)
{
HRESULT
result
;
HANDLE
hThread
=
OpenThread
(
THREAD_ALL_ACCESS
, FALSE,
thread_id
);
int
depth
;
if
(!
hThread
) {
return
-1
;
}
result
=
SuspendThread
(
hThread
);
if
(
result
==
0xffffffff
)
return
-1
;
// possible, e.g. attached debugger or thread alread suspended
// find the correct thread
depth
=
read_trace_from_cpy_frame
(
tstate
->
frame
,
stack
->
stack
,
MAX_STACK_DEPTH
);
stack
->
depth
=
depth
;
stack
->
stack
[
depth
++
]
=
(
void
*
)
thread_id
;
stack
->
count
=
1
;
stack
->
marker
=
MARKER_STACKTRACE
;
ResumeThread
(
hThread
);
return
depth
;
}
long
__stdcall
vmprof_mainloop
(
void
*
arg
)
{
prof_stacktrace_s
*
stack
=
(
prof_stacktrace_s
*
)
malloc
(
SINGLE_BUF_SIZE
);
HANDLE
hThreadSnap
=
INVALID_HANDLE_VALUE
;
int
depth
;
PyThreadState
*
tstate
;
while
(
1
) {
Sleep
(
profile_interval_usec
*
1000
);
if
(!
enabled
) {
continue
;
}
tstate
=
PyInterpreterState_Head
()
->
tstate_head
;
while
(
tstate
) {
depth
=
vmprof_snapshot_thread
(
tstate
->
thread_id
,
tstate
,
stack
);
if
(
depth
>
0
) {
_write_all
((
char
*
)
stack
+
offsetof(
prof_stacktrace_s
,
marker
),
depth
*
sizeof
(
void
*
)
+
sizeof
(
struct
prof_stacktrace_s
)
-
offsetof(
struct
prof_stacktrace_s
,
marker
));
}
tstate
=
tstate
->
next
;
}
}
}
RPY_EXTERN
int
vmprof_enable
(
void
)
{
if
(!
thread_started
) {
if
(!
CreateThread
(
NULL
,
0
,
vmprof_mainloop
,
NULL
,
0
,
NULL
)) {
return
-1
;
}
thread_started
=
1
;
}
enabled
=
1
;
return
0
;
}
RPY_EXTERN
int
vmprof_disable
(
void
)
{
char
marker
=
MARKER_TRAILER
;
enabled
=
0
;
if
(
_write_all
(
&
marker
,
1
)
<
0
)
return
-1
;
profile_file
=
-1
;
return
0
;
}
RPY_EXTERN
void
vmprof_ignore_signals
(
int
ignored
)
{
}
You can’t perform that action at this time.