diff --git a/c_src/quicer_nif.c b/c_src/quicer_nif.c index aa0fe5fa..4ecfa370 100644 --- a/c_src/quicer_nif.c +++ b/c_src/quicer_nif.c @@ -21,7 +21,10 @@ limitations under the License. #include "quicer_listener.h" #include "quicer_vsn.h" +#if defined(__linux__) #include +#endif + #include #include @@ -1703,6 +1706,16 @@ do_malloc_trim(__unused_parm__ ErlNifEnv *env, return ATOM_OK; } +ERL_NIF_TERM +do_malloc_stats(__unused_parm__ ErlNifEnv *env, + __unused_parm__ int argc, + __unused_parm__ const ERL_NIF_TERM argv[]) +{ + CXPLAT_FRE_ASSERT(argc == 0); + malloc_stats(); + return ATOM_OK; +} + static ErlNifFunc nif_funcs[] = { /* | name | arity| funptr | flags| * @@ -1755,7 +1768,10 @@ static ErlNifFunc nif_funcs[] = { { "copy_stream_handle", 1, copy_stream_handle, 0}, /* for testing */ { "mock_buffer_sig", 3, mock_buffer_sig, 0}, +#if defined(__linux__) { "malloc_trim", 0, do_malloc_trim, 0}, + { "malloc_stats", 0, do_malloc_stats, 0}, +#endif #ifdef QUICER_USE_SNK { "set_snab_kc_pid", 1, set_snab_kc_pid, 0}, { "get_snab_kc_pid", 0, get_snab_kc_pid, 0}, diff --git a/src/quicer_nif.erl b/src/quicer_nif.erl index e6354de7..3d260a0a 100644 --- a/src/quicer_nif.erl +++ b/src/quicer_nif.erl @@ -55,7 +55,10 @@ ]). %% tools --export([malloc_trim/0]). +-export([ + malloc_trim/0, + malloc_stats/0 +]). %% For tests only -export([ @@ -354,6 +357,10 @@ get_stream_rid(_Handle) -> malloc_trim() -> erlang:nif_error(nif_library_not_loaded). +-spec malloc_stats() -> ok. +malloc_stats() -> + erlang:nif_error(nif_library_not_loaded). + -spec controlling_process(connection_handle() | stream_handle(), pid()) -> ok | {error, closed | badarg | owner_dead | not_owner}. diff --git a/test/quicer_SUITE.erl b/test/quicer_SUITE.erl index 2688b7b1..0c6a4928 100644 --- a/test/quicer_SUITE.erl +++ b/test/quicer_SUITE.erl @@ -157,6 +157,7 @@ %% Toolings tc_malloc_trim/1, + tc_malloc_stats/1, %% Versions test tc_abi_version/1 @@ -229,6 +230,14 @@ end_per_group(_Groupname, _Config) -> %%%=================================================================== %%% Testcase specific setup/teardown %%%=================================================================== +init_per_testcase(TC, Config) when + TC =:= tc_malloc_trim orelse + TC =:= tc_malloc_stats +-> + case os:type() of + {unix, darwin} -> {skip, "Not runnable on MacOS"}; + _ -> Config + end; init_per_testcase(_TestCase, Config) -> quicer_test_lib:cleanup_msquic(), [{timetrap, 5000} | Config]. @@ -3199,6 +3208,9 @@ tc_setopt_congestion_control_algorithm(Config) -> tc_malloc_trim(_) -> quicer_nif:malloc_trim(). +tc_malloc_stats(_) -> + quicer_nif:malloc_stats(). + %%% ==================== %%% Internal helpers %%% ====================