dlog_logger: refactor QoS distributions
[platform/core/system/dlog.git] / src / logger / qos_distributions.c
index 2fe499f..60813a1 100644 (file)
@@ -1,5 +1,7 @@
 #include "qos.h"
 
+#include <logcommon.h>
+
 #include <assert.h>
 #include <stdlib.h>
 
@@ -17,7 +19,7 @@ static inline int sort_by_count(const void *vlhs, const void *vrhs)
        return lhs->count - rhs->count;
 }
 
-void qos_distribution_proportional_raw(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
+static void qos_distribution_proportional_raw(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
 {
        const double proportion = (double) qos->max_throughput / (metrics_get_total(qos->log_metrics) ?: 1);
 
@@ -25,7 +27,7 @@ void qos_distribution_proportional_raw(struct qos_module *qos, struct metrics_pi
                infos[i].count = (int) (infos[i].count * proportion + 0.5);
 }
 
-void qos_distribution_equal(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
+static void qos_distribution_equal(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
 {
        /* round upwards so that it's never 0, to give all clients a chance
         * to log at least something (so a developer can tell it's alive) */
@@ -36,7 +38,7 @@ void qos_distribution_equal(struct qos_module *qos, struct metrics_pid_aggr_info
 }
 
 
-void qos_distribution_equal_dual(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
+static void qos_distribution_equal_dual(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
 {
        /* Anything below the "equal" threshold is unlimited.
         * The ones above this limit get leftovers distributed
@@ -62,7 +64,7 @@ void qos_distribution_equal_dual(struct qos_module *qos, struct metrics_pid_aggr
                        infos[i].count = -1;
 }
 
-void qos_distribution_equal_multi(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
+static void qos_distribution_equal_multi(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
 {
        /* Similar to 'dual', except anything not reaching the higher
         * threshold also gets an unlimited pass (which increases the
@@ -97,7 +99,7 @@ void qos_distribution_equal_multi(struct qos_module *qos, struct metrics_pid_agg
                        infos[i].count = -1;
 }
 
-void qos_distribution_proportional_talmud(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
+static void qos_distribution_proportional_talmud(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count)
 {
        /* As proscribed by the talmudic contested garment rule.
         * Probably makes little sense given how our QoS works but
@@ -138,3 +140,26 @@ void qos_distribution_proportional_talmud(struct qos_module *qos, struct metrics
                infos[i].count =  upper_half ? infos[i].count - final_level : final_level;
 }
 
+qos_distribution_func qos_get_distribution_func_by_name(const char *name)
+{
+       if (!name)
+               return qos_distribution_equal_multi;
+
+       static struct {
+               void (*func)(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count);
+               const char *name;
+       } qos_methods[] = {
+               { qos_distribution_proportional_raw   , "proportional_raw"    },
+               { qos_distribution_proportional_talmud, "proportional_talmud" },
+               { qos_distribution_equal              , "equal"               },
+               { qos_distribution_equal_dual         , "equal_dual"          },
+               { qos_distribution_equal_multi        , "equal_multi"         },
+       };
+
+       for (int i = 0; i < NELEMS(qos_methods); ++i)
+               if (!strcmp(name, qos_methods[i].name))
+                       return qos_methods[i].func;
+
+       return qos_distribution_equal_multi;
+}
+