From 276b5c4ce8738a8bbd1b96a146114acbec5f1d60 Mon Sep 17 00:00:00 2001 From: Lukasz Stanislawski Date: Wed, 25 Jul 2018 15:03:24 +0200 Subject: remove unsued code after refactor Change-Id: I8d08ab69d195bbee5aea8abd915b9342fa0fda8b --- src/CMakeLists.txt | 3 +- src/appinfo-provider.h | 1 - src/generators/report-generator.c | 42 +++++++ src/generators/report-generator.h | 74 ++++++++++++ src/report-generator.c | 42 ------- src/report-generator.h | 77 ------------ src/report-json-serializer.c | 246 -------------------------------------- src/report-json-serializer.h | 102 ---------------- src/report.h | 68 ----------- src/task-factory.c | 1 - 10 files changed, 117 insertions(+), 539 deletions(-) create mode 100644 src/generators/report-generator.c create mode 100644 src/generators/report-generator.h delete mode 100644 src/report-generator.c delete mode 100644 src/report-generator.h delete mode 100644 src/report-json-serializer.c delete mode 100644 src/report-json-serializer.h delete mode 100644 src/report.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eabedc8..f73c325 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,19 +18,18 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") SET(SRCS task-worker.c procfs.c - report-generator.c worker.c task-factory.c task.c scheduler.c config-deserializer.c appinfo-provider.c - report-json-serializer.c sys-stats.c clock.c ipc.c process.c proc-scanner.c + generators/report-generator.c generators/report-generator-system.c generators/report-generator-load-avg.c generators/report-generator-process.c diff --git a/src/appinfo-provider.h b/src/appinfo-provider.h index ac1c0be..8eef00a 100644 --- a/src/appinfo-provider.h +++ b/src/appinfo-provider.h @@ -17,7 +17,6 @@ #ifndef __APPINFO_PROVIDER_H_ #define __APPINFO_PROVIDER_H_ -#include "report.h" #include /** diff --git a/src/generators/report-generator.c b/src/generators/report-generator.c new file mode 100644 index 0000000..5f28560 --- /dev/null +++ b/src/generators/report-generator.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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 "report-generator.h" +#include "err-check.h" + + +bool report_generator_refresh(report_generator_t *generator) +{ + ON_NULL_RETURN_VAL(generator, false); + + if (generator->refresh) + return generator->refresh(generator); + return true; +} + +void report_generator_generate(report_generator_t *generator, JsonBuilder *builder) +{ + ON_NULL_RETURN(generator); + ON_NULL_RETURN(builder); + + if (generator->generate) generator->generate(generator, builder); +} + +void report_generator_release(report_generator_t *generator) +{ + if (!generator) return; + if (generator->release) generator->release(generator); +} diff --git a/src/generators/report-generator.h b/src/generators/report-generator.h new file mode 100644 index 0000000..b7504dd --- /dev/null +++ b/src/generators/report-generator.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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. + */ + +#ifndef __REPORT_GENERATOR_H_ +#define __REPORT_GENERATOR_H_ + +#include +#include + +typedef struct report_generator report_generator_t; + +/** + * @brief Called by @report_generator_refresh + */ +typedef bool (*report_generator_refresh_cb)(report_generator_t *generator); + +/** + * @brief Called by @report_generator_generate + */ +typedef void (*report_generator_generate_cb)(report_generator_t *generator, JsonBuilder *builder); + +/** + * @brief Called by @report_generator_release + */ +typedef void (*report_generator_release_cb)(report_generator_t *generator); + +/** + * @brief Report generator base. + */ +struct report_generator +{ + report_generator_refresh_cb refresh; + report_generator_generate_cb generate; + report_generator_release_cb release; +}; + +/** + * @brief Refresh report data. + * + * @param[in] generator report generator + * + * @return true on success, false otherwise. + */ +bool report_generator_refresh(report_generator_t *generator); + +/** + * @brief Refresh report as json. + * + * @param[in] generator report generator + * @param[in] builder the build to which report will be appended to. + */ +void report_generator_generate(report_generator_t *generator, JsonBuilder *builder); + +/** + * @brief Release report generator. + * + * @param[in] generator report generator + */ +void report_generator_release(report_generator_t *generator); + +#endif diff --git a/src/report-generator.c b/src/report-generator.c deleted file mode 100644 index 5f28560..0000000 --- a/src/report-generator.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * 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 "report-generator.h" -#include "err-check.h" - - -bool report_generator_refresh(report_generator_t *generator) -{ - ON_NULL_RETURN_VAL(generator, false); - - if (generator->refresh) - return generator->refresh(generator); - return true; -} - -void report_generator_generate(report_generator_t *generator, JsonBuilder *builder) -{ - ON_NULL_RETURN(generator); - ON_NULL_RETURN(builder); - - if (generator->generate) generator->generate(generator, builder); -} - -void report_generator_release(report_generator_t *generator) -{ - if (!generator) return; - if (generator->release) generator->release(generator); -} diff --git a/src/report-generator.h b/src/report-generator.h deleted file mode 100644 index 6cf6c22..0000000 --- a/src/report-generator.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * 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. - */ - -#ifndef __REPORT_GENERATOR_H_ -#define __REPORT_GENERATOR_H_ - -#include -#include - -#include "process.h" -#include "report.h" - -typedef struct report_generator report_generator_t; - -/** - * @brief Called by @report_generator_refresh - */ -typedef bool (*report_generator_refresh_cb)(report_generator_t *generator); - -/** - * @brief Called by @report_generator_generate - */ -typedef void (*report_generator_generate_cb)(report_generator_t *generator, JsonBuilder *builder); - -/** - * @brief Called by @report_generator_release - */ -typedef void (*report_generator_release_cb)(report_generator_t *generator); - -/** - * @brief Report generator base. - */ -struct report_generator -{ - report_generator_refresh_cb refresh; - report_generator_generate_cb generate; - report_generator_release_cb release; -}; - -/** - * @brief Refresh report data. - * - * @param[in] generator report generator - * - * @return true on success, false otherwise. - */ -bool report_generator_refresh(report_generator_t *generator); - -/** - * @brief Refresh report as json. - * - * @param[in] generator report generator - * @param[in] builder the build to which report will be appended to. - */ -void report_generator_generate(report_generator_t *generator, JsonBuilder *builder); - -/** - * @brief Release report generator. - * - * @param[in] generator report generator - */ -void report_generator_release(report_generator_t *generator); - -#endif diff --git a/src/report-json-serializer.c b/src/report-json-serializer.c deleted file mode 100644 index 949d82c..0000000 --- a/src/report-json-serializer.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * 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 - -#include "report-json-serializer.h" -#include "json-schema-defs.h" - -static char *_serialize(JsonBuilder *builder) -{ - JsonGenerator *gen = json_generator_new(); - if (!gen) { - g_object_unref(builder); - return NULL; - } - - JsonNode *root = json_builder_get_root(builder); - json_generator_set_root(gen, root); - char *str = json_generator_to_data(gen, NULL); - g_object_unref(gen); - return str; -} - -#define IMPLEMENT_SERIALIZER_FUNC(func_name, param_type, serializer) \ -char* \ -func_name(param_type *report) \ -{\ - JsonBuilder *builder = json_builder_new(); \ - if (!builder) return NULL; \ - serializer(builder, report); \ - char *ret = _serialize(builder); \ - g_object_unref(builder); \ - return ret; \ -} - -#define IMPLEMENT_ARRAY_SERIALIZER_FUNC(func_name, param_type, serializer) \ -char* \ -func_name(param_type *reports, int len) \ -{\ - JsonBuilder *builder = json_builder_new(); \ - if (!builder) return NULL; \ - serializer(builder, reports, len); \ - char *ret = _serialize(builder); \ - g_object_unref(builder); \ - return ret; \ -} - -static void system_load_average_report_to_json_object(JsonBuilder *builder, struct system_load_average_report *report) -{ - json_builder_begin_object(builder); - - json_builder_set_member_name(builder, SCHEMA_TYPE); - json_builder_add_string_value(builder, SCHEMA_TYPE_LOAD_AVG); - - json_builder_set_member_name(builder, SCHEMA_RESULT_DATA_LOAD_AVG); - json_builder_begin_object(builder); - - json_builder_set_member_name(builder, SCHEMA_RESULT_TIME); - json_builder_add_int_value(builder, report->time); - json_builder_set_member_name(builder, SCHEMA_RESULT_AVG_ONE); - json_builder_add_double_value(builder, report->one_min_avg); - json_builder_set_member_name(builder, SCHEMA_RESULT_AVG_FIVE); - json_builder_add_double_value(builder, report->five_min_avg); - json_builder_set_member_name(builder, SCHEMA_RESULT_AVG_FIFTEEN); - json_builder_add_double_value(builder, report->fifteen_min_avg); - - json_builder_end_object(builder); - - json_builder_end_object(builder); -} - -static void system_report_to_json_object(JsonBuilder *builder, struct system_report *report) -{ - json_builder_begin_object(builder); - - json_builder_set_member_name(builder, SCHEMA_TYPE); - json_builder_add_string_value(builder, SCHEMA_TYPE_SYSTEM); - - json_builder_set_member_name(builder, SCHEMA_RESULT_DATA_SYSTEM); - json_builder_begin_object(builder); - - json_builder_set_member_name(builder, SCHEMA_RESULT_TIME); - json_builder_add_int_value(builder, report->time); - - json_builder_set_member_name(builder, SCHEMA_RESULT_CPU); - json_builder_add_double_value(builder, report->cpu); - - json_builder_set_member_name(builder, SCHEMA_RESULT_MEMORY); - json_builder_add_double_value(builder, report->memory); - - json_builder_end_object(builder); - - json_builder_end_object(builder); -} - -static void top_cpu_usage_reports_to_json_object(JsonBuilder *builder, struct process_usage_report *reports, int len) -{ - json_builder_begin_object(builder); - - json_builder_set_member_name(builder, SCHEMA_TYPE); - json_builder_add_string_value(builder, SCHEMA_TYPE_TOP); - - json_builder_set_member_name(builder, SCHEMA_TARGET); - json_builder_add_string_value(builder, SCHEMA_TARGET_CPU); - - json_builder_set_member_name(builder, SCHEMA_RESULT_DATA_TOP); - json_builder_begin_array(builder); - - for (int i = 0; i < len; ++i) - { - json_builder_begin_object(builder); - - json_builder_set_member_name(builder, SCHEMA_ID); - json_builder_add_string_value(builder, reports[i].app_id); - - json_builder_set_member_name(builder, SCHEMA_RESULT_PID); - json_builder_add_int_value(builder, reports[i].pid); - - json_builder_set_member_name(builder, SCHEMA_RESULT_RESULT); - json_builder_begin_object(builder); - - json_builder_set_member_name(builder, SCHEMA_RESULT_TIME); - json_builder_add_int_value(builder, reports[i].time); - json_builder_set_member_name(builder, SCHEMA_RESULT_USAGE); - json_builder_add_double_value(builder, reports[i].usage); - - json_builder_end_object(builder); - - json_builder_end_object(builder); - } - - json_builder_end_array(builder); - json_builder_end_object(builder); -} - -static void top_memory_usage_reports_to_json_object(JsonBuilder *builder, struct process_usage_report *reports, int len) -{ - json_builder_begin_object(builder); - - json_builder_set_member_name(builder, SCHEMA_TYPE); - json_builder_add_string_value(builder, SCHEMA_TYPE_TOP); - - json_builder_set_member_name(builder, SCHEMA_TARGET); - json_builder_add_string_value(builder, SCHEMA_TARGET_MEMORY); - - json_builder_set_member_name(builder, SCHEMA_RESULT_DATA_TOP); - json_builder_begin_array(builder); - - for (int i = 0; i < len; ++i) - { - json_builder_begin_object(builder); - - json_builder_set_member_name(builder, SCHEMA_ID); - json_builder_add_string_value(builder, reports[i].app_id); - - json_builder_set_member_name(builder, SCHEMA_RESULT_PID); - json_builder_add_int_value(builder, reports[i].pid); - - json_builder_set_member_name(builder, SCHEMA_RESULT_RESULT); - json_builder_begin_object(builder); - - json_builder_set_member_name(builder, SCHEMA_RESULT_TIME); - json_builder_add_int_value(builder, reports[i].time); - json_builder_set_member_name(builder, SCHEMA_RESULT_USAGE); - json_builder_add_double_value(builder, reports[i].usage); - - json_builder_end_object(builder); - - json_builder_end_object(builder); - } - - json_builder_end_array(builder); - json_builder_end_object(builder); -} - -static void process_report_to_json_object(JsonBuilder *builder, struct process_report *report) -{ - json_builder_begin_object(builder); - - json_builder_set_member_name(builder, SCHEMA_TYPE); - json_builder_add_string_value(builder, SCHEMA_TYPE_PROCESS); - - json_builder_set_member_name(builder, SCHEMA_RESULT_TIME); - json_builder_add_int_value(builder, report->time); - - json_builder_set_member_name(builder, SCHEMA_RESULT_DATA_PROCESS); - json_builder_begin_array(builder); - - for (int i = 0; i < report->n_processes; ++i) { - json_builder_begin_object(builder); - json_builder_set_member_name(builder, SCHEMA_RESULT_APP_ID); - json_builder_add_string_value(builder, report->processes[i].app_id); - json_builder_set_member_name(builder, SCHEMA_RESULT_EXE); - json_builder_add_string_value(builder, report->processes[i].exe); - json_builder_set_member_name(builder, SCHEMA_RESULT_PID); - json_builder_add_int_value(builder, report->processes[i].pid); - json_builder_set_member_name(builder, SCHEMA_RESULT_CPU); - json_builder_add_double_value(builder, report->processes[i].cpu); - json_builder_set_member_name(builder, SCHEMA_RESULT_MEMORY); - json_builder_add_double_value(builder, report->processes[i].memory); - json_builder_end_object(builder); - } - json_builder_end_array(builder); - - json_builder_end_object(builder); // end data process - json_builder_end_object(builder); // end report -} - -IMPLEMENT_SERIALIZER_FUNC( - report_json_serializer_serialize_system_load_average_report, - struct system_load_average_report, - system_load_average_report_to_json_object); - -IMPLEMENT_SERIALIZER_FUNC( - report_json_serializer_serialize_system_report, - struct system_report, - system_report_to_json_object) - -IMPLEMENT_SERIALIZER_FUNC( - report_json_serializer_serialize_process_report, - struct process_report, - process_report_to_json_object) - -IMPLEMENT_ARRAY_SERIALIZER_FUNC( - report_json_serializer_serialize_top_cpu_usage_reports, - struct process_usage_report, - top_cpu_usage_reports_to_json_object) - -IMPLEMENT_ARRAY_SERIALIZER_FUNC( - report_json_serializer_serialize_top_memory_usage_reports, - struct process_usage_report, - top_memory_usage_reports_to_json_object) - diff --git a/src/report-json-serializer.h b/src/report-json-serializer.h deleted file mode 100644 index b236c8a..0000000 --- a/src/report-json-serializer.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * 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. - */ - -#ifndef __REPORT_JSON_SERIALIZER_H_ -#define __REPORT_JSON_SERIALIZER_H_ - -#include "report.h" - -/** - * @brief Serializes system_load_average_report to json string - * - * @param[in] report Report structure with usage data. - * - * @return dynamically allocated string on NULL on error. - * @remark returned value should be released with @free - */ -char *report_json_serializer_serialize_system_load_average_report(struct system_load_average_report *report); - -/** - * @brief Serializes system_report to json string - * - * @param[in] report Report structure with usage data. - * - * @return dynamically allocated string on NULL on error. - * @remark returned value should be released with @free - */ -char *report_json_serializer_serialize_system_report(struct system_report *report); - -/** - * @brief Serializes process_report to json string - * - * @param[in] report Report structure with usage data. - * - * @return dynamically allocated string on NULL on error. - * @remark returned value should be released with @free - */ -char *report_json_serializer_serialize_process_report(struct process_report *report); - -/** - * @brief Serializes process_usage_report to json string - * - * @param[in] report Report structure with usage data. - * - * @return dynamically allocated string on NULL on error. - * @remark returned value should be released with @free - */ -char *report_json_serializer_serialize_process_memory_usage_report(struct process_usage_report *report); - -/** - * @brief Serializes app_system_cpu_usage_report to json string - * - * @param[in] report Report structure with usage data. - * - * @return dynamically allocated string on NULL on error. - * @remark returned value should be released with @free - */ -char *report_json_serializer_serialize_apps_cpu_usage_report(struct process_usage_report *report); - -/** - * @brief Serializes process_usage_report to json string - * - * @param[in] report Report structure with usage data. - * - * @return dynamically allocated string on NULL on error. - * @remark returned value should be released with @free - */ -char *report_json_serializer_serialize_apps_memory_usage_report(struct process_usage_report *report); - -/** - * @brief Serializes app_system_cpu_usage_reports to json string - * - * @param[in] report NULL-terminated array of report structures with usage data. - * - * @return dynamically allocated string on NULL on error. - * @remark returned value should be released with @free - */ -char *report_json_serializer_serialize_top_cpu_usage_reports(struct process_usage_report *reports, int len); - -/** - * @brief Serializes app_memory_usage_reports to json string - * - * @param[in] report NULL-terminated array of report structures with usage data. - * - * @return dynamically allocated string on NULL on error. - * @remark returned value should be released with @free - */ -char *report_json_serializer_serialize_top_memory_usage_reports(struct process_usage_report *reports, int len); - -#endif diff --git a/src/report.h b/src/report.h deleted file mode 100644 index dc717c4..0000000 --- a/src/report.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * 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. - */ - -#ifndef __REPORT_H_ -#define __REPORT_H_ - -#include - -#define APP_ID_MAX_SIZE 256 - -/** - * @brief Load average report - */ -struct system_load_average_report { - time_t time; /** Number of seconds after the Epoch */ - float one_min_avg; /** One minute load averate */ - float five_min_avg; /** Five minutes load average */ - float fifteen_min_avg; /** Fifteen minutes load average */ -}; - -/** - * @brief System report - */ -struct system_report { - time_t time; /** Number of seconds after the Epoch */ - float cpu; /** CPU utilization (Percent) */ - float memory; /** Memory utilization (Percent) */ -}; - -/** - * @brief Process usage report. - */ -struct process_usage_report { - time_t time; /** Number of seconds after the Epoch */ - int pid; /** Process Pid */ - float usage; /** CPU utilization of process (Percent) */ - char app_id[APP_ID_MAX_SIZE]; -}; - -struct process_info { - const char *app_id; - const char *exe; - int pid; - float cpu; /** CPU utilization (Percent) */ - float memory; /** Memory utilization (Percent) */ -}; - -struct process_report { - time_t time; /** Number of seconds after the Epoch */ - struct process_info *processes; - int n_processes; -}; - -#endif - diff --git a/src/task-factory.c b/src/task-factory.c index 9924c27..194e3a4 100644 --- a/src/task-factory.c +++ b/src/task-factory.c @@ -23,7 +23,6 @@ #include "report-generator-load-avg.h" #include "report-generator-process.h" #include "report-generator-top.h" -#include "report-json-serializer.h" #include "log.h" #include "err-check.h" #include "macros.h" -- cgit v1.2.3