mirror of
https://github.com/python/cpython.git
synced 2025-08-23 18:24:46 +00:00
gh-109587: Allow "precompiled" perf-trampolines to largely mitigate the cost of enabling perf-trampolines (#109666)
This commit is contained in:
parent
3d2f1f0b83
commit
21f068d80c
8 changed files with 199 additions and 10 deletions
|
@ -2361,7 +2361,7 @@ PyAPI_FUNC(int) PyUnstable_WritePerfMapEntry(
|
|||
#ifndef MS_WINDOWS
|
||||
if (perf_map_state.perf_map == NULL) {
|
||||
int ret = PyUnstable_PerfMapState_Init();
|
||||
if(ret != 0){
|
||||
if (ret != 0){
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -2388,6 +2388,45 @@ PyAPI_FUNC(void) PyUnstable_PerfMapState_Fini(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
PyAPI_FUNC(int) PyUnstable_CopyPerfMapFile(const char* parent_filename) {
|
||||
#ifndef MS_WINDOWS
|
||||
FILE* from = fopen(parent_filename, "r");
|
||||
if (!from) {
|
||||
return -1;
|
||||
}
|
||||
if (perf_map_state.perf_map == NULL) {
|
||||
int ret = PyUnstable_PerfMapState_Init();
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
char buf[4096];
|
||||
PyThread_acquire_lock(perf_map_state.map_lock, 1);
|
||||
int fflush_result = 0, result = 0;
|
||||
while (1) {
|
||||
size_t bytes_read = fread(buf, 1, sizeof(buf), from);
|
||||
size_t bytes_written = fwrite(buf, 1, bytes_read, perf_map_state.perf_map);
|
||||
fflush_result = fflush(perf_map_state.perf_map);
|
||||
if (fflush_result != 0 || bytes_read == 0 || bytes_written < bytes_read) {
|
||||
result = -1;
|
||||
goto close_and_release;
|
||||
}
|
||||
if (bytes_read < sizeof(buf) && feof(from)) {
|
||||
goto close_and_release;
|
||||
}
|
||||
}
|
||||
close_and_release:
|
||||
fclose(from);
|
||||
PyThread_release_lock(perf_map_state.map_lock);
|
||||
return result;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static PyMethodDef sys_methods[] = {
|
||||
/* Might as well keep this in alphabetic order */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue