2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <libsyscommon/libgdbus.h>
27 #include <runtime_info.h>
28 #include <runtime_info_private.h>
29 #include <runtime_info-internal.h>
33 #include <hal/hal-device-memory.h>
35 #define RESOURCED_BUS_NAME "org.tizen.resourced"
36 #define RESOURCED_USAGE_OBJECT_NAME "/Org/Tizen/ResourceD/Process"
37 #define RESOURCED_USAGE_INTERFACE_NAME "org.tizen.resourced.process"
38 #define DBUS_REPLY_TIMEOUT (120 * 1000)
41 USAGE_TYPE_PROCESS_MEMORY,
42 USAGE_TYPE_PROCESS_CPU,
43 USAGE_TYPE_APP_MEMORY,
45 USAGE_TYPE_PROCESS_SWAP,
46 } runtime_info_usage_type_e;
49 const char *method_name;
51 } runtime_info_dbus_info_s;
53 /* The index of this array must be matched with runtime_info_usage_type_e */
54 static const runtime_info_dbus_info_s dbus_info[] = {
55 { "ProcMemoryUsage", "process memory" },
56 { "ProcCpuUsage", "process cpu" },
57 { "GetMemoryList", "all apps memory" },
58 { "GetCpuList", "all apps cpu" },
59 { "ProcSwapUsage", "process swap" },
62 #define ULONGtoINT(ulong) (int)(MIN((ulong), INT_MAX))
64 /* ((val << 12) >> 10) = (val << 2) */
65 #define pagetoKiB(val) ((val) <= 0) ? 0 : (int)MIN(((long long)(val) << 2), INT_MAX)
67 /* Convert int array to GVariant("ai") */
68 static GVariant *runtime_info_append_args(int *args, int size)
70 GVariantBuilder builder, *sub_builder;
73 g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE);
74 sub_builder = g_variant_builder_new(G_VARIANT_TYPE("ai"));
76 for (i = 0; i < size; i++)
77 g_variant_builder_add(sub_builder, "i", args[i]);
79 g_variant_builder_add_value(&builder, g_variant_new("ai", sub_builder));
80 g_variant_builder_unref(sub_builder);
82 return g_variant_builder_end(&builder);
86 static runtime_info_error_e errno_to_runtime_info_error(int err)
90 return RUNTIME_INFO_ERROR_NONE;
92 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
94 return RUNTIME_INFO_ERROR_OUT_OF_MEMORY;
97 return RUNTIME_INFO_ERROR_IO_ERROR;
100 return RUNTIME_INFO_ERROR_PERMISSION_DENIED;
102 return RUNTIME_INFO_ERROR_NOT_SUPPORTED;
104 return RUNTIME_INFO_ERROR_REMOTE_IO;
106 // TODO: what is the runtime-info error for this default case?
107 return RUNTIME_INFO_ERROR_NO_DATA;
112 /* Handler function which handles dbus related instructions
113 * Creates the method call to resourced and receives the reply (if successful)
114 * Return the received usage information (if received) else NULL to signify failed call to resourced
116 static GVariant *runtime_info_dbus_request_usage_info(runtime_info_usage_type_e type,
117 int *pid, int size, int *error)
120 GVariant *args_in = NULL;
121 GVariant *reply = NULL;
124 /* Check parameter */
126 case USAGE_TYPE_PROCESS_MEMORY:
127 case USAGE_TYPE_PROCESS_CPU:
128 case USAGE_TYPE_PROCESS_SWAP:
129 if (!pid || size <= 0) {
130 //LCOV_EXCL_START : system error
131 _E("INVALID_PARAMETER(0x%08x): pid list cannot be null",
132 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
134 *error = RUNTIME_INFO_ERROR_INVALID_PARAMETER;
139 case USAGE_TYPE_APP_MEMORY:
140 case USAGE_TYPE_APP_CPU:
141 if (!error) { //LCOV_EXCL_START : system error
142 _E("INVALID_PARAMETER(0x%08x): error parameter cannot be null",
143 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
149 //LCOV_EXCL_START : system error
150 _E("INVALID_PARAMETER(0x%08x): invalid type parameter",
151 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
153 *error = RUNTIME_INFO_ERROR_INVALID_PARAMETER;
158 /* Make argument for requesting */
160 case USAGE_TYPE_PROCESS_MEMORY:
161 case USAGE_TYPE_PROCESS_CPU:
162 case USAGE_TYPE_PROCESS_SWAP:
163 _D("Process %d: received query to get %s usage of %d processes",
164 getpid(), dbus_info[type].caption, size);
165 args_in = runtime_info_append_args(pid, size);
167 //LCOV_EXCL_START : system error
168 _E("DBUS_METHOD_CALL: not able to append pid array to message");
170 *error = RUNTIME_INFO_ERROR_IO_ERROR;
175 case USAGE_TYPE_APP_MEMORY:
176 case USAGE_TYPE_APP_CPU:
177 _D("Process %d: received query to get %s usage of all apps",
178 getpid(), dbus_info[type].caption);
183 _D("Process %d: Sending dbus message to resourced for %s info",
184 getpid(), dbus_info[type].caption);
185 ret_dbus = gdbus_call_sync_with_reply(RESOURCED_BUS_NAME,
186 RESOURCED_USAGE_OBJECT_NAME,
187 RESOURCED_USAGE_INTERFACE_NAME,
188 dbus_info[type].method_name,
192 //LCOV_EXCL_START : system error
193 _E("DBUS_METHOD_CALL: not able to send message");
195 *error = errno_to_runtime_info_error(ret_dbus);
200 ret = g_variant_get_child_value(reply, 0);
201 g_variant_unref(reply);
206 static int runtime_info_get_all_apps_usage(runtime_info_usage_type_e type,
212 struct app_usages_s *usages;
217 _E("INVALID_PARAMETER(0x%08x) : invalid output param",
218 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
219 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
222 reply = runtime_info_dbus_request_usage_info(type, NULL, 0, &error);
224 //LCOV_EXCL_START : system error
225 _E("DBUS_METHOD_CALL: call to resourced not successful");
230 /* Check whether the received usage has expected format or not */
231 if (g_strcmp0(g_variant_get_type_string(reply), "a(su)")) {
232 //LCOV_EXCL_START : system error
233 _E("DBUS_METHOD_CALL: received dbus message is not in expected format");
234 g_variant_unref(reply);
235 return RUNTIME_INFO_ERROR_REMOTE_IO;
239 /* Populate the entries of info array using the data received from resourced */
240 len = g_variant_n_children(reply);
243 _E("NO_DATA(0x%08x) : there is no registered app", RUNTIME_INFO_ERROR_NO_DATA);
244 g_variant_unref(reply);
245 return RUNTIME_INFO_ERROR_NO_DATA;
249 usages = calloc(1, sizeof(struct app_usages_s));
252 _E("OUT_OF_MEMORY(0x%08x)", RUNTIME_INFO_ERROR_OUT_OF_MEMORY);
253 g_variant_unref(reply);
254 return RUNTIME_INFO_ERROR_OUT_OF_MEMORY;
258 usages->len = (int)len;
260 usages->list = calloc(len, sizeof(struct app_usage_s));
263 _E("OUT_OF_MEMORY(0x%08x)", RUNTIME_INFO_ERROR_OUT_OF_MEMORY);
265 g_variant_unref(reply);
266 return RUNTIME_INFO_ERROR_OUT_OF_MEMORY;
270 g_variant_iter_init(&iter, reply);
271 for (i = 0; i < len; i++)
272 g_variant_iter_next(&iter, "(su)",
273 &(usages->list[i].appid), &(usages->list[i].usage));
274 g_variant_unref(reply);
278 return RUNTIME_INFO_ERROR_NONE;
281 API int runtime_info_get_system_memory_info(runtime_memory_info_s *info)
286 unsigned long mem_total = 0;
287 unsigned long mem_free = 0;
288 unsigned long cached = 0;
289 unsigned long mem_available = 0;
290 unsigned long swap_total = 0;
291 unsigned long swap_free = 0;
294 _E("INVALID_PARAMETER(0x%08x) : invalid output param",
295 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
296 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
299 swap_total = swap_free = mem_available = 0;
301 fp = fopen("/proc/meminfo", "r");
304 _E("IO_ERROR(0x%08x) : failed to open file to read memory usage",
305 RUNTIME_INFO_ERROR_IO_ERROR);
306 return RUNTIME_INFO_ERROR_IO_ERROR;
310 info->total = info->free = info->cache = 0;
311 while (fgets(buf, sizeof(buf), fp) != NULL) {
312 if (sscanf(buf, "MemTotal: %lu", &mem_total) == 1)
313 info->total = ULONGtoINT(mem_total);
314 else if (sscanf(buf, "MemFree: %lu", &mem_free) == 1)
315 info->free = ULONGtoINT(mem_free);
316 else if (sscanf(buf, "Cached: %lu", &cached) == 1)
317 info->cache = ULONGtoINT(cached);
318 else if (sscanf(buf, "MemAvailable: %lu", &value) == 1)
319 mem_available = value;
320 else if (sscanf(buf, "SwapTotal: %lu", &value) == 1)
322 else if (sscanf(buf, "SwapFree: %lu", &value) == 1)
327 if (mem_available > 0) {
328 if (mem_total > mem_available)
329 info->used = ULONGtoINT(mem_total - mem_available);
333 if (mem_total > mem_free && mem_total - mem_free > cached)
334 info->used = ULONGtoINT(mem_total - mem_free - cached);
339 info->swap = (swap_total > swap_free) ? ULONGtoINT(swap_total - swap_free) : 0;
341 return RUNTIME_INFO_ERROR_NONE;
344 API int runtime_info_get_process_memory_info(int *pid, int size, process_memory_info_s **info)
351 if (!pid || size <= 0) {
352 _E("INVALID_PARAMETER(0x%08x) : invalid input param",
353 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
354 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
358 _E("INVALID_PARAMETER(0x%08x) : invalid output param",
359 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
360 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
365 /* Get the needed information from resourced daemon using dbus */
366 reply = runtime_info_dbus_request_usage_info(USAGE_TYPE_PROCESS_MEMORY, pid, size, &error);
368 //LCOV_EXCL_START : system error
369 _E("DBUS_METHOD_CALL: call to resourced not successful");
374 /* Check whether the received usage has expected format or not */
375 if (g_strcmp0(g_variant_get_type_string(reply), "a(iiiiiii)") ||
376 g_variant_n_children(reply) != size) {
377 //LCOV_EXCL_START : system error
378 _E("DBUS_METHOD_CALL: received dbus message is not in expected format");
379 g_variant_unref(reply);
380 return RUNTIME_INFO_ERROR_REMOTE_IO;
384 /* Populate the entries of info array using the data received from resourced */
385 *info = (process_memory_info_s *)malloc(size * sizeof(process_memory_info_s));
388 _E("OUT_OF_MEMORY(0x%08x)", RUNTIME_INFO_ERROR_OUT_OF_MEMORY);
389 g_variant_unref(reply);
390 return RUNTIME_INFO_ERROR_OUT_OF_MEMORY;
394 g_variant_iter_init(&iter, reply);
395 for (i = 0; i < size; i++)
396 g_variant_iter_next(&iter, "(iiiiiii)",
400 &((*info)[i].shared_clean),
401 &((*info)[i].shared_dirty),
402 &((*info)[i].private_clean),
403 &((*info)[i].private_dirty));
405 g_variant_unref(reply);
407 return RUNTIME_INFO_ERROR_NONE;
410 //LCOV_EXCL_START Internal API
411 static int get_process_memory_info_direct(int *pid, int size, process_memory_info_key_e key, int **info)
414 hal_device_memory_gpu_info_s gpu_info;
415 hal_device_memory_gem_info_s gem_info;
417 int ret = RUNTIME_INFO_ERROR_NONE;
419 result = (int *)calloc(size, sizeof(int));
421 ret = RUNTIME_INFO_ERROR_OUT_OF_MEMORY;
426 case RUNTIME_INFO_PROC_MEMORY_GPU:
427 for (i = 0; i < size; ++i) {
428 ret_hal = hal_device_memory_get_gpu_info(pid[i], &gpu_info);
430 ret = errno_to_runtime_info_error(ret_hal);
433 result[i] = gpu_info.used_pages;
437 case RUNTIME_INFO_PROC_MEMORY_GEM_RSS:
438 for (i = 0; i < size; ++i) {
439 ret_hal = hal_device_memory_get_gem_info(pid[i], &gem_info);
441 ret = errno_to_runtime_info_error(ret_hal);
444 result[i] = gem_info.rss;
449 ret = RUNTIME_INFO_ERROR_INVALID_PARAMETER;
454 if (ret != RUNTIME_INFO_ERROR_NONE)
460 static int get_process_memory_swap_info(int *pid, int size, int **info)
467 if (!pid || size <= 0) {
468 _E("INVALID_PARAMETER(0x%08x) : invalid input param",
469 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
470 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
474 _E("INVALID_PARAMETER(0x%08x) : invalid output param",
475 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
476 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
481 /* Get the needed information from resourced daemon using dbus */
482 reply = runtime_info_dbus_request_usage_info(USAGE_TYPE_PROCESS_SWAP, pid, size, &error);
484 _E("DBUS_METHOD_CALL: call to resourced not successful");
488 /* Check whether the received usage has expected format or not */
489 if (g_strcmp0(g_variant_get_type_string(reply), "a(i)") ||
490 g_variant_n_children(reply) != size) {
491 _E("DBUS_METHOD_CALL: received dbus message is not in expected format");
492 g_variant_unref(reply);
493 return RUNTIME_INFO_ERROR_REMOTE_IO;
496 /* Populate the entries of info array using the data received from resourced */
497 *info = (int *)malloc(size * sizeof(int));
499 _E("OUT_OF_MEMORY(0x%08x)", RUNTIME_INFO_ERROR_OUT_OF_MEMORY);
500 g_variant_unref(reply);
501 return RUNTIME_INFO_ERROR_OUT_OF_MEMORY;
504 g_variant_iter_init(&iter, reply);
505 for (i = 0; i < size; i++) {
506 g_variant_iter_next(&iter, "(i)", &temp);
510 g_variant_unref(reply);
512 return RUNTIME_INFO_ERROR_NONE;
515 static int get_process_memory_info(int *pid, int size, process_memory_info_key_e key, int **info)
520 process_memory_info_s *base = NULL;
522 ret = RUNTIME_INFO_ERROR_NONE;
524 result = (int *)calloc(size, sizeof(int));
526 ret = RUNTIME_INFO_ERROR_OUT_OF_MEMORY;
530 ret = runtime_info_get_process_memory_info(pid, size, &base);
531 if (ret != RUNTIME_INFO_ERROR_NONE)
535 case RUNTIME_INFO_PROC_MEMORY_VSZ:
536 for (i = 0; i < size; ++i)
537 result[i] = base[i].vsz;
539 case RUNTIME_INFO_PROC_MEMORY_RSS:
540 for (i = 0; i < size; ++i)
541 result[i] = base[i].rss;
543 case RUNTIME_INFO_PROC_MEMORY_PSS:
544 for (i = 0; i < size; ++i)
545 result[i] = base[i].pss;
547 case RUNTIME_INFO_PROC_MEMORY_SHARED_CLEAN:
548 for (i = 0; i < size; ++i)
549 result[i] = base[i].shared_clean;
551 case RUNTIME_INFO_PROC_MEMORY_SHARED_DIRTY:
552 for (i = 0; i < size; ++i)
553 result[i] = base[i].shared_dirty;
555 case RUNTIME_INFO_PROC_MEMORY_PRIVATE_CLEAN:
556 for (i = 0; i < size; ++i)
557 result[i] = base[i].private_clean;
559 case RUNTIME_INFO_PROC_MEMORY_PRIVATE_DIRTY:
560 for (i = 0; i < size; ++i)
561 result[i] = base[i].private_dirty;
564 ret = RUNTIME_INFO_ERROR_INVALID_PARAMETER;
571 if (ret != RUNTIME_INFO_ERROR_NONE)
578 API int runtime_info_get_process_memory_value_int(int *pid, int size, process_memory_info_key_e key, int **info)
581 case RUNTIME_INFO_PROC_MEMORY_GPU:
582 case RUNTIME_INFO_PROC_MEMORY_GEM_RSS:
583 return get_process_memory_info_direct(pid, size, key, info);
584 case RUNTIME_INFO_PROC_MEMORY_SWAP:
585 return get_process_memory_swap_info(pid, size, info);
586 case RUNTIME_INFO_PROC_MEMORY_VSZ:
587 case RUNTIME_INFO_PROC_MEMORY_RSS:
588 case RUNTIME_INFO_PROC_MEMORY_PSS:
589 case RUNTIME_INFO_PROC_MEMORY_SHARED_CLEAN:
590 case RUNTIME_INFO_PROC_MEMORY_SHARED_DIRTY:
591 case RUNTIME_INFO_PROC_MEMORY_PRIVATE_CLEAN:
592 case RUNTIME_INFO_PROC_MEMORY_PRIVATE_DIRTY:
593 return get_process_memory_info(pid, size, key, info);
595 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
600 API int runtime_info_get_cpu_usage(runtime_cpu_usage_s *usage)
604 unsigned long long user = 0;
605 unsigned long long nice = 0;
606 unsigned long long system = 0;
607 unsigned long long idle = 0;
608 unsigned long long iowait = 0;
609 unsigned long long irq = 0;
610 unsigned long long softirq = 0;
611 unsigned long long total_uptime = 0;
614 _E("INVALID_PARAMETER(0x%08x) : invalid output param",
615 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
616 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
619 cpuinfo_fp = fopen("/proc/stat", "r");
620 if (cpuinfo_fp == NULL) {
622 _E("IO_ERROR(0x%08x) : failed to open file to read cpu usage",
623 RUNTIME_INFO_ERROR_IO_ERROR);
624 return RUNTIME_INFO_ERROR_IO_ERROR;
628 while (fgets(buf, sizeof(buf), cpuinfo_fp) != NULL) {
629 if (!strncmp(buf, "cpu ", 4) &&
630 sscanf(buf + 4, "%llu %llu %llu %llu %llu %llu %llu",
631 &user, &nice, &system, &idle,
632 &iowait, &irq, &softirq) == 7)
637 total_uptime = user + nice + system + idle + iowait + irq + softirq;
639 if (total_uptime > 0) {
640 usage->user = (double)user * 100 / total_uptime;
641 usage->nice = (double)nice * 100 / total_uptime;
642 usage->system = (double)system * 100 / total_uptime;
643 usage->iowait = (double)iowait * 100 / total_uptime;
651 return RUNTIME_INFO_ERROR_NONE;
654 API int runtime_info_get_process_cpu_usage(int *pid, int size, process_cpu_usage_s **usage)
661 if (!pid || size <= 0) {
662 _E("INVALID_PARAMETER(0x%08x) : invalid input param",
663 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
664 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
668 _E("INVALID_PARAMETER(0x%08x) : invalid output param",
669 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
670 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
675 /* Get the needed information from resourced daemon using dbus */
676 reply = runtime_info_dbus_request_usage_info(USAGE_TYPE_PROCESS_CPU, pid, size, &error);
678 //LCOV_EXCL_START : system error
679 _E("DBUS_METHOD_CALL: call to resourced not successful");
684 /* Check whether the received usage has expected format or not */
685 if (g_strcmp0(g_variant_get_type_string(reply), "a(ii)") ||
686 g_variant_n_children(reply) != size) {
687 //LCOV_EXCL_START : system error
688 _E("DBUS_METHOD_CALL: received dbus message is not in expected format");
689 g_variant_unref(reply);
690 return RUNTIME_INFO_ERROR_REMOTE_IO;
694 /* Populate the entries of info array using the data received from resourced */
695 *usage = (process_cpu_usage_s *)malloc(size * sizeof(process_cpu_usage_s));
697 //LCOV_EXCL_START : system error
698 _E("OUT_OF_MEMORY(0x%08x)", RUNTIME_INFO_ERROR_OUT_OF_MEMORY);
699 g_variant_unref(reply);
700 return RUNTIME_INFO_ERROR_OUT_OF_MEMORY;
704 g_variant_iter_init(&iter, reply);
705 for (i = 0; i < size; i++)
706 g_variant_iter_next(&iter, "(ii)", &((*usage)[i].utime), &((*usage)[i].stime));
708 g_variant_unref(reply);
710 return RUNTIME_INFO_ERROR_NONE;
713 API int runtime_info_get_processor_count(int *num_core)
720 _E("INVALID_PARAMETER(0x%08x) : invalid output parameter",
721 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
722 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
725 cpuinfo_fp = fopen("/sys/devices/system/cpu/possible", "r");
726 if (cpuinfo_fp == NULL) {
727 //LCOV_EXCL_START : system error
728 _E("IO_ERROR(0x%08x) : failed to open file to read cpu information",
729 RUNTIME_INFO_ERROR_IO_ERROR);
730 return RUNTIME_INFO_ERROR_IO_ERROR;
734 if (!fscanf(cpuinfo_fp, "%d-%d", &buf, &result)) {
735 //LCOV_EXCL_START : system error
736 _E("IO_ERROR(0x%08x) : there is no information in the system file",
737 RUNTIME_INFO_ERROR_IO_ERROR);
739 return RUNTIME_INFO_ERROR_IO_ERROR;
743 *num_core = result + 1;
746 return RUNTIME_INFO_ERROR_NONE;
749 API int runtime_info_get_processor_current_frequency(int core_idx, int *cpu_freq)
753 if (runtime_info_get_processor_count(&num_core)
754 != RUNTIME_INFO_ERROR_NONE) {
755 _E("runtime_info_get_processor_count is failed");
756 return RUNTIME_INFO_ERROR_IO_ERROR;
759 if (core_idx < 0 || core_idx >= num_core) {
760 _E("INVALID_PARAMETER(0x%08x) : invalid input parameter",
761 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
762 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
766 _E("INVALID_PARAMETER(0x%08x) : invalid output parameter",
767 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
768 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
771 if (runtime_info_get_frequency_cpufreq(core_idx, "cur", cpu_freq)
772 != RUNTIME_INFO_ERROR_NONE) {
773 //LCOV_EXCL_START : system error
774 _I("This system doesn't support cpufreq. Use cpuinfo instead.");
776 switch (runtime_info_get_frequency_cpuinfo(core_idx, cpu_freq)) {
777 case RUNTIME_INFO_ERROR_NONE:
778 _I("Notice : it is max CPU frequency");
780 case RUNTIME_INFO_ERROR_NO_DATA:
781 _E("This system doesn't support MHz information in the cpuinfo");
782 return RUNTIME_INFO_ERROR_NO_DATA;
784 _E("Fail to get current CPU frequency");
785 return RUNTIME_INFO_ERROR_IO_ERROR;
790 return RUNTIME_INFO_ERROR_NONE;
793 API int runtime_info_get_processor_max_frequency(int core_idx, int *cpu_freq)
797 if (runtime_info_get_processor_count(&num_core)
798 != RUNTIME_INFO_ERROR_NONE) {
799 _E("runtime_info_get_processor_count is failed");
800 return RUNTIME_INFO_ERROR_IO_ERROR;
803 if (core_idx < 0 || core_idx >= num_core) {
804 _E("INVALID_PARAMETER(0x%08x) : invalid input parameter",
805 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
806 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
810 _E("INVALID_PARAMETER(0x%08x) : invalid output parameter",
811 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
812 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
815 if (runtime_info_get_frequency_cpufreq(core_idx, "max", cpu_freq)
816 != RUNTIME_INFO_ERROR_NONE) {
817 //LCOV_EXCL_START : system error
818 _I("This system doesn't support cpufreq. Use cpuinfo instead.");
820 switch (runtime_info_get_frequency_cpuinfo(core_idx, cpu_freq)) {
821 case RUNTIME_INFO_ERROR_NONE:
823 case RUNTIME_INFO_ERROR_NO_DATA:
824 _E("This system doesn't support MHz information in the cpuinfo");
825 return RUNTIME_INFO_ERROR_NO_DATA;
827 _E("Fail to get current CPU frequency");
828 return RUNTIME_INFO_ERROR_IO_ERROR;
833 return RUNTIME_INFO_ERROR_NONE;
836 API int runtime_info_get_physical_memory_size(int *size)
841 FILE *fp = fopen("/proc/zoneinfo", "r");
844 _E("IO_ERROR(0x%08x) : failed to open file to read memory size",
845 RUNTIME_INFO_ERROR_IO_ERROR);
846 return RUNTIME_INFO_ERROR_IO_ERROR;
851 _E("INVALID PARAMETER(0x%08x) : invalid output parameter",
852 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
854 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
858 while (fgets(buf, sizeof(buf), fp) != NULL)
859 if (sscanf(buf, " spanned %lu", &value) == 1)
861 *size = pagetoKiB(sum);
865 return RUNTIME_INFO_ERROR_NONE;
868 API int runtime_info_app_usage_destroy(app_usage_h handle)
871 struct app_usage_s *list;
872 struct app_usages_s *usages = handle;
875 _E("INVALID PARAMETER(0x%08x) : invalid input parameter",
876 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
877 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
882 for (i = 0; i < usages->len; i++)
890 return RUNTIME_INFO_ERROR_NONE;
893 API int runtime_info_app_usage_get_count(app_usage_h handle, int *count)
895 struct app_usages_s *usages = handle;
898 _E("INVALID PARAMETER(0x%08x) : invalid input parameter",
899 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
900 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
904 _E("INVALID PARAMETER(0x%08x) : invalid output parameter",
905 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
906 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
909 *count = usages->len;
911 return RUNTIME_INFO_ERROR_NONE;
914 API int runtime_info_app_usage_get_appid(app_usage_h handle, int index, char **appid)
916 struct app_usages_s *usages = handle;
918 if (!usages || index < 0 || index >= usages->len) {
919 _E("INVALID PARAMETER(0x%08x) : invalid input parameter",
920 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
921 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
925 _E("INVALID PARAMETER(0x%08x) : invalid output parameter",
926 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
927 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
930 *appid = strndup(usages->list[index].appid, strlen(usages->list[index].appid));
932 return RUNTIME_INFO_ERROR_NONE;
935 API int runtime_info_app_usage_get_usage(app_usage_h handle, int index, unsigned int *usage)
937 struct app_usages_s *usages = handle;
939 if (!usages || index < 0 || index >= usages->len) {
940 _E("INVALID PARAMETER(0x%08x) : invalid input parameter",
941 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
942 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
946 _E("INVALID PARAMETER(0x%08x) : invalid output parameter",
947 RUNTIME_INFO_ERROR_INVALID_PARAMETER);
948 return RUNTIME_INFO_ERROR_INVALID_PARAMETER;
951 *usage = usages->list[index].usage;
953 return RUNTIME_INFO_ERROR_NONE;
956 API int runtime_info_get_all_apps_memory_usage(app_usage_h *usage)
958 return runtime_info_get_all_apps_usage(USAGE_TYPE_APP_MEMORY, usage);
961 API int runtime_info_get_all_apps_cpu_rate(app_usage_h *rate)
963 return runtime_info_get_all_apps_usage(USAGE_TYPE_APP_CPU, rate);