anchor.diff:  -define(COUNTERS_MPS, ddb_counters_mps).
   
   
  --record(state, {n, w, prefix}).
  +-record(state, {n, w, prefix, ppf}).
   
   %%%===================================================================
   %%% API
  
positive.code: %%% Internal functions
  %%%===================================================================
  
  %do_metrics(CBin, Time, Specs, Acc) ->
  do_metrics(_Prefix, _CBin, _Time, [], Acc) ->
      Acc;
  
  do_metrics(Prefix, CBin, Time, [{N, [{type, histogram}]} | Spec], Acc) ->
      Stats = folsom_metrics:get_histogram_statistics(N),
      Prefix1 = [Prefix, metric_name(N)],
      Acc1 = build_histogram(Stats, Prefix1, Time, CBin, Acc),
      do_metrics(Prefix, CBin, Time, Spec, Acc1);
  
  do_metrics(Prefix, CBin, Time, [{N, [{type, spiral}]} | Spec], Acc) ->
      [{count, Count}, {one, One}] = folsom_metrics:get_metric_value(N),
      K = metric_name(N),
      Acc1 = add_metric(Prefix, CBin, [K, <<"count">>], Time, Count, Acc),
      Acc2 = add_metric(Prefix, CBin, [K, <<"one">>], Time, One, Acc1),
      do_metrics(Prefix, CBin, Time, Spec, Acc2);
  
  
  do_metrics(Prefix, CBin, Time, [{N, [{type, counter}]} | Spec], Acc) ->
      Count = folsom_metrics:get_metric_value(N),
      Acc1 = add_metric(Prefix, CBin, N, Time, Count, Acc),
      do_metrics(Prefix, CBin, Time, Spec, Acc1);
  
  do_metrics(Prefix, CBin, Time, [{N, [{type, duration}]} | Spec], Acc) ->
      Stats = folsom_metrics:get_metric_value(N),
      Prefix1 = [Prefix, metric_name(N)],
      Acc1 = build_histogram(Stats, Prefix1, Time, CBin, Acc),
      do_metrics(Prefix, CBin, Time, Spec, Acc1);
  
  
  do_metrics(Prefix, CBin, Time, [{N, [{type, meter}]} | Spec], Acc) ->
      Prefix1 = [Prefix, metric_name(N)],
      [{count, Count},
       {one, One},
  
negative.code: a2b(A) ->
      erlang:atom_to_binary(A, utf8).
  
  % build_histogram(Stats, Prefix, PPF, Time, CBin, Acc)
  build_histogram([], _, _, _, _, Acc) ->
      Acc;
  
  build_histogram([{min, V} | H], Prefix, PPF, Time, CBin, Acc) ->
      Acc1 = add_metric(Prefix, CBin, <<"min">>, PPF, Time, round(V), Acc),
      build_histogram(H, Prefix, PPF, Time, CBin, Acc1);
  
  build_histogram([{max, V} | H], Prefix, PPF, Time, CBin, Acc) ->
      Acc1 = add_metric(Prefix, CBin, <<"max">>, PPF, Time, round(V), Acc),
      build_histogram(H, Prefix, PPF, Time, CBin, Acc1);
  
  build_histogram([{arithmetic_mean, V} | H], Prefix, PPF, Time, CBin, Acc) ->
      Acc1 = add_metric(Prefix, CBin, <<"arithmetic_mean">>, PPF, Time, round(V), Acc),
      build_histogram(H, Prefix, PPF, Time, CBin, Acc1);
  
  build_histogram([{geometric_mean, V} | H], Prefix, PPF, Time, CBin, Acc) ->
      Acc1 = add_metric(Prefix, CBin, <<"geometric_mean">>, PPF, Time, round(V), Acc),
      build_histogram(H, Prefix, PPF, Time, CBin, Acc1);
  
  build_histogram([{harmonic_mean, V} | H], Prefix, PPF, Time, CBin, Acc) ->
      Acc1 = add_metric(Prefix, CBin, <<"harmonic_mean">>, PPF, Time, round(V), Acc),
      build_histogram(H, Prefix, PPF, Time, CBin, Acc1);
  
  build_histogram([{median, V} | H], Prefix, PPF, Time, CBin, Acc) ->
      Acc1 = add_metric(Prefix, CBin, <<"median">>, PPF, Time, round(V), Acc),
      build_histogram(H, Prefix, PPF, Time, CBin, Acc1);
  
  build_histogram([{variance, V} | H], Prefix, PPF, Time, CBin, Acc) ->
      Acc1 = add_metric(Prefix, CBin, <<"variance">>, PPF, Time, round(V), Acc),
      build_histogram(H, Prefix, PPF, Time, CBin, Acc1);
  
  build_histogram([{standard_deviation, V} | H], Prefix, PPF, Time, CBin, Acc) ->
      Acc1 = add_metric(Prefix, CBin, <<"standard_deviation">>, PPF, Time, round(V), Acc),
      build_histogram(H, Prefix, PPF, Time, CBin, Acc1);
  
  build_histogram([{skewness, V} | H], Prefix, PPF, Time, CBin, Acc) ->
      Acc1 = add_metric(Prefix, CBin, <<"skewness">>, PPF, Time, round(V), Acc),
      build_histogram(H, Prefix, PPF, Time, CBin, Acc1);
  
  build_histogram([{kurtosis, V} | H], Prefix, PPF, Time, CBin, Acc) ->
      Acc1 = add_metric(Prefix, CBin, <<"kurtosis">>, PPF, Time, round(V), Acc),
      build_histogram(H, Prefix, PPF, Time, CBin, Acc1);
  
  build_histogram([{percentile,
                    [{50, P50}, {75, P75}, {90, P90}, {95, P95}, {99, P99},
                     {999, P999}]} | H], Prefix, PPF, Time, CBin, Acc) ->
      Acc1 = add_metric(Prefix, CBin, <<"p50">>, PPF, Time, round(P50), Acc),
      Acc2 = add_metric(Prefix, CBin, <<"p75">>, PPF, Time, round(P75), Acc1),
      Acc3 = add_metric(Prefix, CBin, <<"p90">>, PPF, Time, round(P90), Acc2),
      Acc4 = add_metric(Prefix, CBin, <<"p95">>, PPF, Time, round(P95), Acc3),
      Acc5 = add_metric(Prefix, CBin, <<"p99">>, PPF, Time, round(P99), Acc4),
      Acc6 = add_metric(Prefix, CBin, <<"p999">>, PPF, Time, round(P999), Acc5),
      build_histogram(H, Prefix, PPF, Time, CBin, Acc6);
  
  build_histogram([{n, V} | H], Prefix, PPF, Time, CBin, Acc) ->
      Acc1 = add_metric(Prefix, CBin, <<"count">>, PPF, Time, V, Acc),
      build_histogram(H, Prefix, PPF, Time, CBin, Acc1);
  
  build_histogram([_ | H], Prefix, PPF, Time, CBin, Acc) ->
      build_histogram(H, Prefix, PPF, Time, CBin, Acc).
  