free(generator);
}
+report_generator_apps_t *report_generator_new_apps_report_generator(const char *app_id)
+{
+ //TODO implement
+ return NULL;
+}
+
+void report_generator_free_apps_generator(report_generator_apps_t *generator)
+{
+ //TODO implement
+}
+
static void _calculate_system_cpu_usage(
struct procfs_system_cpu_usage_info *previous,
struct procfs_system_cpu_usage_info *current,
return 0;
}
+int report_generator_generate_apps_cpu_usage_report(
+ report_generator_apps_t *generator,
+ int interval,
+ struct app_cpu_usage_report **reports)
+{
+ //TODO implement
+ return -1;
+}
+
+
+int report_generator_generate_apps_memory_usage_report(
+ report_generator_apps_t *generator,
+ struct app_memory_usage_report **report)
+{
+ //TODO implement
+ return -1;
+}
+
int report_generator_generate_load_average_report(struct system_load_average_report *report)
{
ON_NULL_RETURN_VAL(report, -1);
/** Generator for per process report */
typedef struct report_generator_process report_generator_process_t;
+/** Generator for apps report */
+typedef struct report_generator_apps report_generator_apps_t;
+
/**
* @brief Creates new instance of report_generator_system_t
* @return new report_generator_system_t object, or NULL on error
/**
* @brief Creates new instance of report_generator_process_t
*
- * @param[in] procsss PID
+ * @param[in] process PID
* @return new report_generator_system_t object, or NULL on error
*
* @remark return value should be released with
/**
* @brief Release report_generator_process_t created with
- * @report_generator_new_process_report_generator_
+ * @report_generator_new_process_report_generator
*/
void report_generator_free_process_generator(report_generator_process_t *generator);
/**
+ * @brief Creates new instance of report_generator_apps_t
+ *
+ * @param[in] Apps id regex.
+ * @return New report_generator_apps_t object, or NULL on error
+ *
+ * @remark return value should be released with
+ * @report_generator_free_apps_generator
+ */
+report_generator_apps_t *report_generator_new_apps_report_generator(const char *app_id);
+
+/**
+ * @brief Release report_generator_apps_t created with
+ * @report_generator_new_apps_report_generator
+ */
+void report_generator_free_apps_generator(report_generator_apps_t *generator);
+
+/**
* @brief Fills system_cpu_usage_report.
*
* When interval > 0 the function will block for interval seconds and return report with
* cpu usage calculated as average between current time and last call to
* report_generator_generate_process_cpu_usage_report for generator
*
- * @param[in] generator system generator
+ * @param[in] generator process generator
* @param[in] interval in seconds, Should be >= 0
* @param[out] report
* @return 0 on success, other value on failure
/**
* @brief Fills process_memory_usage_report.
*
- * @param[in] generator system generator
+ * @param[in] generator process generator
* @param[out] report
* @return 0 on success, other value on failure
*/
struct process_memory_usage_report *report);
/**
+ * @brief Fills apps_cpu_usage_report.
+ *
+ * When interval > 0 the function will block for interval seconds and return report with
+ * apps cpu usage calculated as average during interval period.
+ * When interval == 0 the function will not block and return report with apps
+ * cpu usage calculated as average between current time and last call to
+ * report_generator_generate_process_cpu_usage_report for generator
+ *
+ * @param[in] generator apps generator
+ * @param[in] interval in seconds, Should be >= 0
+ * @param[out] Dynamically allocated array of reports.
+ * @return 0 on success, other value on failure
+ * @remarks Returned value should be freed.
+ */
+int report_generator_generate_apps_cpu_usage_report(
+ report_generator_apps_t *generator,
+ int interval,
+ struct app_cpu_usage_report **reports);
+
+/**
+ * @brief Fills process_memory_usage_report.
+ *
+ * @param[in] generator apps generator
+ * @param[out] Dynamically allocated array of reports.
+ * @return 0 on success, other value on failure
+ */
+int report_generator_generate_apps_memory_usage_report(
+ report_generator_apps_t *generator,
+ struct app_memory_usage_report **report);
+
+/**
* @brief Fills system_load_average_report
*
* @param[out] report
json_builder_end_object(builder);
}
-static void app_cpu_usage_report_to_json_object(JsonBuilder *builder, struct app_cpu_usage_report *report)
+static void apps_cpu_usage_report_to_json_object(JsonBuilder *builder, struct app_cpu_usage_report *report)
{
//TODO
//implement after report API changes
}
-static void app_memory_usage_report_to_json_object(JsonBuilder *builder, struct app_memory_usage_report *report)
+static void apps_memory_usage_report_to_json_object(JsonBuilder *builder, struct app_memory_usage_report *report)
{
//TODO
//implement after report API changes
system_cpu_usage_report_to_json_object)
IMPLEMENT_SERIALIZER_FUNC(
- report_json_serializer_serialize_app_cpu_usage_report,
+ report_json_serializer_serialize_apps_cpu_usage_report,
struct app_cpu_usage_report,
- app_cpu_usage_report_to_json_object)
+ apps_cpu_usage_report_to_json_object)
IMPLEMENT_SERIALIZER_FUNC(
- report_json_serializer_serialize_app_memory_usage_report,
+ report_json_serializer_serialize_apps_memory_usage_report,
struct app_memory_usage_report,
- app_memory_usage_report_to_json_object)
+ apps_memory_usage_report_to_json_object)
* @return dynamically allocated string on NULL on error.
* @remark returned value should be released with @free
*/
-char *report_json_serializer_serialize_app_cpu_usage_report(struct app_cpu_usage_report *report);
+char *report_json_serializer_serialize_apps_cpu_usage_report(struct app_cpu_usage_report *report);
/**
* @brief Serializes app_memory_usage_report to json string
* @return dynamically allocated string on NULL on error.
* @remark returned value should be released with @free
*/
-char *report_json_serializer_serialize_app_memory_usage_report(struct app_memory_usage_report *report);
+char *report_json_serializer_serialize_apps_memory_usage_report(struct app_memory_usage_report *report);
#endif
static task_t *create_system_report_task(config_options_e options);
static task_t *create_load_avg_report_task();
+static task_t *create_apps_report_task(config_options_e options, const char *regex);
static void execute_scan_system_memory(task_t *task);
static void execute_scan_system_cpu(task_t *task);
static void execute_scan_load_avg(task_t *task);
+static void execute_scan_apps_memory(task_t *task);
+static void execute_scan_apps_cpu(task_t *task);
static void send_report(char *report);
+
static void release_system_task(task_t *task);
+static void release_app_task(task_t *task);
task_t *task_factory_create_single(const config_t *config)
{
case LOAD_AVG:
return create_load_avg_report_task();
case APPS:
+ return create_apps_report_task(config->data.apps.options, config->data.apps.app_id);
case TOP:
default:
return NULL;
return _load_avg_task;
}
+static task_t *create_apps_report_task(config_options_e options, const char *regex)
+{
+ app_task_t *_app_task = (app_task_t *)g_malloc(sizeof(app_task_t));
+
+ _app_task->task.release = release_app_task;
+ _app_task->report_generator = report_generator_new_apps_report_generator(regex);
+
+ switch (options)
+ {
+ case OBSERVE_CPU:
+ _app_task->task.execute = execute_scan_apps_cpu;
+ break;
+ case OBSERVE_MEMORY:
+ _app_task->task.execute = execute_scan_apps_memory;
+ break;
+ default:
+ report_generator_free_apps_generator(_app_task->report_generator);
+ g_free(_app_task);
+ return NULL;
+ }
+
+ return &_app_task->task;
+}
+
static void execute_scan_system_memory(task_t *task)
{
ON_NULL_RETURN(task);
g_free(json_report);
}
+static void execute_scan_apps_memory(task_t *task)
+{
+ ON_NULL_RETURN(task);
+
+ app_task_t *_app_task = container_of(task, app_task_t, task);
+
+ struct app_memory_usage_report *reports;
+
+ report_generator_generate_apps_memory_usage_report(_app_task->report_generator, &reports);
+
+ char *json_report = report_json_serializer_serialize_apps_memory_usage_report(reports);
+ send_report(json_report);
+ g_free(reports);
+ g_free(json_report);
+}
+
+static void execute_scan_apps_cpu(task_t *task)
+{
+ ON_NULL_RETURN(task);
+
+ app_task_t *_app_task = container_of(task, app_task_t, task);
+
+ struct app_cpu_usage_report *reports;
+
+ report_generator_generate_apps_cpu_usage_report(_app_task->report_generator, 0, &reports);
+
+ char *json_report = report_json_serializer_serialize_apps_cpu_usage_report(reports);
+ send_report(json_report);
+ g_free(reports);
+ g_free(json_report);
+}
+
static void send_report(char *report)
{
//TODO send report here
system_task_t *_system_task = container_of(task, system_task_t, task);
report_generator_free_system_generator(_system_task->report_generator);
-
g_free(_system_task);
+}
+
+static void release_app_task(task_t *task)
+{
+ ON_NULL_RETURN(task);
+
+ app_task_t *_app_task = container_of(task, app_task_t, task);
+
+ report_generator_free_apps_generator(_app_task->report_generator);
+ g_free(_app_task);
}
\ No newline at end of file
typedef struct app_task
{
task_t task;
- report_generator_process_t *report_generator;
+ report_generator_apps_t *report_generator;
} app_task_t;
/**