Use realtime clock for report time.
Change-Id: I4623ef15d9c5b842077035525248015051b9e34b
appinfo-provider.c
report-json-serializer.c
stats.c
+ clock.c
)
ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
--- /dev/null
+/*
+ * 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 "clock.h"
+#include "log.h"
+
+struct timespec clock_monotonic_get()
+{
+ struct timespec ret = {0,};
+
+ if (clock_gettime(CLOCK_MONOTONIC, &ret) != 0) {
+ ERR("Platform do not support monotonic clock type");
+ abort();
+ }
+
+ return ret;
+}
+
+struct timespec clock_realtime_get()
+{
+ struct timespec ret = {0,};
+
+ if (clock_gettime(CLOCK_REALTIME, &ret) != 0) {
+ ERR("Platform do not support realtime clock type");
+ abort();
+ }
+
+ return ret;
+}
+
+bool clock_is_supported()
+{
+ struct timespec ret = {0,};
+
+ if (clock_gettime(CLOCK_MONOTONIC, &ret) != 0) {
+ ERR("Platform do not support monotonic clock type");
+ return false;
+ }
+ if (clock_gettime(CLOCK_REALTIME, &ret) != 0) {
+ ERR("Platform do not support realtime clock type");
+ return false;
+ }
+ return true;
+}
+
--- /dev/null
+/*
+ * 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 _CLOCK_MONOTONIC_H
+#define _CLOCK_MONOTONIC_H
+
+#include <time.h>
+#include <stdbool.h>
+
+/**
+ * @brief Check if platform supports required clock types
+ *
+ * @return true if supported, false otherwise.
+ */
+bool clock_is_supported();
+
+/**
+ * @brief Gets current time using monotonic clock
+ *
+ * @note the func will abort if monotonic clock is not supported.
+ * call @clock_is_supported beforehead to validate if platform
+ * supports all clock types.
+ */
+struct timespec clock_monotonic_get();
+
+/**
+ * @brief Gets current time using realtime clock
+ *
+ * @note the func will abort if realtime clock is not supported.
+ * call @clock_is_supported beforehead to validate if platform
+ * supports all clock types.
+ *
+ */
+struct timespec clock_realtime_get();
+
+#endif
*/
#include <stdlib.h>
-#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include "err-check.h"
#include "appinfo-provider.h"
#include "stats.h"
+#include "clock.h"
struct report_generator_system {
/** system cpu usage statistics */
int _app_report_generator_setup_process_generator(report_generator_app_t *generator);
-static struct timespec clock_get_monotonic()
-{
- struct timespec ret = {0,};
-
- if (clock_gettime(CLOCK_MONOTONIC, &ret) != 0) {
- ERR("Platform do not support monotonic clock type");
- //TODO consider adding first init function to evaluate
- //if clock_gettime can be used, so calling module could
- //handle cases without monotonic clock gracefully.
- abort();
- }
-
- return ret;
-}
-
report_generator_system_t *report_generator_new_system_report_generator()
{
report_generator_system_t *ret = calloc(1, sizeof(struct report_generator_system));
}
report->usage = usage;
- report->time = clock_get_monotonic().tv_sec;
+ report->time = clock_realtime_get().tv_sec;
generator->previous = current;
return -1;
}
- report->time = clock_get_monotonic().tv_sec;
+ report->time = clock_realtime_get().tv_sec;
report->usage = usage;
return 0;
return -1;
}
- report->time = clock_get_monotonic().tv_sec;
+ report->time = clock_realtime_get().tv_sec;
report->pid = generator->pid;
report->usage = usage;
return -1;
}
- report->time = clock_get_monotonic().tv_sec;
+ report->time = clock_realtime_get().tv_sec;
report->usage = usage;
return 0;
return -1;
}
- report->time = clock_get_monotonic().tv_sec;
+ report->time = clock_realtime_get().tv_sec;
report->one_min_avg = a1;
report->five_min_avg = a5;
report->fifteen_min_avg = a15;