Fix handling of c_compiler_used when only a major version is provided
This mostly occurs when erlang is compiled under MSC since it only
provides a single number as the version. GCC can trigger this issue if it
does not have a minor version, but is probably rare in the wild.
Additionally, this allows for the case where erlang wasn't able to
determine which compiler was used (i.e. {undefined, undefined}).
Add test for the handling of c_compiler_used by convert_system_info
diff --git a/src/folsom_vm_metrics.erl b/src/folsom_vm_metrics.erl
index 9984c37..c5391af 100644
--- a/src/folsom_vm_metrics.erl
+++ b/src/folsom_vm_metrics.erl
@@ -132,7 +132,9 @@
convert_c_compiler_version({A, B, C}) ->
list_to_binary(io_lib:format("~p.~p.~p", [A, B, C]));
convert_c_compiler_version({A, B}) ->
- list_to_binary(io_lib:format("~p.~p", [A, B])).
+ list_to_binary(io_lib:format("~p.~p", [A, B]));
+convert_c_compiler_version(A) ->
+ list_to_binary(io_lib:format("~p", [A])).
convert_cpu_topology([{core, Value}| Tail], Acc) when is_tuple(Value) ->
convert_cpu_topology(Tail, lists:append(Acc, [{core, tuple_to_list(Value)}]));
diff --git a/test/folsom_erlang_checks.erl b/test/folsom_erlang_checks.erl
index 473fe7d..87462a1 100644
--- a/test/folsom_erlang_checks.erl
+++ b/test/folsom_erlang_checks.erl
@@ -33,7 +33,8 @@
delete_metrics/0,
vm_metrics/0,
counter_metric/2,
- cpu_topology/0
+ cpu_topology/0,
+ c_compiler_used/0
]).
-define(DATA, [0, 1, 5, 10, 100, 200, 500, 750, 1000, 2000, 5000]).
@@ -349,6 +350,19 @@
%?debugFmt("~p~n", [mochijson2:encode(Result)]).
mochijson2:encode(Result).
+c_compiler_used() ->
+ Test = [{gnuc, {4,4,5}},
+ {gnuc, {4,4}},
+ {msc, 1600}],
+
+ Expected = [[{compiler, gnuc}, {version, <<"4.4.5">>}],
+ [{compiler, gnuc}, {version, <<"4.4">>}],
+ [{compiler, msc}, {version, <<"1600">>}]],
+
+ ?assertEqual(Expected, [folsom_vm_metrics:convert_system_info({c_compiler_used, {Compiler, Version}})
+ || {Compiler, Version} <- Test]).
+
+
duration_check(Duration) ->
[?assert(lists:keymember(Key, 1, Duration)) || Key <-
[count, last, min, max, arithmetic_mean,
diff --git a/test/folsom_tests.erl b/test/folsom_tests.erl
index 296b57f..a003053 100644
--- a/test/folsom_tests.erl
+++ b/test/folsom_tests.erl
@@ -45,7 +45,9 @@
{"deleting metrics",
fun folsom_erlang_checks:delete_metrics/0},
{"cpu topology test",
- fun folsom_erlang_checks:cpu_topology/0}]}.
+ fun folsom_erlang_checks:cpu_topology/0},
+ {"c compiler test",
+ fun folsom_erlang_checks:c_compiler_used/0}]}.
configure_test_() ->
{foreach, fun setup_app/0, fun cleanup_app/1,