diff --git a/src/erlperf.erl b/src/erlperf.erl index b7e36b3..b1dc4a1 100644 --- a/src/erlperf.erl +++ b/src/erlperf.erl @@ -163,6 +163,10 @@ -type system_information() :: #{ os := {unix | win32, atom()}, system_version := string(), + debug => boolean(), %% true if the emulator has been debug-compiled, otherwise false + emu_type => atom(), %% see system_info(emu_type), since OTP 24 + emu_flavor => atom(), %% see system_info(emu_flavor), since OTP 24 + dynamic_trace => atom(),%% see system_info(dynamic_trace), since OTP 24 cpu => string() }. %% System information, as returned by {@link erlang:system_info/1} @@ -779,14 +783,21 @@ report_stats(Samples) -> system_report() -> OSType = erlang:system_info(os_type), - Guaranteed = #{ + Guaranteed = detect_feature([emu_type, emu_flavor, dynamic_trace], #{ os => OSType, system_version => string:trim(erlang:system_info(system_version), trailing) - }, + }), try Guaranteed#{cpu => string:trim(detect_cpu(OSType), both)} catch _:_ -> Guaranteed end. +detect_feature([], System) -> + System; +detect_feature([F | T], System) -> + try detect_feature(T, System#{F => erlang:system_info(F)}) + catch error:badarg -> detect_feature(T, System) + end. + detect_cpu({unix, freebsd}) -> os:cmd("sysctl -n hw.model"); detect_cpu({unix, darwin}) -> diff --git a/src/erlperf_cli.erl b/src/erlperf_cli.erl index 06aac69..18587db 100644 --- a/src/erlperf_cli.erl +++ b/src/erlperf_cli.erl @@ -372,23 +372,23 @@ color(info, Text) -> Text. %% Report formatter format_report(full, [#{system := System} | _] = Reports, Width) -> - [format_system(System), format_report(extended, Reports, Width)]; + warn_system(System) ++ [format_system(System), format_report(extended, Reports, Width)]; -format_report(extended, Reports, Width) -> +format_report(extended, [#{system := System} | _] = Reports, Width) -> Sorted = sort_by(Reports), #{result := #{average := MaxAvg}} = hd(Sorted), Header = ["Code", " ||", " Samples", " Avg", " StdDev", " Median", " P99", " Iteration", " Rel"], Data = [format_report_line(MaxAvg, ReportLine, extended) || ReportLine <- Sorted], - format_table(remove_relative_column([Header | Data]), Width); + warn_system(System) ++ format_table(remove_relative_column([Header | Data]), Width); -format_report(basic, Reports, Width) -> +format_report(basic, [#{system := System} | _] = Reports, Width) -> Sorted = sort_by(Reports), #{result := #{average := MaxAvg}} = hd(Sorted), Header = ["Code", " ||", " QPS", " Time", " Rel"], Data0 = [format_report_line(MaxAvg, ReportLine, basic) || ReportLine <- Sorted], %% remove columns that should not be displayed in basic mode Data = [[C1, C2, C3, C4, C5] || [C1, C2, _, C3, _, _, _, C4, C5] <- Data0], - format_table(remove_relative_column([Header | Data]), Width). + warn_system(System) ++ format_table(remove_relative_column([Header | Data]), Width). sort_by([#{mode := timed} | _] = Reports) -> lists:sort(fun (#{result := #{average := L}}, #{result := #{average := R}}) -> L < R end, Reports); @@ -461,6 +461,15 @@ format_code(Code) when is_list(Code) -> format_code(Code) when is_binary(Code) -> binary_to_list(Code). +warn_system(#{dynamic_trace := Trace} = System) when Trace =/= none -> + [io_lib:format("WARNING: Dynamic Trace Probes enabled (~s detected)~n", [Trace]) | warn_system(maps:remove(dynamic_trace, System))]; +warn_system(#{emu_type := Type} = System) when Type =/= opt -> + [io_lib:format("WARNING: Emulator is not optimised (~s detected)~n", [Type]) | warn_system(maps:remove(emu_type, System))]; +warn_system(#{emu_flavor := Flavor} = System) when Flavor =/= jit -> + [io_lib:format("WARNING: Emulator is not JIT (~s detected)~n", [Flavor]) | warn_system(maps:remove(emu_flavor, System))]; +warn_system(_) -> + []. + format_system(#{os := OSType, system_version := SystemVsn} = System) -> OS = io_lib:format("OS : ~s~n", [format_os(OSType)]), CPU = if is_map_key(cpu, System) -> io_lib:format("CPU: ~s~n", [maps:get(cpu, System)]); true -> "" end,