diff options
author | Lukasz Stanislawski <l.stanislaws@samsung.com> | 2018-07-25 12:29:52 +0200 |
---|---|---|
committer | Lukasz Stanislawski <l.stanislaws@samsung.com> | 2018-07-25 12:29:52 +0200 |
commit | 878be323b38c9b1c598480b375e0e6b962fb200a (patch) | |
tree | e77569eef726fd7057820356903e3dd381ce27fd /src | |
parent | 953840fae0a31065908253ed9d4ee6ea21e4f7be (diff) | |
download | ttsd-worker-task-878be323b38c9b1c598480b375e0e6b962fb200a.tar.gz ttsd-worker-task-878be323b38c9b1c598480b375e0e6b962fb200a.tar.bz2 ttsd-worker-task-878be323b38c9b1c598480b375e0e6b962fb200a.zip |
report-generator: move system_generator to separate file
Change-Id: If06549372f095047fe52395667e9dc249970338e
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/generators/report-generator-load-avg.c | 0 | ||||
-rw-r--r-- | src/generators/report-generator-load-avg.h | 0 | ||||
-rw-r--r-- | src/generators/report-generator-process.c | 0 | ||||
-rw-r--r-- | src/generators/report-generator-process.h | 0 | ||||
-rw-r--r-- | src/generators/report-generator-system.c | 103 | ||||
-rw-r--r-- | src/generators/report-generator-system.h | 32 | ||||
-rw-r--r-- | src/generators/report-generator-top.c | 0 | ||||
-rw-r--r-- | src/generators/report-generator-top.h | 0 | ||||
-rw-r--r-- | src/report-generator.c | 75 | ||||
-rw-r--r-- | src/report-generator.h | 12 | ||||
-rw-r--r-- | src/task-factory.c | 3 |
12 files changed, 138 insertions, 88 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dfbd9e3..9867bdf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,6 +31,7 @@ SET(SRCS ipc.c process.c proc-scanner.c + generators/report-generator-system.c ) ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) diff --git a/src/generators/report-generator-load-avg.c b/src/generators/report-generator-load-avg.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/generators/report-generator-load-avg.c diff --git a/src/generators/report-generator-load-avg.h b/src/generators/report-generator-load-avg.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/generators/report-generator-load-avg.h diff --git a/src/generators/report-generator-process.c b/src/generators/report-generator-process.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/generators/report-generator-process.c diff --git a/src/generators/report-generator-process.h b/src/generators/report-generator-process.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/generators/report-generator-process.h diff --git a/src/generators/report-generator-system.c b/src/generators/report-generator-system.c new file mode 100644 index 0000000..6ce98e1 --- /dev/null +++ b/src/generators/report-generator-system.c @@ -0,0 +1,103 @@ +/* + * 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 <stdlib.h> + +#include "report-generator-system.h" +#include "log.h" +#include "report-generator.h" +#include "err-check.h" +#include "sys-stats.h" +#include "clock.h" +#include "json-schema-defs.h" +#include "macros.h" + +static void report_generator_release_system_generator(report_generator_t *generator); +static bool report_generator_refresh_system_generator(report_generator_t *generator); +static void report_generator_generate_system_report(report_generator_t *generator, JsonBuilder *builder); + +struct report_generator_system { + /** generator base - should be first */ + struct report_generator base; + /** system cpu usage statistics */ + struct sys_stats stats; + time_t update_time; +}; + +report_generator_system_t *report_generator_system_new_generator() +{ + report_generator_system_t *ret = calloc(1, sizeof(struct report_generator_system)); + if (!ret) + return NULL; + + ret->base.refresh = report_generator_refresh_system_generator; + ret->base.generate = report_generator_generate_system_report; + ret->base.release = report_generator_release_system_generator; + + if (report_generator_refresh((report_generator_t*)ret) != true) { + free(ret); + return NULL; + } + + return ret; +} + +static void report_generator_release_system_generator(report_generator_t *generator) +{ + report_generator_system_t *gen = container_of(generator, report_generator_system_t, base); + free(gen); +} + +static bool report_generator_refresh_system_generator( + report_generator_t *generator) +{ + report_generator_system_t *sys_gen = container_of(generator, report_generator_system_t, base); + + if (sys_stats_update(&sys_gen->stats) != 0) { + ERR("stats_update_system_stats failed."); + return false; + } + sys_gen->update_time = clock_realtime_get(); + return true; +} + +static void report_generator_generate_system_report( + report_generator_t *generator, + JsonBuilder *builder) +{ + report_generator_system_t *gen = container_of(generator, report_generator_system_t, base); + + 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, gen->update_time); + + json_builder_set_member_name(builder, SCHEMA_RESULT_CPU); + json_builder_add_double_value(builder, sys_stats_get_cpu_usage_percentage(&gen->stats)); + + json_builder_set_member_name(builder, SCHEMA_RESULT_MEMORY); + json_builder_add_double_value(builder, sys_stats_get_memory_usage_percentage(&gen->stats)); + + json_builder_end_object(builder); + json_builder_end_object(builder); +} + diff --git a/src/generators/report-generator-system.h b/src/generators/report-generator-system.h new file mode 100644 index 0000000..930107b --- /dev/null +++ b/src/generators/report-generator-system.h @@ -0,0 +1,32 @@ +/* + * 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_SYSTEM_H_ +#define __REPORT_GENERATOR_SYSTEM_H_ + +/** Generator for system-wide reports */ +typedef struct report_generator_system report_generator_system_t; + +/** + * @brief Creates new instance of report_generator_system_t + * @return new report_generator_system_t object, or NULL on error + * + * @remark return value should be released with + * @report_generator_free_system_generator + */ +report_generator_system_t *report_generator_system_new_generator(); + +#endif diff --git a/src/generators/report-generator-top.c b/src/generators/report-generator-top.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/generators/report-generator-top.c diff --git a/src/generators/report-generator-top.h b/src/generators/report-generator-top.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/generators/report-generator-top.h diff --git a/src/report-generator.c b/src/report-generator.c index 5eca6c8..b851469 100644 --- a/src/report-generator.c +++ b/src/report-generator.c @@ -31,21 +31,10 @@ #include "json-schema-defs.h" #include "macros.h" -static void report_generator_release_system_generator(report_generator_t *generator); -static bool report_generator_refresh_system_generator(report_generator_t *generator); -static void report_generator_generate_system_report(report_generator_t *generator, JsonBuilder *builder); static void report_generator_release_load_avg_generator(report_generator_t *generator); static bool report_generator_refresh_load_avg_generator(report_generator_t *generator); static void report_generator_generate_load_avg_report(report_generator_t *generator, JsonBuilder *builder); -struct report_generator_system { - /** generator base - should be first */ - struct report_generator base; - /** system cpu usage statistics */ - struct sys_stats stats; - time_t update_time; -}; - struct report_generator_load_avg { /** generator base - should be first */ @@ -79,30 +68,6 @@ struct report_generator_top_closure { static int _report_generator_top_report_generator_scan(report_generator_top_t *generator); -report_generator_system_t *report_generator_new_system_report_generator() -{ - report_generator_system_t *ret = calloc(1, sizeof(struct report_generator_system)); - if (!ret) - return NULL; - - ret->base.refresh = report_generator_refresh_system_generator; - ret->base.generate = report_generator_generate_system_report; - ret->base.release = report_generator_release_system_generator; - - if (report_generator_refresh((report_generator_t*)ret) != true) { - free(ret); - return NULL; - } - - return ret; -} - -static void report_generator_release_system_generator(report_generator_t *generator) -{ - report_generator_system_t *gen = container_of(generator, report_generator_system_t, base); - free(gen); -} - report_generator_process_t *report_generator_new_process_report_generator() { report_generator_process_t *ret = calloc(1, sizeof(struct report_generator_process)); @@ -188,46 +153,6 @@ void report_generator_set_filter( generator->user_data = (void*)user_data; } -static bool report_generator_refresh_system_generator( - report_generator_t *generator) -{ - report_generator_system_t *sys_gen = container_of(generator, report_generator_system_t, base); - - if (sys_stats_update(&sys_gen->stats) != 0) { - ERR("stats_update_system_stats failed."); - return false; - } - sys_gen->update_time = clock_realtime_get(); - return true; -} - -static void report_generator_generate_system_report( - report_generator_t *generator, - JsonBuilder *builder) -{ - report_generator_system_t *gen = container_of(generator, report_generator_system_t, base); - - 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, gen->update_time); - - json_builder_set_member_name(builder, SCHEMA_RESULT_CPU); - json_builder_add_double_value(builder, sys_stats_get_cpu_usage_percentage(&gen->stats)); - - json_builder_set_member_name(builder, SCHEMA_RESULT_MEMORY); - json_builder_add_double_value(builder, sys_stats_get_memory_usage_percentage(&gen->stats)); - - json_builder_end_object(builder); - json_builder_end_object(builder); -} - report_generator_load_avg_t *report_generator_new_load_avg_report_generator() { report_generator_load_avg_t *ret = calloc(1, sizeof(report_generator_load_avg_t)); diff --git a/src/report-generator.h b/src/report-generator.h index 8b56644..a3955be 100644 --- a/src/report-generator.h +++ b/src/report-generator.h @@ -71,9 +71,6 @@ void report_generator_generate(report_generator_t *generator, JsonBuilder *build */ void report_generator_release(report_generator_t *generator); -/** Generator for system-wide reports */ -typedef struct report_generator_system report_generator_system_t; - /** Generator for per process report */ typedef struct report_generator_process report_generator_process_t; @@ -101,15 +98,6 @@ typedef struct report_generator_load_avg report_generator_load_avg_t; report_generator_load_avg_t *report_generator_new_load_avg_report_generator(); /** - * @brief Creates new instance of report_generator_system_t - * @return new report_generator_system_t object, or NULL on error - * - * @remark return value should be released with - * @report_generator_free_system_generator - */ -report_generator_system_t *report_generator_new_system_report_generator(); - -/** * @brief Creates new instance of report_generator_process_t * * @return new report_generator_system_t object, or NULL on error diff --git a/src/task-factory.c b/src/task-factory.c index 166bad6..4d91796 100644 --- a/src/task-factory.c +++ b/src/task-factory.c @@ -19,6 +19,7 @@ #include "task-factory.h" #include "config.h" #include "report-generator.h" +#include "report-generator-system.h" #include "report-json-serializer.h" #include "log.h" #include "err-check.h" @@ -96,7 +97,7 @@ static task_t *create_system_report_task() system_task_t *_system_task = (system_task_t *)g_malloc(sizeof(system_task_t)); _system_task->task.release = release_system_task; - _system_task->report_generator = report_generator_new_system_report_generator(); + _system_task->report_generator = report_generator_system_new_generator(); _system_task->task.execute = execute_scan_system; _system_task->builder = json_builder_new(); _system_task->generator = json_generator_new(); |