QoS: split off distributions to a separate file 12/240812/2
authorMichal Bloch <m.bloch@samsung.com>
Tue, 11 Aug 2020 12:59:11 +0000 (14:59 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 12 Aug 2020 10:29:39 +0000 (12:29 +0200)
Change-Id: I2f708535940b355e6396eb28b5523752ce8c8872
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
Makefile.am
src/logger/logger.c
src/logger/logger_internal.h
src/logger/qos.c [new file with mode: 0644]
src/logger/qos.h [new file with mode: 0644]

index 5c5a2f7..4747440 100644 (file)
@@ -126,6 +126,7 @@ dlog_logger_SOURCES = \
        external/sd-daemon/sd-daemon.c \
        src/logger/logger.c \
        src/logger/log_storage.c \
+       src/logger/qos.c \
        src/shared/backend_androidlogger.c \
        src/shared/ptrs_list.c \
        src/shared/logcommon.c \
index 170c12a..7baf0ab 100644 (file)
@@ -622,31 +622,6 @@ bool qos_is_enabled(const struct qos_module *qos)
        return qos->threshold > 0 && qos->max_throughput > 0 && qos->file_path && strlen(qos->file_path) > 0;
 }
 
-struct metrics_pid_aggr_info {
-       pid_t pid;
-       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, 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)
-               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)
-{
-       /* 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)
-               infos[i].count = equal_limit_for_everybody;
-}
-
 void qos_create_limits_file(struct qos_module *qos, bool is_limiting)
 {
        __attribute__((cleanup(close_fd))) int fd = creat(qos->file_path, 0644);
index 040bbd4..52b40fd 100644 (file)
@@ -29,6 +29,7 @@
 #include <backend_androidlogger.h>
 #include <queued_entry_timestamp.h>
 #include <dlogutil-internal.h>
+#include "qos.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -99,17 +100,6 @@ struct fd_entity {
        int fd;
 };
 
-struct qos_module {
-       struct metrics *log_metrics;
-       char *file_path;
-       int max_throughput;
-       int threshold;
-       int threshold_reapply;
-       int limit_duration;
-       struct timespec cancel_limits_at;
-       bool currently_limiting;
-};
-
 /**
  * @brief Service a writer
  * @details Specific handler that event is delegated to, according to writers type
diff --git a/src/logger/qos.c b/src/logger/qos.c
new file mode 100644 (file)
index 0000000..6eb7331
--- /dev/null
@@ -0,0 +1,36 @@
+/* Copyright (c) 2020, Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. */
+
+#include "qos.h"
+
+void (*qos_distribution_func)(struct qos_module *qos, 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)
+               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)
+{
+       /* 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)
+               infos[i].count = equal_limit_for_everybody;
+}
+
diff --git a/src/logger/qos.h b/src/logger/qos.h
new file mode 100644 (file)
index 0000000..70ea9da
--- /dev/null
@@ -0,0 +1,43 @@
+#pragma once
+
+/* Copyright (c) 2020, Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. */
+
+// C
+#include <time.h>
+
+// DLog
+#include <metrics.h>
+
+struct metrics_pid_aggr_info {
+       pid_t pid;
+       int count;
+};
+
+struct qos_module {
+       struct metrics *log_metrics;
+       char *file_path;
+       int max_throughput;
+       int threshold;
+       int threshold_reapply;
+       int limit_duration;
+       struct timespec cancel_limits_at;
+       bool currently_limiting;
+};
+
+extern void (*qos_distribution_func)(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count);
+
+void qos_distribution_equal(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count);
+void qos_distribution_proportional(struct qos_module *qos, struct metrics_pid_aggr_info *infos, int count);
+