4 * Lib for getting process statistics
6 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
25 #include <proc_stat.h>
31 GArray *valid_proc_infos = NULL;
32 GArray *terminated_proc_infos = NULL;
33 proc_stat_system_time st_diff;
35 terminated_proc_infos = g_array_new(false, false, sizeof(proc_stat_process_info));
36 valid_proc_infos = g_array_new(false, false, sizeof(proc_stat_process_info));
43 proc_stat_get_process_info(valid_proc_infos, terminated_proc_infos, NULL);
44 proc_stat_get_system_time_diff(&st_diff);
46 if (st_diff.total_time != 0) {
48 double total_time = st_diff.total_time;
50 printf("Total CPU Info : %3.2lf%%us %3.2lf%%sy %3.2lf%%ni %3.2lf%%id %3.2lf%%iowait %3.2lf%%irq %3.2lf%%softirq\n",
51 (double)st_diff.user_time / total_time * 100,
52 (double)st_diff.system_time / total_time * 100,
53 (double)st_diff.nice_time / total_time * 100,
54 (double)st_diff.idle_time / total_time * 100,
55 (double)st_diff.iowait_time / total_time * 100,
56 (double)st_diff.irq_time / total_time * 100,
57 (double)st_diff.softirq_time / total_time * 100);
59 unsigned int total, free;
60 if (proc_stat_get_total_mem_size(&total) && proc_stat_get_free_mem_size(&free))
61 printf("Total Memory Info : Total:%dMB Free:%dMB Used:%dMB\n", total, free, total - free);
64 for (i = 0; i < valid_proc_infos->len; ++i) {
65 proc_stat_process_info *ps = &g_array_index(valid_proc_infos, proc_stat_process_info, i);
67 if ((ps->active) || (ps->fresh)) {
73 printf("[pid:%d\t name:%40s utime:%3.2lf%% stime:%3.2lf%% rss:%dKb\n",
75 (double)(ps->utime_diff)/(double)st_diff.total_time*100,
76 (double)(ps->stime_diff)/(double)st_diff.total_time*100,
81 for (i = 0; i < terminated_proc_infos->len; ++i) {
83 proc_stat_process_info *ps = &g_array_index(terminated_proc_infos, proc_stat_process_info, i);
86 printf("[pid:%d\t name:%40s\n",
93 g_array_set_size(valid_proc_infos, 0);
94 g_array_set_size(terminated_proc_infos, 0);
96 printf("-------------------------------------------------------------------------------\n");
100 if (valid_proc_infos) {
101 g_array_free(valid_proc_infos, true);
102 valid_proc_infos = NULL;
106 if (terminated_proc_infos) {
107 g_array_free(terminated_proc_infos, true);
108 terminated_proc_infos = NULL;
111 proc_stat_finalize();