[wperf] WPERF-618: Switch to `CComPtr`s and release the `DiaDataSource` to remove memory leaks.
Introduction
Solves the memory leak reported by WPERF-618. The leaks were detected using the AppVerifier with the default settings using the command,
.\wperf.exe record -e vfp_spec:10000 -c 0 --timeout 5 -- .\WindowsPerfSample1.exe
the leak traces inside the JIRA ticket pointed to the origin as being the pe_file::read_function_lines and pe_file::parse_pdb_file. The problem with the later is that we were not calling the Release() function of DiaDataSource. On read_function_lines we were using normal C pointers instead of the required CComPtr.
In this patch:
- [wperf] Switch to
CComPtrs and release theDiaDataSourceto remove memory leaks.
Testing
Volterra test results
============================= test session starts =============================
platform win32 -- Python 3.12.0, pytest-7.4.4, pluggy-1.3.0
rootdir: C:\Users\tcwg\wperf-scripts\tests
configfile: pytest.ini
collected 188 items / 4 skipped
wperf_cli_common_test.py .... [ 2%]
wperf_cli_config_test.py ..... [ 4%]
wperf_cli_extra_events_test.py .... [ 6%]
wperf_cli_info_str_test.py . [ 7%]
wperf_cli_json_validator_test.py .......... [ 12%]
wperf_cli_list_test.py ..... [ 15%]
wperf_cli_metrics_test.py ..s....sssssssss [ 23%]
wperf_cli_padding_test.py .............. [ 31%]
wperf_cli_record_test.py .............. [ 38%]
wperf_cli_sample_test.py .. [ 39%]
wperf_cli_stat_test.py ................................................. [ 65%]
..s [ 67%]
wperf_cli_test_test.py ........ [ 71%]
wperf_cli_timeline_test.py ...........................ssssssssssssssssss [ 95%]
....... [ 99%]
wperf_lib_app_test.py s [100%]
============================== warnings summary ===============================
wperf_cli_json_validator_test.py::test_wperf_timeline_json_schema
wperf_cli_json_validator_test.py::test_wperf_timeline_json_schema
wperf_cli_json_validator_test.py::test_wperf_timeline_json_stdout_schema
wperf_cli_json_validator_test.py::test_wperf_timeline_json_stdout_schema
C:\Python312\Lib\site-packages\jsonschema\_keywords.py:295: DeprecationWarning: Automatically retrieving remote references can be a security vulnerability and is discouraged by the JSON Schema specifications. Relying on this behavior is deprecated and will shortly become an error. If you are sure you want to remotely retrieve your reference and that it is safe to do so, you can find instructions for doing so via referencing.Registry in the referencing documentation (https://referencing.readthedocs.org).
yield from validator.descend(
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ===========================
SKIPPED [1] wperf_cli_ustress_bench_test.py:109: skipping as ustress do not support CPU=ARMV8_A
SKIPPED [1] wperf_cli_ustress_dep_record_test.py:104: skipping as ustress do not support CPU=ARMV8_A
SKIPPED [1] wperf_cli_ustress_dep_wperf_lib_timeline_test.py:107: skipping as ustress do not support CPU=ARMV8_A
SKIPPED [1] wperf_cli_ustress_dep_wperf_test.py:107: skipping as ustress do not support CPU=ARMV8_A
SKIPPED [2] wperf_cli_metrics_test.py:71: unsupported configuration
SKIPPED [4] wperf_cli_metrics_test.py:99: unsupported configuration
SKIPPED [4] wperf_cli_metrics_test.py:129: unsupported configuration
SKIPPED [1] wperf_cli_stat_test.py:295: place wperf.exe in the same directory as tests to run the test
SKIPPED [4] wperf_cli_timeline_test.py:250: unsupported metric: l1d_cache_miss_ratio
SKIPPED [2] wperf_cli_timeline_test.py:250: unsupported metric: l1d_tlb_mpki
SKIPPED [8] wperf_cli_timeline_test.py:312: unsupported metric: l1d_cache_miss_ratio
SKIPPED [4] wperf_cli_timeline_test.py:312: unsupported metric: l1d_tlb_mpki
SKIPPED [1] wperf_lib_app_test.py:44: Can not run wperf-lib-app.exe
=========== 158 passed, 34 skipped, 4 warnings in 326.40s (0:05:26) ===========
Ampere is currently under maintenance.
Result from the following command
.\wperf.exe record -e vfp_spec:10000 -c 0 --timeout 5 --annotate -- .\WindowsPerfSample1.exe
is
base address of '.\WindowsPerfSample1.exe': 0x7ff6943115c4, runtime delta: 0x7ff554300000
sampling ....eeee done!
======================== sample source: vfp_spec, top 50 hot functions ========================
simd_hot
line_number hits filename
=========== ==== ========
53 89 C:\Users\evert\source\repos\WindowsPerfSample\lib.c
52 13 C:\Users\evert\source\repos\WindowsPerfSample\lib.c
overhead count symbol
======== ===== ======
79.69 102 simd_hot
20.31 26 unknown
100.00% 128 top 2 in total
AppVerifier with the above command and default settings no longer shows memory leaks.