QoS: move file handling out of distribution funcs 11/240811/2
authorMichal Bloch <m.bloch@samsung.com>
Tue, 11 Aug 2020 12:16:30 +0000 (14:16 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 12 Aug 2020 10:29:39 +0000 (12:29 +0200)
Will allow easier testing for the functions.

Change-Id: Idacc1b8863eb76d87b4b58f8824ce8bcf53cf808
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/logger/logger.c

index 0724e59..170c12a 100644 (file)
@@ -627,28 +627,24 @@ struct metrics_pid_aggr_info {
        int count;
 };
 
-void (*qos_distribution_func)(struct qos_module *qos, int fd, struct metrics_pid_aggr_info *infos, int count);
+void (*qos_distribution_func)(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count);
 
-void qos_distribution_proportional(struct qos_module *qos, int fd, struct metrics_pid_aggr_info *infos, int count)
+void qos_distribution_proportional(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);
 
-       for (int i = 0; i < count; ++i) {
-               struct metrics_pid_aggr_info *const single_info = infos + i;
-               dprintf(fd, "pidlimit|%d=%d\n", single_info->pid, (int) (single_info->count * proportion + 0.5));
-       }
+       for (int i = 0; i < count; ++i)
+               infos[i].count = (int) (infos[i].count * proportion + 0.5);
 }
 
-void qos_distribution_equal(struct qos_module *qos, int fd, struct metrics_pid_aggr_info *infos, int count)
+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) */
        const int equal_limit_for_everybody = (qos->max_throughput + (count - 1)) / count;
 
-       for (int i = 0; i < count; ++i) {
-               struct metrics_pid_aggr_info *const single_info = infos + i;
-               dprintf(fd, "pidlimit|%d=%d\n", single_info->pid, equal_limit_for_everybody);
-       }
+       for (int i = 0; i < count; ++i)
+               infos[i].count = equal_limit_for_everybody;
 }
 
 void qos_create_limits_file(struct qos_module *qos, bool is_limiting)
@@ -685,7 +681,10 @@ void qos_create_limits_file(struct qos_module *qos, bool is_limiting)
                }
        }
 
-       qos_distribution_func(qos, fd, aggr_infos, aggr_count);
+       qos_distribution_func(qos, aggr_infos, aggr_count);
+       for (int i = 0; i < aggr_count; ++i)
+               if (aggr_infos[i].count >= 0)
+                       dprintf(fd, "pidlimit|%d=%d\n", aggr_infos[i].pid, aggr_infos[i].count);
 }
 
 void qos_set_next_update_time(struct qos_module *qos, struct timespec now)
@@ -2715,7 +2714,7 @@ int prepare_config_data(struct logger_config_data *data)
        data->qos_threshold_reapply = log_config_get_int(&conf, "qos_threshold_reapply_logs", DEFAULT_QOS_THRESHOLD_REAPPLY_LOGS);
 
        struct {
-               void (*func)(struct qos_module *qos, int fd, struct metrics_pid_aggr_info *infos, int count);
+               void (*func)(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count);
                const char *name;
        } const qos_methods[] = {
                { qos_distribution_proportional, "proportional" },