2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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.
23 #include <sys/ioctl.h>
25 #include <netinet/in.h>
26 #include <arpa/inet.h>
30 #include <sys/timerfd.h>
34 #include <sys/types.h>
38 #include <native_service/frameworkunified_dispatcher.h>
39 #include <native_service/frameworkunified_framework_if.h>
40 #include <native_service/ns_version_if.h>
41 #include <system_service/ss_services.h>
42 #include <native_service/frameworkunified_application.h>
43 #include <system_service/ss_system_if.h>
44 #include <system_service/ss_version.h>
45 #include <native_service/cl_process.h>
46 #include <system_service/ss_system_process.h>
47 #include <other_service/rpc.h>
48 #include "resmgr_srvr.h"
49 #include "resm_internal.h"
50 #include "resmgr_api.h"
51 #include "ss_resm_resourcemanagerlog.h"
53 #include "proc_watch.h"
57 CFrameworkunifiedVersion g_FrameworkunifiedVersion(MAJORNO, MINORNO, REVISION);
58 /**********************************************
59 * Constant definitions
60 **********************************************/
61 #define Resm_Flag_ID_Base EV_Flag_ID_Base(RESMGR_MID)
62 #define RESM_SUB_PRIORITY (0)
64 // #define WTC_CPU_INTERVAL (3)
66 #define CPULOAD_INVALID (-2)
67 #define CPULOAD_READY (-1)
68 #define CPULOG_TIMER_CLEAR (1)
69 #define CPULOG_LOGGING (0)
70 #define CPULOG_NO_LOGGING (-1)
72 #define PROCNET_DEV_FILE "/proc/net/dev"
73 #define MEMINFO_FILE "/proc/meminfo"
74 #define PROC_STAT_FILE "/proc/stat"
76 #define BYTE_TO_KIBIBYTE (1024)
77 #define KIBIBYTE_TO_BYTE (1024)
78 #define PERF_PNAME_MAX 128 // Max path name of process
79 #define PERF_PATH "/usr/bin/perf"
80 #define PERF_FILE "/tmp/perf"
81 #define PERF_DUMP "/tmp/perf_dump"
82 #define PERF_REPORT_DELAY 1 // 1 sec
83 #define PERF_REPORT_RETRY 3 // retry 3 times
84 #define CPULOAD_NICEVAL 10 // value of nice() to lower priority
86 #define DEBUG_INFO_DIRPATH "/tmp/diag_analysis"
87 #define DEBUG_INFO_FPATH DEBUG_INFO_DIRPATH"/dispinfo_resource.dbg"
88 #define DEBUG_INFO_TMPPATH DEBUG_INFO_DIRPATH"/dispinfo_resource.tmp"
89 #define DEBUG_INFO_MEM_LETTERS (25)
90 #define DEBUG_INFO_CPU_TOP_LINES (10)
91 #define DEBUG_INFO_CMA_MIN (160000) // in KB
92 #define DEBUG_INFO_CMA_LETTERS (20)
93 #define DEBUG_INFO_DSP_PG_PATH "/usr/bin/bs_analysis_dispinfo_debug"
95 #define DROP_CACHES_PG_PATH "/usr/bin/drop_caches"
97 #define READLINE_MAX_SIZE 512
98 #define READ_MAX_SIZE 4096
101 /**********************************************
102 * Structure definitions
103 **********************************************/
104 // App session information
107 RESM_REQ_EVENT_t reqEv; // event request
110 // CPU usage information
128 HANDLE hApp; // DispatcherHandle
129 int32_t nsFd; // For receiving from the NSFW
131 // Session information
132 SSN_INFO_t ssnInfo[EV_MAX_IDS_IN_THREAD];
134 // Memory information
135 uint32_t restMem; // Remaining memory information
143 // CPU load information
144 // int32_t cpuloadRate;
153 /**********************************************
154 * External variable definitions
155 **********************************************/
156 // FRAMEWORKUNIFIEDLOG
157 FRAMEWORKUNIFIEDLOGPARAM g_FrameworkunifiedLogParams = {
158 FRAMEWORKUNIFIEDLOGOPTIONS, {
159 ZONE_TEXT_10, ZONE_TEXT_11, ZONE_TEXT_12,
160 ZONE_TEXT_13, ZONE_TEXT_14, ZONE_TEXT_15,
161 ZONE_TEXT_16, ZONE_TEXT_17, ZONE_TEXT_18,
162 ZONE_TEXT_19, ZONE_TEXT_20, ZONE_TEXT_21,
163 ZONE_TEXT_22, ZONE_TEXT_23, ZONE_TEXT_24,
164 ZONE_TEXT_25, ZONE_TEXT_26, ZONE_TEXT_27,
165 ZONE_TEXT_28, ZONE_TEXT_29, ZONE_TEXT_30,
167 }, FRAMEWORKUNIFIEDLOGZONES
170 int isNfs; // NFS env : 1
172 static SVC_COMMON_t g_resmgr; // NOLINT (readability/nolint)
173 static int32_t g_sock = -1;
174 static uint32_t inactFile_kib;
175 static uint32_t mainFree_kib;
176 static uint32_t memTotal_kib;
177 static uint32_t cmaFree_kib;
178 static uint32_t cmaTotal_kib;
179 static uint32_t minRestMem; // Minimum memory available
180 static uint32_t minRestCma; // Minimum CMA available
181 static int32_t g_cpuloadRate1000;
182 static int g_cpu_num;
183 static CPU_INFO_t *g_cpuload_pre;
184 static CPU_INFO_t *g_cpuload;
186 static int32_t g_fifo_status = STATUS_IDOL;
187 static int32_t g_tss_status = STATUS_IDOL;
188 static int32_t g_fifo_timer = 0;
189 static int32_t g_tss_timer = 0;
192 /**********************************************
193 * Local function definition
194 **********************************************/
195 static void ctxCreate(SVC_COMMON_t* p_ctx, int32_t argc, char* argv[]);
198 static int32_t get_new_id(uint32_t* ssnId);
202 static int32_t comp_meminfo_tbl(const void* a, const void* b);
203 static int32_t get_meminfo(void);
205 // Network monitoring
206 static int32_t getInetStatus(RESM_INET_STATUS_t* p_iStatus);
207 static char* get_aliasName(char* name, char* line);
208 static int32_t get_hwaddr(char* name, char* hwaddr);
212 static void watchCPUStatus(void);
213 static void watchCPU(void);
214 static int32_t get_cpuload(CPU_INFO_t* p_cpu);
215 static int32_t calc_cpuloadRate(void);
216 static int32_t calc_cpuloadRate_each(int num);
218 // static int32_t chk_logging(int32_t cpuload, int32_t timer);
219 // static void logging_cpuload(void);
221 static void trim_end(char* buf);
223 // static void escape_percent(char* in, char* out);
224 static void init_cpuload(void);
226 // extern void logging_cpuload_custom(void);
227 static void exec_perf(int32_t t_pid);
228 extern unsigned long logging_cpuload_custom(int32_t tmode);
231 // Debug information output
232 void outputResouceInfo(void);
233 static int write_meminfo_work(FILE *wfp);
234 static int write_cpuinfo_work(FILE *wfp);
235 static int write_cmainfo_work(FILE *wfp);
236 static int write_resourcemanagerloginfo_work(void);
238 /*******************************************************************************
240 *******************************************************************************/
241 /* Event issuance request */
242 RESM_ERR_t RESM_ReqEvent(uint32_t ssnId, const RESM_REQ_EVENT_t* p_reqEvent) {
244 if (p_reqEvent == NULL) {
245 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr ReqEvent Invalid Arg");
249 if (ssnId >= EV_MAX_IDS_IN_THREAD) {
250 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr ReqEvent Invalid Arg");
254 if (!g_resmgr.ssnInfo[ssnId].useFlag) {
255 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr ReqEvent Invalid Arg");
260 if (p_reqEvent->reqEvent == RESM_EV_MEM) {
261 // Record event issuance request
262 memcpy(&g_resmgr.ssnInfo[ssnId].reqEv, p_reqEvent,
263 sizeof(RESM_REQ_EVENT_t));
269 /* Get system status */
270 RESM_ERR_t RESM_GetStatus(uint32_t ssnId, RESM_STATUS_t* p_status) {
274 if (p_status == NULL) {
275 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr GetStatus Invalid Arg");
279 if (ssnId >= EV_MAX_IDS_IN_THREAD) {
280 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr GetStatus Invalid Arg");
284 if (!g_resmgr.ssnInfo[ssnId].useFlag) {
285 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr GetStatus Invalid Arg");
289 if (!g_resmgr.restMemFlag) {
290 // No remaining memory information
291 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr GetStatus get restmem Error"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" // NOLINT[whitespace/line_length]
294 p_status->restMemSize = g_resmgr.restMem;
295 p_status->nandWriteStatus = RESM_NAND_WRITE_ENABLE; //[]Always possible
297 ret = getInetStatus(&p_status->inetStatus);
299 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__,
300 "ResMgr GetStatus getInetStatus Error");
307 /*******************************************************************************
309 *******************************************************************************/
310 /* Session connection */
311 RESM_ERR_t RESM_SV_Open(const RESM_RSV_t* p_prim, uint32_t* p_ssnId) {
314 ret = get_new_id(p_ssnId);
318 // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "ResMgr Open Session:ID=[%d]", *p_ssnId);
323 /* Session disconnection */
324 RESM_ERR_t RESM_SV_Close(uint32_t ssnId) {
326 if (ssnId >= EV_MAX_IDS_IN_THREAD) {
327 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr Close Invalid Arg");
331 if (!g_resmgr.ssnInfo[ssnId].useFlag) {
332 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr Close Invalid Arg");
336 // Turn off used flag
337 g_resmgr.ssnInfo[ssnId].useFlag = FALSE;
339 // Clear event request
340 memset(&g_resmgr.ssnInfo[ssnId].reqEv, 0, sizeof(RESM_REQ_EVENT_t));
345 /* Session ID check */
346 RESM_ERR_t RESM_SV_ChkSsnId(uint32_t ssnId) {
347 if (ssnId >= EV_MAX_IDS_IN_THREAD) {
348 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr ssnId[%d] over MAX", ssnId);
352 if (!g_resmgr.ssnInfo[ssnId].useFlag) {
353 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr ssnId[%d] is unidentified",
361 /**********************************************
362 * Initialization function
363 **********************************************/
364 /* Context Initialization */
365 static void ctxCreate(SVC_COMMON_t* p_ctx, int32_t argc, char* argv[]) {
366 EFrameworkunifiedStatus resourcemanagerRet;
367 FrameworkunifiedDefaultCallbackHandler cbFuncs;
368 FRAMEWORKUNIFIED_MAKE_DEFAULT_CALLBACK(cbFuncs);
369 FRAMEWORKUNIFIED_SET_ZONES();
371 memset(p_ctx, 0, sizeof(SVC_COMMON_t));
372 strcpy(p_ctx->procName, SS_RESOURCE_MANAGER); // NOLINT
374 // Create a Dispatcher
375 resourcemanagerRet = FrameworkunifiedCreateDispatcherWithoutLoop(p_ctx->procName, p_ctx->hApp, argc,
376 argv, &cbFuncs, TRUE);
377 if (resourcemanagerRet != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
378 // LCOV_EXCL_START 4: NSFW error case.
379 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
380 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
381 "[RESM_ERR]ResMgr Create Dispatcher Failed. ret[%d]", resourcemanagerRet);
383 // LCOV_EXCL_STOP 4: NSFW error case.
386 resourcemanagerRet = FrameworkunifiedGetDispatcherFD(p_ctx->hApp, &p_ctx->nsFd);
387 if (resourcemanagerRet != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
388 // LCOV_EXCL_START 4: NSFW error case.
389 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
390 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
391 "[RESM_ERR]ResMgr Get Dispatcher FD Failed. ret[%d]", resourcemanagerRet);
393 // LCOV_EXCL_STOP 4: NSFW error case.
396 // Initialize session
397 memset(p_ctx->ssnInfo, 0, sizeof(p_ctx->ssnInfo));
400 // // Initialize CPU Information
401 // g_resmgr.cpuloadRate = CPULOAD_INVALID;
407 /**********************************************
408 * Get FRAMEWORKUNIFIEDLOG BasePF Flag
409 **********************************************/
410 static EFrameworkunifiedStatus resourcemanagerlog_output_debug_info;
411 #define RESOURCEMANAGERLOG_BASEPF_FLAG_ID (11)
413 EFrameworkunifiedStatus resourcemanagerlog_flag_check(UI_8 *mode) {
414 if (resourcemanagerlog_output_debug_info != eFrameworkunifiedStatusOK)
415 return eFrameworkunifiedStatusFail;
417 return NsLogGetFrameworkunifiedLogFlag(RESOURCEMANAGERLOG_BASEPF_FLAG_ID, mode);
420 /* drop_caches Start update Task */
421 static void start_drop_caches(void) {
424 if (setuid(0) == -1) { // LCOV_EXCL_BR_LINE 5: setuid's error case
425 // LCOV_EXCL_START 5: setuid's error case
426 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
427 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to setuid(0)-1, errno=%d", errno);
430 struct sched_param param;
432 param.sched_priority = 0;
433 if (sched_setscheduler(getpid(), SCHED_OTHER, ¶m) < 0) { // LCOV_EXCL_BR_LINE 5: sched_setscheduler's error case
434 // LCOV_EXCL_START 5: sched_setscheduler's error case
435 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
436 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to sched_setscheduler errno=%d",
440 execl(DROP_CACHES_PG_PATH, basename(DROP_CACHES_PG_PATH), NULL);
441 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to execl %s errno=%d",
448 if (pid == (pid_t) -1) { // LCOV_EXCL_BR_LINE 5: fork's error case
449 // LCOV_EXCL_START 5: fork's error case
450 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
451 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to fork=-1, errno=%d", errno);
456 /**********************************************
458 **********************************************/
459 int32_t main(int32_t argc, char* argv[]) {
460 int32_t mainRet = -1;
463 struct itimerspec tm;
465 struct itimerspec tm2;
469 struct sched_param prcwParam;
475 bool fork_dsp_task = false;
476 CL_ProcessAttr_t attr;
478 const char *args[iProcess_MAXIMUM_NUMBER_OF_PROCESS_ARGUMENTS];
480 EFrameworkunifiedStatus eRet;
483 RPC_ID rpcId = RESMGR_RPC_ID;
484 SVC_COMMON_t* p_ctx = &g_resmgr;
485 EFrameworkunifiedStatus resourcemanagerRet = eFrameworkunifiedStatusOK;
488 const char* nfsenv = getenv("AGL_NFS");
489 isNfs = (nfsenv && strcmp(nfsenv, "y") == 0) ? 1 : 0;
493 ctxCreate(p_ctx, argc, argv);
495 /* Start debug information display task */
498 tmp = getenv("AGL_DEVDIAG_FLAG");
499 if ((tmp == NULL) || strcmp(tmp, "ON")) { // != "ON"
500 resourcemanagerlog_output_debug_info = eFrameworkunifiedStatusFail;
502 resourcemanagerlog_output_debug_info = eFrameworkunifiedStatusOK;
505 eRet = resourcemanagerlog_flag_check(&mode);
506 if (eRet == eFrameworkunifiedStatusOK && mode == FRAMEWORKUNIFIEDLOG_FLAG_MODE_DEBUG) {
507 fork_dsp_task = true;
510 // LCOV_EXCL_START 8: there is no bs_analysis_dispinfo_debug
511 if (0 == stat(DEBUG_INFO_DSP_PG_PATH, &statbuf)) {
512 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
513 if (0 != CL_ProcessCreateAttrInit(&attr)) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
514 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
515 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "CL_ProcessCreateAttrInit Error"); // LCOV_EXCL_LINE 4: NSFW error case.
517 prName = basename(DEBUG_INFO_DSP_PG_PATH);
518 if (0 != CL_ProcessCreateAttrSetName(&attr, prName)) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
519 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
520 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Set Name Error"); // LCOV_EXCL_LINE 4: NSFW error case.
524 if (CL_ProcessCreate(DEBUG_INFO_DSP_PG_PATH, (char* const *) args, NULL,
525 &attr) < 0) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
526 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
527 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "CL_ProcessCreate Error"); // LCOV_EXCL_LINE 4: NSFW error case.
530 // LCOV_EXCL_STOP 8: there is no bs_analysis_dispinfo_debug
534 g_sock = socket(AF_INET, SOCK_DGRAM, 0);
535 if (g_sock < 0) { // LCOV_EXCL_BR_LINE 5: socket error case
536 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
537 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "[RESM_ERR]ResMgr Create Socket Failed"); // LCOV_EXCL_LINE 5: socket error case
540 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "[%s:%d] ResMgr Wakeup", p_ctx->procName,
543 RPC_START_SERVER(rpcId); // Start RPC Server
544 RPC_get_fd(rpcId, &rpcFd); // Event reception FD of RPC
546 /* Create proc_watch thread */
547 ret = pthread_create(&ptPRCW, NULL, &PRCW_main, reinterpret_cast<void*>(NULL));
548 if (ret != 0) { // LCOV_EXCL_BR_LINE 5: pthread_create error case
549 // LCOV_EXCL_START 5: pthread_create error case
550 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
551 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
552 "[RESM_ERR]ResMgr Create Thread Failed. code[%d]", ret);
553 // LCOV_EXCL_STOP 5: pthread_create error case
555 prcwParam.sched_priority = RESM_SUB_PRIORITY;
556 ret = pthread_setschedparam(ptPRCW, SCHED_OTHER, &prcwParam);
557 if (ret != 0) { // LCOV_EXCL_BR_LINE 5: pthread_setschedparam error case
558 // LCOV_EXCL_START 5: pthread_setschedparam error case
559 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
560 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
561 "[RESM_ERR]ResMgr Set Thread Schedparam Failed. code[%d]", ret);
562 // LCOV_EXCL_STOP 5: pthread_setschedparam error case
567 if ((timerFd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC)) == -1) {
568 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
569 "[RESM_ERR]ResMgr Create timerFd Failed. errno[%d]", errno);
574 if ((timerFd2 = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC)) == -1) {
575 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
576 "[RESM_ERR]ResMgr Create timerFd2 Failed. errno[%d]", errno);
581 // Initialize remaining memory acquisition
588 g_resmgr.restMem = mainFree_kib + inactFile_kib;
589 minRestMem = g_resmgr.restMem;
590 g_resmgr.restMemFlag = TRUE;
591 g_resmgr.restCma = cmaFree_kib;
592 minRestCma = g_resmgr.restCma;
593 g_resmgr.restCmaFlag = TRUE;
595 tm.it_value.tv_sec = MONITORING_START_DELAT_TIME;
596 tm.it_value.tv_nsec = 0;
597 tm.it_interval.tv_sec = 1;
598 tm.it_interval.tv_nsec = 0;
599 if (timerfd_settime(timerFd, 0, &tm, NULL) == -1) {
600 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
601 "[RESM_ERR]ResMgr Set timerFd Failed. errno[%d]", errno);
605 tm2.it_value.tv_sec = DROP_CACHES_START_DELAT_TIME;
606 tm2.it_value.tv_nsec = 0;
607 tm2.it_interval.tv_sec = 0;
608 tm2.it_interval.tv_nsec = 0;
609 if (timerfd_settime(timerFd2, 0, &tm2, NULL) == -1) { // LCOV_EXCL_BR_LINE 11:Gcov constraints (coverage measurement revision by DeathTest)
610 // LCOV_EXCL_START 11:Gcov constraints (coverage measurement revision by DeathTest)
611 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
612 "[RESM_ERR]ResMgr Set timerFd2 Failed. errno[%d]", errno);
614 // LCOV_EXCL_END 11:Gcov constraints (coverage measurement revision by DeathTest)
617 /* API to Publish Service Availability Notification. */
618 resourcemanagerRet = FrameworkunifiedPublishServiceAvailability(p_ctx->hApp, TRUE);
619 if (eFrameworkunifiedStatusOK != resourcemanagerRet) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
620 // LCOV_EXCL_START 4: NSFW error case.
621 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
622 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
623 "Failed to Publish Service Availability Notification:0x%x", resourcemanagerRet);
625 // LCOV_EXCL_STOP 4: NSFW error case.
630 g_fifo_status = STATUS_CHECK_CPU;
631 g_tss_status = STATUS_CHECK_CPU;
632 g_cpuloadRate1000 = 0;
634 cpu_ret = get_cpuload(g_cpuload);
635 if ( cpu_ret != 0 ) { // LCOV_EXCL_BR_LINE 200: cpu_ret must be 0
636 // LCOV_EXCL_START 200: cpu_ret must be 0
637 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
638 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "Get cpuload Failed");
639 g_cpuloadRate1000 = 0;
647 maxFd = MY_MAX(maxFd, rpcFd);
649 FD_SET(p_ctx->nsFd, &fds);
650 maxFd = MY_MAX(maxFd, p_ctx->nsFd);
652 FD_SET(timerFd, &fds);
653 maxFd = MY_MAX(maxFd, timerFd);
655 if (timerFd2 != -1) {
656 FD_SET(timerFd2, &fds);
657 maxFd = MY_MAX(maxFd, timerFd2);
659 ret = select(maxFd + 1, &fds, NULL, NULL, NULL);
660 if (ret < 0) { // LCOV_EXCL_BR_LINE 5: select error case
661 // LCOV_EXCL_START 5: select error case
662 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
663 if (errno != EINTR) {
664 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "[RESM_ERR]ResMgr Handle Error");
668 // LCOV_EXCL_STOP 5: select error case
670 /* API CALL from RPC */
671 if ((timerFd2 != -1) && FD_ISSET(timerFd2, &fds)) {
676 /* API CALL from RPC */
677 if (FD_ISSET(rpcFd, &fds)) {
678 RPC_process_API_request(rpcId);
680 /* Events from the NSFW */
681 if (FD_ISSET(p_ctx->nsFd, &fds)) {
682 FrameworkunifiedDispatchProcessWithoutLoop(p_ctx->hApp);
685 /* Timer expiration */
686 if (FD_ISSET(timerFd, &fds)) {
687 read(timerFd, &exp, sizeof(uint64_t));
688 /* CPU load monitoring */
689 if ((sec % WTC_CPU_INTERVAL) == 0) {
693 if (sec >= RESET_SEC) {
709 /*********************************************************************************
711 *********************************************************************************/
712 /* Numbering session ID */
713 static int32_t get_new_id(uint32_t* ssnId) {
715 SSN_INFO_t* p_ssnInfo;
717 for (i = 0; i < EV_MAX_IDS_IN_THREAD; i++) {
718 p_ssnInfo = &g_resmgr.ssnInfo[i];
720 if (p_ssnInfo->useFlag) {
725 p_ssnInfo->useFlag = TRUE;
733 /*********************************************************************************
735 *********************************************************************************/
736 /* Memory monitoring */
737 void watchMem(void) {
739 SSN_INFO_t* p_ssnInfo;
744 // Get remaining memory
750 g_resmgr.restMemFlag = FALSE;
751 g_resmgr.restCmaFlag = FALSE;
754 // [Note] Unit of the value gotten by the meminfo is KiB
755 restMem_b = (mainFree_kib + inactFile_kib) * KIBIBYTE_TO_BYTE;
758 // Failed to get remaining memory info
759 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr get_meminfo Failed");
762 g_resmgr.restMem = mainFree_kib + inactFile_kib;
763 g_resmgr.restMemFlag = TRUE;
764 g_resmgr.restCma = cmaFree_kib;
765 g_resmgr.restCmaFlag = TRUE;
767 if (g_resmgr.restMem < minRestMem) {
768 // Update minimum available memory
769 minRestMem = g_resmgr.restMem;
771 if (g_resmgr.restCma < minRestCma) {
772 // Update minimum available CMA
773 minRestCma = g_resmgr.restCma;
776 for (i = 0; i < RESM_INET_IF_MAX; i++) {
777 p_ssnInfo = &g_resmgr.ssnInfo[i];
778 if (!p_ssnInfo->useFlag) {
785 if (p_ssnInfo->reqEv.reqEvent != RESM_EV_MEM) {
786 // Other than memory monitoring
790 if (p_ssnInfo->reqEv.prm.restMemThresh > restMem_b) {
792 ret = EV_set_flag(Resm_Flag_ID_Base + ssnId, RESM_EV_MEM);
793 if (ret != EV_OK) { // LCOV_EXCL_BR_LINE 200: EV_set_flag will not return ng
794 // LCOV_EXCL_START 200: EV_set_flag will not return ng
795 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
796 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__,
797 "ResMgr EV_set_flag Failed. ssnId[%d]", ssnId);
798 // LCOV_EXCL_STOP 200: EV_set_flag will not return ng
806 void FlushMemInfo(void) {
810 "MEMORY Info(KB):<PEAK>REST(%d) [Memtotal(%d)] / CMA Info(KB):<PEAK>REST(%d) [CMAtotal(%d)]",
811 minRestMem, memTotal_kib, minRestCma, cmaTotal_kib);
814 /* Compare memory information */
815 static int32_t comp_meminfo_tbl(const void* data1, const void* data2) {
816 return strcmp(((const meminfo_tbl*) data1)->name,
817 ((const meminfo_tbl*) data2)->name);
820 /* Get memory information */
821 static int32_t get_meminfo(void) {
822 int32_t meminfo_fd = -1;
825 meminfo_tbl target = { srch_name, NULL };
830 /* Strings must be in ascending order when adding entries to this table (for bsearch) */
831 static const meminfo_tbl mem_table[] = {
832 { "CmaFree", &cmaFree_kib },
833 { "CmaTotal", &cmaTotal_kib },
834 { "Inactive(file)", &inactFile_kib },
835 { "MemFree", &mainFree_kib },
836 { "MemTotal", &memTotal_kib },
838 const int32_t mem_table_count = sizeof(mem_table) / sizeof(meminfo_tbl);
840 if (meminfo_fd == -1) {
841 meminfo_fd = open(MEMINFO_FILE, O_RDONLY);
842 if (meminfo_fd == -1) {
848 lseek(meminfo_fd, 0L, SEEK_SET);
849 read_byte = read(meminfo_fd, buf, sizeof buf - 1);
850 if (read_byte < 0) { // LCOV_EXCL_BR_LINE 200: if file exist, it will not be -1
851 // LCOV_EXCL_START 200: if file exist, it will not be -1
852 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
856 // LCOV_EXCL_STOP 200: if file exis, it will not be -1
858 buf[read_byte] = '\0';
862 tail = strchr(head, ':');
868 if (strlen(head) >= sizeof(srch_name)) {
871 strcpy(srch_name, head); // NOLINT
872 found = reinterpret_cast<meminfo_tbl *>(bsearch(&target, mem_table, mem_table_count,
873 sizeof(meminfo_tbl), comp_meminfo_tbl));
876 *(found->value) = strtoul(head, &tail, 10);
879 tail = strchr(head, '\n');
889 /*********************************************************************************
891 *********************************************************************************/
892 /* Get system information */
893 static int32_t getInetStatus(RESM_INET_STATUS_t* p_iStatus) {
895 char buf[READLINE_MAX_SIZE];
898 char hwaddr[HWADDR_LEN];
916 fh = fopen(PROCNET_DEV_FILE, "r");
918 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__,
919 "ResMgr getInetStatus() File Open Error. errno[%d]", errno);
923 // Initialize interface count
924 p_iStatus->ifNum = 0;
926 while (fgets(buf, sizeof(buf), fh)) {
928 tmp = get_aliasName(name, buf);
933 // Get amount of receive/transmit data
934 ret = sscanf(tmp, "%u%u%u%u%u%u%u%*u%u%u%u%u%u%u%u", &rx_b, &rx_pckt,
935 &rx_err, &rx_drp, &rx_fifo, &rx_frm, &rx_mlt, &tx_b, &tx_pckt,
936 &tx_err, &tx_drp, &tx_fifo, &tx_cll, &tx_crr);
937 if (ret != 14) { // LCOV_EXCL_BR_LINE 200: ret is always 14
938 // LCOV_EXCL_START 200: ret is always 14
939 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
940 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__,
941 "ResMgr getInetStatus() GET Rx and Tx size Failed");
943 // LCOV_EXCL_STOP 200: ret is always 14
945 // Get hardware address
946 ret = get_hwaddr(name, hwaddr);
947 if (ret != 0) { // LCOV_EXCL_BR_LINE 5: get_hwaddr will not return !0
948 // LCOV_EXCL_START 5: get_hwaddr will not return !0
949 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
950 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__,
951 "ResMgr getInetStatus() GET hwaddr Failed");
953 // LCOV_EXCL_STOP 5: get_hwaddr will not return !0
956 // Set values in the system information structure
957 strcpy(p_iStatus->ifInfo[p_iStatus->ifNum].name, name); // NOLINT
958 p_iStatus->ifInfo[p_iStatus->ifNum].rxSize = rx_b / BYTE_TO_KIBIBYTE;
959 p_iStatus->ifInfo[p_iStatus->ifNum].txSize = tx_b / BYTE_TO_KIBIBYTE;
960 memcpy(p_iStatus->ifInfo[p_iStatus->ifNum].hwaddr, hwaddr, HWADDR_LEN);
964 if (p_iStatus->ifNum >= RESM_INET_IF_MAX) {
969 // Termination processing
972 if (p_iStatus->ifNum == 0) {
979 static char *get_aliasName(char* name, char* line) {
983 while (isspace(*line)) {
987 if (isspace(*line)) {
993 dot = line, dotname = name;
996 while (isdigit(*line)) {
1003 if (*line == '\0') {
1016 /* Get hardware address */
1017 static int32_t get_hwaddr(char* name, char* hwaddr) {
1021 if (g_sock < 0) { // LCOV_EXCL_BR_LINE 6: g_sock is not -1
1022 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1023 return -1; // LCOV_EXCL_LINE 6: g_sock is not -1
1026 memset(&ifr, 0, sizeof(ifr));
1029 strncpy(ifr.ifr_name, name, (sizeof(ifr.ifr_name) - 1));
1031 // Get hardware address
1032 ret = ioctl(g_sock, SIOCGIFHWADDR, &ifr);
1033 if (ret < 0) { // LCOV_EXCL_BR_LINE 5: ioctl error case
1034 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1035 return -1; // LCOV_EXCL_LINE 5: ioctl error case
1037 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, HWADDR_LEN);
1042 /*********************************************************************************
1044 *********************************************************************************/
1045 // // CPU monitoring
1046 // static void watchCPU() {
1047 // Main processing of CPU monitoring
1048 static void watchCPUStatus() {
1049 unsigned long fifo_task_occ = 0;
1050 unsigned long tss_task_occ = 0;
1051 int32_t fifo_status = g_fifo_status;
1052 int32_t tss_status = g_tss_status;
1053 int32_t cpu_load_status = CPU_TASK_INIT;
1056 // static int32_t cpuLogTimer = 0;
1057 if ((g_fifo_status == STATUS_CHECK_CPU) || (g_tss_status == STATUS_CHECK_CPU)) {
1060 // if (cpuLogTimer > 0) { // LCOV_EXCL_BR_LINE 6:Because the condition cannot be set
1061 // // Make to progress the timer
1062 // cpuLogTimer -= WTC_CPU_INTERVAL; // LCOV_EXCL_LINE 6:Because the condition cannot be set
1064 if (g_cpuloadRate1000 >= CPU_LOAD_THRESHOLD) {
1065 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "CPU TOTAL:(%d.%d%%)",g_cpuloadRate1000/10, g_cpuloadRate1000%10);
1067 int32_t cpuloadRate1000;
1068 for (i = 1; i < g_cpu_num; i++) {
1070 cpuloadRate1000 = calc_cpuloadRate_each(i);
1071 sprintf (buf, "%s(%d.%d%%) ", g_cpuload[i].cpuname, cpuloadRate1000/10, cpuloadRate1000%10);
1072 FRAMEWORKUNIFIEDLOG (ZONE_INFO, __FUNCTION__, "%s", buf);
1074 if (g_fifo_status == STATUS_CHECK_CPU) { // LCOV_EXCL_BR_LINE 6: g_fifo_status must be STATUS_CHECK_CPU
1075 fifo_status = STATUS_WATCH_PROCESS;
1078 if (g_tss_status == STATUS_CHECK_CPU) { // LCOV_EXCL_BR_LINE 6: g_tss_status must be STATUS_CHECK_CPU
1079 tss_status = STATUS_WATCH_PROCESS;
1082 if ((g_fifo_status != STATUS_WATCH_PROCESS ) && ( g_tss_status != STATUS_WATCH_PROCESS)) { // LCOV_EXCL_BR_LINE 6: g_fifo_status must be STATUS_CHECK_CPU and g_tss_status must be STATUS_CHECK_CPU // NOLINT[whitespace/line_length]
1083 logging_cpuload_custom(CPU_TASK_INIT);
1090 if (g_resmgr.cpuloadRate == CPULOAD_INVALID) {
1093 ret = get_cpuload(g_cpuload);
1094 if (ret == 0) { // LCOV_EXCL_BR_LINE 5: get_cpuload will not return -1
1095 g_resmgr.cpuloadRate = CPULOAD_READY;
1097 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1098 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "watchCPU() Get cpuload Failed"); // LCOV_EXCL_LINE 5: get_cpuload will not return -1 // NOLINT[whitespace/line_length]
1101 if ((g_fifo_status == STATUS_WATCH_PROCESS) || (g_tss_status == STATUS_WATCH_PROCESS)) {
1102 if (g_fifo_status == STATUS_WATCH_PROCESS) {
1103 g_fifo_timer = g_fifo_timer + WTC_CPU_INTERVAL;
1104 if ((g_fifo_timer == WTC_CPU_INTERVAL) || (g_fifo_timer >= FIFO_TIMER_LIMIT)) { // LCOV_EXCL_BR_LINE 200: g_fifo_timer must be bigger than WTC_CPU_INTERVAL/FIFO_TIMER_LIMIT // NOLINT[whitespace/line_length]
1105 cpu_load_status = CPU_TASK_SHOW_AF;
1107 // LCOV_EXCL_START 200: g_fifo_timer must be bigger than WTC_CPU_INTERVAL/FIFO_TIMER_LIMIT
1108 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1109 logging_cpuload_custom(FIFO_TASK_SHOW);
1116 memcpy(g_cpuload_pre, g_cpuload, sizeof(*g_cpuload_pre)*g_cpu_num);
1117 ret = get_cpuload(g_cpuload);
1118 if (ret != 0) { // LCOV_EXCL_BR_LINE 5: get_cpuload will not return -1
1119 // LCOV_EXCL_START 5: get_cpuload will not return -1
1120 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1121 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "watchCPU() Get cpuload Failed");
1123 // LCOV_EXCL_STOP 5: get_cpuload will not return -1
1125 if (g_tss_status == STATUS_WATCH_PROCESS) {
1126 g_tss_timer = g_tss_timer + WTC_CPU_INTERVAL;
1127 if ((g_tss_timer == WTC_CPU_INTERVAL) || (g_tss_timer >= TSS_TIMER_LIMIT)) {
1128 cpu_load_status = CPU_TASK_SHOW_AF;
1130 logging_cpuload_custom(TSS_TASK_SHOW);
1135 // Calculate CPU usage (Notes! Return as a thousandth rate(10 times of %)
1136 g_cpuloadRate1000 = calc_cpuloadRate();
1137 g_resmgr.cpuloadRate = g_cpuloadRate1000 / 10;
1139 ret = chk_logging(g_resmgr.cpuloadRate, cpuLogTimer);
1140 if (ret == CPULOG_LOGGING) {
1143 if (cpu_load_status == CPU_TASK_SHOW_AF) {
1146 int32_t cpuloadRate1000;
1147 char *cpunames = (char *) malloc( // NOLINT
1148 sizeof("[CpuHighLoad]") + (sizeof("cpuXX(xxx%) ") * g_cpu_num));
1149 cpuloadRate1000 = calc_cpuloadRate();
1150 sprintf(cpunames, "[CpuHighLoad]%s(%d%%) ", g_cpuload[0].cpuname, cpuloadRate1000/10); // NOLINT
1151 for (i = 1; i < g_cpu_num; i++) {
1153 cpuloadRate1000 = calc_cpuloadRate_each(i);
1154 sprintf(buf, "%s(%d%%) ", g_cpuload[i].cpuname, cpuloadRate1000 / 10); // NOLINT
1155 strcat(cpunames, buf); // NOLINT
1158 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "%s", cpunames);
1161 logging_cpuload_custom(cpu_load_status);
1163 if (g_fifo_status == STATUS_WATCH_PROCESS) {
1164 fifo_task_occ = logging_cpuload_custom(CPU_FIFO_TASK_GET_OCCUPANCY);
1165 if ((fifo_task_occ >= TASK_STAT_THRESHOLD) && (g_fifo_timer >= FIFO_TIMER_LIMIT)) {
1166 fifo_status = STATUS_IDOL;
1168 exec_perf(logging_cpuload_custom(CPU_FIFO_TASK_GET_ID));
1169 } else if (fifo_task_occ < TASK_STAT_THRESHOLD) {
1170 fifo_status = STATUS_CHECK_CPU;
1172 logging_cpuload_custom(CPU_FIFO_TASK_GET_ID);
1175 if (g_tss_status == STATUS_WATCH_PROCESS) {
1176 tss_task_occ = logging_cpuload_custom(CPU_TSS_TASK_GET_OCCUPANCY);
1177 if ((tss_task_occ >= TASK_STAT_THRESHOLD) && (g_tss_timer >= TSS_TIMER_LIMIT)) {
1178 tss_status = STATUS_IDOL;
1180 exec_perf(logging_cpuload_custom(CPU_TSS_TASK_GET_ID));
1181 } else if(tss_task_occ < TASK_STAT_THRESHOLD) {
1182 tss_status = STATUS_CHECK_CPU;
1184 logging_cpuload_custom(CPU_TSS_TASK_GET_ID);
1188 logging_cpuload_custom();
1191 cpuLogTimer = CPU_HIGH_LOAD_LOG_FREQ;
1192 } else if (ret == CPULOG_TIMER_CLEAR) {
1199 logging_cpuload_custom(CPU_TASK_SHOW_BF);
1201 if ((g_fifo_status == STATUS_IDOL) || (g_tss_status == STATUS_IDOL)) {
1202 if (g_fifo_status == STATUS_IDOL) {
1203 g_fifo_timer = g_fifo_timer + WTC_CPU_INTERVAL;
1204 if (g_fifo_timer >= CPU_HIGH_LOAD_LOG_FREQ) {
1205 fifo_status = STATUS_CHECK_CPU;
1209 if (g_tss_status == STATUS_IDOL) {
1210 g_tss_timer = g_tss_timer + WTC_CPU_INTERVAL;
1211 if (g_tss_timer >= CPU_HIGH_LOAD_LOG_FREQ) {
1212 tss_status = STATUS_CHECK_CPU;
1217 g_fifo_status = fifo_status;
1218 g_tss_status = tss_status;
1230 memcpy(g_cpuload_pre, g_cpuload, sizeof(*g_cpuload_pre)*g_cpu_num);
1231 ret = get_cpuload(g_cpuload);
1233 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "watchCPU() Get cpuload Failed");
1234 g_cpuloadRate1000 = 0;
1236 // Calculate CPU usage (Notes! Return as a thousandth rate(10 times of percentage)
1237 g_cpuloadRate1000 = calc_cpuloadRate();
1244 static void init_cpuload(void) {
1246 char buf[READ_MAX_SIZE];
1251 struct timespec req = { 0, 1000000 }; // 1msec
1254 g_cpuload_pre = NULL;
1256 fd = open(PROC_STAT_FILE, O_RDONLY);
1257 if (fd == -1) { // LCOV_EXCL_BR_LINE 5: open error case
1258 // LCOV_EXCL_START 5: open error case
1259 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1260 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr File Open Error. errno[%d]",
1263 // LCOV_EXCL_STOP 5: open error case
1265 rsize = read(fd, buf, sizeof(buf));
1266 if (rsize == -1) { // LCOV_EXCL_BR_LINE 5: read error case
1267 // LCOV_EXCL_START 5: read error case
1268 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1269 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr File Read Error. errno[%d]",
1273 // LCOV_EXCL_STOP 5: read error case
1275 nanosleep(&req, NULL);
1279 if (strncmp(p, "cpu", 3) == 0) {
1280 ret = sscanf(p, "%8s %d %d %d %d %d %d %d %d %d %d", &p_cpu.cpuname[0],
1281 &p_cpu.user, &p_cpu.nice, &p_cpu.system, &p_cpu.idle,
1282 &p_cpu.iowait, &p_cpu.irq, &p_cpu.softirq, &p_cpu.steal,
1283 &p_cpu.guest, &p_cpu.guest_nice);
1284 if (ret < 11) { // LCOV_EXCL_BR_LINE 200: ret will always 11
1285 // LCOV_EXCL_START 200: ret will always 11
1286 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1287 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__,
1288 "ResMgr get_cpuload() File Read Error");
1291 // LCOV_EXCL_STOP 200: ret will always 11
1306 g_cpuload_pre = reinterpret_cast<CPU_INFO_t *>(malloc(sizeof(CPU_INFO_t) * g_cpu_num));
1307 g_cpuload = reinterpret_cast<CPU_INFO_t *>(malloc(sizeof(CPU_INFO_t) * g_cpu_num));
1308 if ((g_cpuload_pre == NULL) || (g_cpuload == NULL)) { // LCOV_EXCL_BR_LINE 5: malloc error case
1309 // LCOV_EXCL_START 5: malloc error case
1310 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1311 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__,
1312 "ResMgr malloc Error. g_cpu_num[%d] errno[%d]", g_cpu_num, errno);
1314 // LCOV_EXCL_STOP 5: malloc error case
1317 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr cpu_num:%d", g_cpu_num);
1323 static int32_t get_cpuload(CPU_INFO_t* p_cpu) {
1325 char buf[READ_MAX_SIZE];
1330 struct timespec req = { 0, 1000000 }; // 1msec
1333 fd = open(PROC_STAT_FILE, O_RDONLY);
1334 if (fd == -1) { // LCOV_EXCL_BR_LINE 5: open's error case
1335 // LCOV_EXCL_START 5: open's error case
1336 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1337 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__,
1338 "ResMgr get_cpuload() File Open Error. errno[%d]", errno);
1342 rsize = read(fd, buf, sizeof(buf));
1343 if (rsize == -1) { // LCOV_EXCL_BR_LINE 5: read error case
1344 // LCOV_EXCL_START 5: read error case
1345 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1346 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr File Read Error. errno[%d]",
1350 // LCOV_EXCL_STOP 5: read error case
1352 nanosleep(&req, NULL);
1356 if (strncmp(p, "cpu", 3) == 0) {
1357 ret = sscanf(p, "%8s %d %d %d %d %d %d %d %d %d %d", &p_cpu[i].cpuname[0],
1358 &p_cpu[i].user, &p_cpu[i].nice, &p_cpu[i].system,
1359 &p_cpu[i].idle, &p_cpu[i].iowait, &p_cpu[i].irq,
1360 &p_cpu[i].softirq, &p_cpu[i].steal, &p_cpu[i].guest,
1361 &p_cpu[i].guest_nice);
1362 if (ret < 11) { // LCOV_EXCL_BR_LINE 200: ret will always 11
1363 // LCOV_EXCL_START 200: ret will always 11
1364 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1365 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__,
1366 "ResMgr get_cpuload() File Read Error");
1369 // LCOV_EXCL_STOP 200: ret will always 11
1387 // Calcurate CPU usage
1388 static int32_t calc_cpuloadRate(void) {
1394 CPU_INFO_t* info_pre;
1396 info = &g_cpuload[0];
1397 info_pre = &g_cpuload_pre[0];
1399 val = (info->user - info_pre->user)
1400 + (info->system - info_pre->system)
1401 + (info->irq - info_pre->irq)
1402 + (info->softirq - info_pre->softirq);
1404 val_others = (info->idle - info_pre->idle)
1405 + (info->iowait - info_pre->iowait);
1407 total = val + val_others;
1408 rate = (total > 0) ? (val*1000 / total) : 0;
1413 // Calcurate CPU usage for each CPU
1414 static int32_t calc_cpuloadRate_each(int num) {
1418 CPU_INFO_t* info_pre;
1421 info = &g_cpuload[0];
1422 info_pre = &g_cpuload_pre[0];
1423 val = (info->user - info_pre->user)
1424 + (info->system - info_pre->system)
1425 + (info->irq - info_pre->irq)
1426 + (info->softirq - info_pre->softirq);
1429 info = &g_cpuload[num];
1430 info_pre = &g_cpuload_pre[num];
1431 valn = (info->user - info_pre->user)
1432 + (info->system - info_pre->system)
1433 + (info->softirq - info_pre->softirq);
1435 rate = valn * 1000 / val;
1440 //// Logging check at CPU overload
1441 //static int32_t chk_logging(int32_t cpuload, int32_t timer) {
1442 // if (cpuload >= CPU_LOAD_THRESHOLD) {
1444 // return CPULOG_NO_LOGGING;
1446 // return CPULOG_LOGGING;
1449 // return CPULOG_TIMER_CLEAR;
1453 // Check if cmd to perf
1454 // LCOV_EXCL_START 8: dead code
1455 bool valid_perf_cmd(char *buf) { // LCOV_EXCL_BR_LINE 8: dead code
1456 const char *cmd2exclude[] = { "top", "init", "bash", NULL };
1459 for (int i = 0;; i++) {
1460 if (cmd2exclude[i] == NULL) {
1463 sprintf(cmdstr, " %s ", cmd2exclude[i]); // NOLINT
1464 if (strstr(buf, cmdstr) == NULL) {
1472 // LCOV_EXCL_STOP 8: dead code
1474 //// exec perf to pids
1475 //static pid_t pids[PERF_MAX_PROCS];
1478 static bool lower_sched_priority(int niceval) {
1479 struct sched_param sparam = { };
1480 sparam.sched_priority = 0;
1481 if (sched_setscheduler(0, SCHED_OTHER, &sparam) == -1) { // LCOV_EXCL_BR_LINE 5: sched_setscheduler's error case
1482 // LCOV_EXCL_START 5: sched_setscheduler's error case
1483 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1484 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed change scheduler to TSS, errno=%d",
1489 if (nice(niceval) == -1) { // LCOV_EXCL_BR_LINE 5: nice's error case
1490 // LCOV_EXCL_START 5: nice's error case
1491 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1492 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to add nice val %d, errno=%d",
1500 /*********************************************************************************
1501 * exec_perf sub function RECORD perf data processing
1502 *********************************************************************************/
1503 static void exec_perf_Record_Perf_Data(
1504 pid_t* c_pids, char* perf_file, char* pidstr, int* status,
1506 // char pnames[PERF_MAX_PROCS][PERF_PNAME_MAX]) {
1507 pid_t pids[PERF_MAX_PROCS]) {
1513 bool do_sigkill = false;
1515 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "+");
1517 /* RECORD perf data */
1518 for (i = 0; i < PERF_MAX_PROCS; i++) {
1522 sprintf(perf_file, PERF_FILE"%06d", pids[i]); // NOLINT
1523 sprintf(pidstr, "%d", pids[i]); // NOLINT
1524 if ((c_pids[i] = fork()) == 0) {
1525 if (lower_sched_priority(CPULOAD_NICEVAL) == false) { // LCOV_EXCL_BR_LINE 200: lower_sched_priority() must be true
1526 // LCOV_EXCL_START 200: lower_sched_priority() must be true
1527 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1528 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to lower scheduler-1");
1532 if (setuid(0) == -1) { // LCOV_EXCL_BR_LINE 5: setuid's error case
1533 // LCOV_EXCL_START 5: setuid's error case
1534 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1535 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to setuid(0)-1, errno=%d",
1541 fd = open("/dev/null", O_WRONLY);
1542 if (fd > 0) { // LCOV_EXCL_BR_LINE 5: open's error case
1546 execl(PERF_PATH, basename(PERF_PATH), "record", "-p", pidstr, "-o",
1548 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to execl %s record, errno=%d",
1553 if (c_pids[i] == (pid_t) -1) { // LCOV_EXCL_BR_LINE 5: fork's error case
1554 // LCOV_EXCL_START 5: fork's error case
1555 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1556 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to fork-1, errno=%d", errno);
1560 // Kill perf after PERF_RECORD_SPAN sec
1561 // (Killed by child process to avoid making resm process super-user with setuid.)
1562 if ((term_pid = fork()) == 0) {
1563 const struct timespec delay = { PERF_RECORD_SPAN, 0 };
1564 if (setuid(0) == -1) { // LCOV_EXCL_BR_LINE 5: setuid's error case
1565 // LCOV_EXCL_START 5: setuid's error case
1566 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1567 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to setuid(0)-2, errno=%d",
1572 nanosleep(&delay, NULL); // Let perf record run for a while before kill it.
1573 if (kill(c_pids[i], SIGINT) == -1) { // LCOV_EXCL_BR_LINE 5: kill's error case
1574 // LCOV_EXCL_START 5: kill's error case
1575 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1576 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1577 "Failed to kill(SIGINT), pid=%d, errno=%d", (int) c_pids[i],
1581 nanosleep(&delay, NULL); // Allow perf to do ending procedure.
1583 } else if (term_pid == (pid_t) -1) { // LCOV_EXCL_BR_LINE 5: fork's error case
1584 // LCOV_EXCL_START 5: fork's error case
1585 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1586 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to fork-2, errno=%d", errno);
1590 if (waitpid(term_pid, status, 0) == -1) { // LCOV_EXCL_BR_LINE 5: waitpid's error case
1591 // LCOV_EXCL_START 5: waitpid's error case
1592 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1593 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1594 "Failed to waitpid of killer %d, errno=%d", term_pid, errno);
1599 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "");
1600 // NOT block even if perf is not terminated
1601 if ((waitret = waitpid(c_pids[i], status, WNOHANG)) == -1) { // LCOV_EXCL_BR_LINE 5: waitpid's error case
1602 // LCOV_EXCL_START 5: waitpid's error case
1603 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1604 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to waitpid of RECORD %d, errno=%d",
1607 } else if (waitret == 0) {
1609 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to terminate perf record, pid=%d",
1611 pids[i] = -2; // Skip following sequences
1613 } else if (WEXITSTATUS(*status) != 0 && WEXITSTATUS(*status) != 2) {
1615 // FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1616 // "perf record %d exited abnormally, target=%s(%d), status=%d",
1617 // c_pids[i], pnames[i], pids[i], WEXITSTATUS(*status));
1618 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1619 "perf record %d exited abnormally, target=(%d), status=%d",
1620 c_pids[i], pids[i], WEXITSTATUS(*status));
1622 pids[i] = -2; // Skip following sequences
1625 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "");
1626 if (pids[i] == -2) {
1627 if ((term_pid = fork()) == 0) {
1628 const struct timespec delay = { PERF_RECORD_SPAN, 0 };
1629 if (setuid(0) == -1) { // LCOV_EXCL_BR_LINE 5: setuid's error case
1630 // LCOV_EXCL_START 5: setuid's error case
1631 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1632 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to setuid(0)-2B, errno=%d",
1637 // Kill "perf record" by SIGKILL signal
1639 int sigret = kill(c_pids[i], SIGKILL);
1640 if (sigret == 0) { // LCOV_EXCL_BR_LINE 5: kill case
1641 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1642 "SIGKILL has been sent to perf record process, pid=%d",
1645 // LCOV_EXCL_START 5: kill case
1646 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1647 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1648 "sending SIGKILL to perf record failed, pid=%d, errno=%d",
1650 // LCOV_EXCL_STOP 5: kill case
1653 nanosleep(&delay, NULL);
1654 // remove perf data file possibly made
1656 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "");
1658 } else if (term_pid == (pid_t) -1) { // LCOV_EXCL_BR_LINE 5: fork's error case
1659 // LCOV_EXCL_START 5: fork's error case
1660 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1661 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to fork-2B, errno=%d", errno);
1664 if (waitpid(term_pid, status, 0) == -1) { // LCOV_EXCL_BR_LINE 5: waitpid's error case
1665 // LCOV_EXCL_START 5: waitpid's error case
1666 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1667 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1668 "Failed to waitpid of killer-2 %d, errno=%d", term_pid, errno);
1672 if ((waitret = waitpid(c_pids[i], status, WNOHANG)) == -1) { // LCOV_EXCL_BR_LINE 5: waitpid's error case
1673 // LCOV_EXCL_START 5: waitpid's error case
1674 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1675 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1676 "Failed to waitpid of RECORD(2) %d, errno=%d", c_pids[i],
1679 } else if (waitret == 0) {
1680 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1681 "Failed to terminate perf record by SIGKILL, pid=%d",
1688 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "");
1691 /*********************************************************************************
1692 * exec_perf sub function make perf file available to default user processing
1693 *********************************************************************************/
1695 //static int32_t exec_perf_Make_Perf_File(pid_t* c_pids, char* perf_file) {
1696 static int32_t exec_perf_Make_Perf_File(pid_t* c_pids, char* perf_file, pid_t pids[PERF_MAX_PROCS]) {
1700 /* make perf file available to default user */
1701 if ((c_pids[0] = fork()) == 0) {
1702 if (setuid(0) == -1) { // LCOV_EXCL_BR_LINE 5: setuid's error case
1703 // LCOV_EXCL_START 5: setuid's error case
1704 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1705 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to setuid(0)-3, errno=%d", errno);
1709 for (i = 0; i < PERF_MAX_PROCS; i++) {
1710 if (pids[i] == -2) {
1711 // killed by SIGKILL
1717 sprintf(perf_file, PERF_FILE"%06d", pids[i]); // NOLINT
1718 if (chmod(perf_file, 0666) != 0) { // LCOV_EXCL_BR_LINE 5: chmod's error case
1719 // LCOV_EXCL_START 5: chmod's error case
1720 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1721 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to chmod %s, errno=%d\n",
1728 if (c_pids[0] == (pid_t) -1) { // LCOV_EXCL_BR_LINE 5: fork's error case
1729 // LCOV_EXCL_START 5: fork's error case
1730 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1731 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to fork-3, errno=%d", errno);
1735 if (waitpid(c_pids[0], NULL, 0) == -1) { // LCOV_EXCL_BR_LINE 5: waitpid's error case
1736 // LCOV_EXCL_START 5: waitpid's error case
1737 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1738 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to waitpid of CHMOD %d, errno=%d\n",
1742 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "");
1746 /*********************************************************************************
1747 * exec_perf sub function REPORT perf data into dump file processing
1748 *********************************************************************************/
1749 static void exec_perf_Report_Perf_Data(pid_t* c_pids, char* perf_file,
1751 // char* perf_dump, int* status) {
1752 char* perf_dump, int* status, pid_t pids[PERF_MAX_PROCS]) {
1758 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "");
1759 /* REPORT perf data into dump file */
1760 for (i = 0; i < PERF_MAX_PROCS; i++) {
1761 const struct timespec delay = { PERF_REPORT_DELAY, 0 };
1762 if (pids[i] == -2) {
1763 // killed by SIGKILL
1769 sprintf(perf_file, PERF_FILE"%06d", pids[i]); // NOLINT
1770 sprintf(perf_dump, PERF_DUMP"%06d", pids[i]); // NOLINT
1771 if ((c_pids[i] = fork()) == 0) {
1772 if (lower_sched_priority(CPULOAD_NICEVAL) == false) { // LCOV_EXCL_BR_LINE 200: lower_sched_priority() will not return false
1773 // LCOV_EXCL_START 200: lower_sched_priority() will not return false
1774 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1775 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to lower scheduler-2");
1779 if ((fd = open(perf_dump, (O_CREAT | O_WRONLY), 0666)) < 0) { // LCOV_EXCL_BR_LINE 5: open error case
1780 // LCOV_EXCL_START 5: open error case
1781 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1782 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to open %s, errno=%d\n",
1784 // LCOV_EXCL_STOP 5: open error case
1790 fd = open("/dev/null", O_WRONLY);
1791 if (fd > 0) { // redirect stderr // LCOV_EXCL_BR_LINE 5: open's error case
1796 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "execl perf report");
1797 execl(PERF_PATH, basename(PERF_PATH), "report", "-i", perf_file, NULL);
1798 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to execl %s report, errno=%d",
1804 if (c_pids[i] == (pid_t) -1) { // LCOV_EXCL_BR_LINE 5: fork's error case
1805 // LCOV_EXCL_START 5: fork's error case
1806 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1807 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to fork-4, errno=%d", errno);
1812 for (; ii < PERF_REPORT_RETRY; ii++) {
1813 nanosleep(&delay, NULL); // Make sure waitpid() to killer returns after perf process exited.
1814 if ((waitret = waitpid(c_pids[i], status, WNOHANG)) == -1) { // LCOV_EXCL_BR_LINE 5: waitpid's error case
1815 // LCOV_EXCL_START 5: waitpid's error case
1816 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1817 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1818 "Failed to waitpid for REPORT %d, errno=%d", c_pids[i], errno);
1819 pids[i] = -2; // Skip FRAMEWORKUNIFIEDLOG perf data
1822 } else if (waitret == c_pids[i]) {
1826 if (ii >= PERF_REPORT_RETRY) {
1827 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "perf report Failed to exit, pid=%d",
1829 pids[i] = -2; // Skip FRAMEWORKUNIFIEDLOG perf data
1831 if (pids[i] == -2) {
1832 // Terminate perf report with SIGKILL
1833 const struct timespec delay = { PERF_RECORD_SPAN, 0 };
1834 int sigret = kill(c_pids[i], SIGKILL);
1835 if (sigret != 0) { // LCOV_EXCL_BR_LINE 5: kill's error case
1836 // LCOV_EXCL_START 5: kill's error case
1837 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1838 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1839 "Failed in sending SIGKILL to perf report, pid=%d, errno=%d",
1843 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1844 "SIGKILL has been sent to perf report process, pid=%d",
1847 nanosleep(&delay, NULL); // Make sure waitpid() to killer returns after perf process exited.
1848 if ((waitret = waitpid(c_pids[i], status, WNOHANG)) == -1) { // LCOV_EXCL_BR_LINE 5: waitpid's error case
1849 // LCOV_EXCL_START 5: waitpid's error case
1850 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1851 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1852 "Failed to waitpid of REPORT(2) %d, errno=%d", c_pids[i], errno);
1854 } else if (waitret == 0) {
1855 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1856 "Failed to terminate perf report by SIGKILL, pid=%d", c_pids[i]);
1865 /*********************************************************************************
1866 * exec_perf FRAMEWORKUNIFIEDLOG perf data processing
1867 *********************************************************************************/
1868 static void exec_perf_Resourcemanagerlog_Perf_Data(
1869 char* perf_file, char* perf_dump,
1871 // char pnames[PERF_MAX_PROCS][PERF_PNAME_MAX]) {
1872 pid_t pids[PERF_MAX_PROCS]) {
1876 char buf[READLINE_MAX_SIZE];
1879 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "");
1880 /* FRAMEWORKUNIFIEDLOG perf data */
1881 for (i = 0; i < PERF_MAX_PROCS; i++) {
1882 if (pids[i] == -2) {
1883 // killed by SIGKILL
1889 sprintf(perf_file, PERF_FILE"%06d", pids[i]); // NOLINT
1890 sprintf(perf_dump, PERF_DUMP"%06d", pids[i]); // NOLINT
1891 if ((rfd = fopen(perf_dump, "r")) == NULL) { // LCOV_EXCL_BR_LINE 5: fopen error case
1892 // LCOV_EXCL_START 5: fopen error case
1893 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1894 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to open-2 %s, errno=%d\n",
1897 // LCOV_EXCL_STOP 5: fopen error case
1900 while (fgets(buf, sizeof(buf), rfd) != NULL) {
1901 if (perf_lines >= PERF_MAX_LINES) {
1905 if (buf[0] == '#') {
1908 if (buf[0] == '\n' || buf[0] == '\r') {
1912 if (perf_lines == 0) {
1914 // FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "[CpuHLPerf:%s(%d)]report by result of 'perf record -p %d'",
1915 // pnames[i], pids[i], pids[i]);
1916 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "[CpuHLPerf:(%d)]report by result of 'perf record -p %d'",
1920 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "[CpuHLPerf]%s\n", buf);
1924 // Check if no line is acquired
1925 if (perf_lines == 0) {
1927 // FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "[CpuHLPerf:%s(%d)] NO_DATA_acquired",
1928 // pnames[i], pids[i]);
1929 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "[CpuHLPerf:(%d)] NO_DATA_acquired",
1937 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "-");
1940 /*********************************************************************************
1941 * exec_perf Main processing
1942 *********************************************************************************/
1944 //static void exec_perf(char pnames[PERF_MAX_PROCS][PERF_PNAME_MAX]) {
1945 static void exec_perf(int32_t t_pid) {
1947 pid_t c_pids[PERF_MAX_PROCS]; // max process to exec perf(forked child pids)
1949 pid_t pids[PERF_MAX_PROCS];
1950 char perf_file[128];
1951 char perf_dump[128];
1953 struct stat statbuf;
1956 /* Check existance of perf exec file */
1957 if (stat(PERF_PATH, &statbuf) == -1 || !(statbuf.st_mode & S_IXUSR)) {
1958 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "%s is not available", PERF_PATH);
1962 FRAMEWORKUNIFIEDLOG (ZONE_INFO, __FUNCTION__, "[CpuHighLoad]Please check User backtrace of following processes in kernel.log");
1963 // print_backtrace_pid(t_pid);
1964 for (int i = 0; i < PERF_MAX_PROCS; i++) {
1971 /* RECORD perf data */
1973 // exec_perf_Record_Perf_Data(c_pids, perf_file, pidstr, &status, pnames);
1974 exec_perf_Record_Perf_Data(c_pids, perf_file, pidstr, &status, pids);
1977 /* make perf file available to default user */
1979 // if (exec_perf_Make_Perf_File(c_pids, perf_file) != 0)
1980 if (exec_perf_Make_Perf_File(c_pids, perf_file, pids) != 0)
1984 /* REPORT perf data into dump file */
1986 // exec_perf_Report_Perf_Data(c_pids, perf_file, perf_dump, &status);
1987 exec_perf_Report_Perf_Data(c_pids, perf_file, perf_dump, &status, pids);
1990 /* FRAMEWORKUNIFIEDLOG perf data */
1992 // exec_perf_Resourcemanagerlog_Perf_Data(perf_file, perf_dump, pnames);
1993 exec_perf_Resourcemanagerlog_Perf_Data(perf_file, perf_dump, pids);
1997 // Logging at CPU overload
1998 #define WAIT_RETRY 3 // 3sec
2002 static void logging_cpuload(void) {
2003 int32_t pipe_fd[2]; // 0:stdin,1:stdout
2005 char buf[READLINE_MAX_SIZE];
2006 char buf2[READLINE_MAX_SIZE];
2007 char tmp[READLINE_MAX_SIZE];
2008 int32_t logLine = 0;
2012 int32_t perfNum = 0;
2013 char pnames[PERF_MAX_PROCS][PERF_PNAME_MAX] = { };
2018 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "+");
2021 ret = pipe(pipe_fd);
2023 if (ret != 0) { // LCOV_EXCL_BR_LINE 5: pipe error case
2024 // LCOV_EXCL_START 5: pipe error case
2025 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2026 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__,
2027 "ResMgr logging_cpuload() pipe Error");
2029 // LCOV_EXCL_STOP 5: pipe error case
2032 // Create child process
2034 if (c_pid < 0) { // LCOV_EXCL_BR_LINE 5: fork error case
2035 // LCOV_EXCL_START 5: fork error case
2036 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2037 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__,
2038 "ResMgr logging_cpuload() fork Error");
2043 // LCOV_EXCL_STOP 5: fork error case
2047 /*******************************************************
2049 * The use of dup() and Close() between fork()-> exec() has been
2050 * confirmed no probrem.
2051 *******************************************************/
2052 if (lower_sched_priority(CPULOAD_NICEVAL) == false) {
2053 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to lower scheduler");
2056 close(pipe_fd[0]); // Unneeded pipes (close stdin)
2058 close(1); // Close stdout
2059 dup2(pipe_fd[1], 1); // Duplicate stdout to pipe_fd[1]
2062 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "execl top");
2063 execl("/usr/bin/top", "top", "-n", "1", "-b", NULL);
2065 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "ResMgr logging_cpuload() execl Error");
2068 close(pipe_fd[1]); // Unneeded pipes(Close stdout)
2071 close(0); // Close stdin
2072 dup2(pipe_fd[0], 0); // Duplicate stdin to pipe_fd[0]
2075 for (int i = 0; i < PERF_MAX_PROCS; i++) {
2083 struct timeval tmout = { TOP_TIMEOUT, 0 };
2086 FD_SET(STDIN_FILENO, &fds);
2087 maxFd = STDIN_FILENO;
2088 ret = select(maxFd + 1, &fds, NULL, NULL, &tmout);
2089 if (ret < 0) { // LCOV_EXCL_BR_LINE 5: select error case
2090 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2091 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "[RESM]Handle Error errno:%d", errno); // LCOV_EXCL_LINE 5: select error case
2092 } else if (FD_ISSET(STDIN_FILENO, &fds)) {
2095 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2096 "[RESM]'top': No response during %d seconds", TOP_TIMEOUT);
2099 // Kill top after TOP_TIMEOUT sec
2100 // (Killed by child process to avoid making resm process super-user with setuid.)
2101 if (kill(c_pid, SIGKILL) == -1) { // LCOV_EXCL_BR_LINE 5: kill error case
2102 // LCOV_EXCL_START 5: kill error case
2103 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2104 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2105 "Failed to kill(SIGKILL), pid=%d, errno=%d", (int) c_pid,
2107 // LCOV_EXCL_STOP 5: kill error case
2110 while (fgets(buf, sizeof(buf), stdin) != NULL) {
2111 // Save ProcessName and Process ID to exec perf
2112 if (logLine >= 2 && perfNum < PERF_MAX_PROCS) {
2114 strncat(buf2, buf, sizeof(buf2) - 1);
2115 buf2[sizeof(buf2) - 1] = 0;
2116 if (valid_perf_cmd(buf2)) {
2117 pids[perfNum] = atoi(buf2);
2119 strncat(pnames[perfNum], rindex(buf2, ' ') + 1,
2120 sizeof(pnames[0]) - 1);
2121 if (pids[perfNum] >= 0
2122 && strnlen(pnames[perfNum], sizeof(pnames[perfNum]) - 1)) {
2130 if ((buf[0] != 'C') && (buf[0] != '%')) {
2133 ptr = strstr(buf, "sy");
2137 while (isalpha(*ptr)) {
2141 escape_percent(buf, tmp);
2142 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "[CpuHighLoad]%s", tmp);
2144 } else if (logLine == 1) {
2145 ptr = strstr(buf, "PID");
2150 escape_percent(buf, tmp);
2151 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "[CpuHighLoad]%s", tmp);
2153 } else if (logLine < (CPU_HIGH_LOAD_P_LOG_NUM + 2)) {
2155 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "[CpuHighLoad]%s", buf);
2161 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "wait pid(%d) kill_flag(%d)", c_pid, kill_flag);
2163 const struct timespec delay = {1, 0};
2165 for (i = 0; i < WAIT_RETRY; i++) {
2166 nanosleep(&delay, NULL);
2167 if ((waitret = waitpid(c_pid, &status, WNOHANG)) == -1) {
2168 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to waitpid for top %d, errno=%d", c_pid, errno);
2170 } else if (waitret == c_pid) {
2171 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "waitpid OK");
2175 if (i >= WAIT_RETRY) {
2176 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "top Failed to exit, pid=%d", c_pid);
2179 if ((waitret = waitpid(static_cast<int>(c_pid), &status, 0)) < 0) {
2180 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "waitpid(%d) Error errno(%d)", c_pid, errno);
2183 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "waitpid(%d) returned (%d) errno(%d) status=%d",
2184 c_pid, waitret, errno, WEXITSTATUS(*status));
2186 dup2(save_0, 0); // Reset the stdin to 0
2193 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "-");
2201 static void trim_end(char* buf) {
2206 if (isspace(buf[len - 1])) {
2207 buf[len - 1] = '\0';
2219 // Escape character "%"
2220 static void escape_percent(char* in, char* out) {
2229 tail = strchr(head, '%');
2231 strcat(out, head); // NOLINT
2236 strcat(out, head); // NOLINT
2237 strcat(out, "%%"); // NOLINT
2248 /*********************************************************************************
2249 * Output debug information display
2250 *********************************************************************************/
2251 void outputResouceInfo(void) {
2252 static bool madedir = false;
2258 if (stat(DEBUG_INFO_DIRPATH, &sbuf) != 0) { // LCOV_EXCL_BR_LINE 5: stat's error case
2259 if (mkdir(DEBUG_INFO_DIRPATH, 0777) != 0) { // LCOV_EXCL_BR_LINE 5: mkdir's error case
2260 // LCOV_EXCL_START 5: mkdir's error case
2261 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2262 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to mkdir %s, errno=%d",
2271 // Open files to work
2272 if ((wfp = fopen(DEBUG_INFO_TMPPATH, "w")) == NULL) { // LCOV_EXCL_BR_LINE 5: fopen error case
2273 // LCOV_EXCL_START 5: fopen error case
2274 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2275 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to open %s, errno=%d",
2279 // LCOV_EXCL_STOP 5: fopen error case
2281 // Output memory information work
2282 if (write_meminfo_work(wfp) != 0) { // LCOV_EXCL_BR_LINE 6: write_meminfo_work will not be error
2283 // LCOV_EXCL_START 6: write_meminfo_work will not be error
2284 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2285 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2286 "Failed to edit and output in write_meminfo_work()");
2289 // LCOV_EXCL_STOP 6: write_meminfo_work will not be error
2291 // Get CMA MEMORY information and output working info
2292 if (write_cmainfo_work(wfp) != 0) { // LCOV_EXCL_BR_LINE 6: write_cmainfo_work will not be error
2293 // LCOV_EXCL_START 6: write_cmainfo_work will not be error
2294 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2295 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2296 "Failed to edit and output in write_cmainfo_work()");
2299 // LCOV_EXCL_STOP 6: write_cmainfo_work will not be error
2301 // Get top information and output work info
2302 if (write_cpuinfo_work(wfp) != 0) { // LCOV_EXCL_BR_LINE 6: write_cpuinfo_work will not be error
2303 // LCOV_EXCL_START 6: write_cpuinfo_work will not be error
2304 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2305 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2306 "Failed to edit and output in write_cpuinfo_work()");
2309 // LCOV_EXCL_STOP 6: write_cpuinfo_work will not be error
2312 // Create output file
2313 if (rename(DEBUG_INFO_TMPPATH, DEBUG_INFO_FPATH) != 0) { // LCOV_EXCL_BR_LINE 5:rename error case
2314 // LCOV_EXCL_START 5:rename error case
2315 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2316 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to make output file %s, errno=%d",
2319 // LCOV_EXCL_STOP 5:rename error case
2321 // Write information and output FRAMEWORKUNIFIEDLOG
2322 if (write_resourcemanagerloginfo_work() != 0) { // LCOV_EXCL_BR_LINE 6: write_resourcemanagerloginfo_work will not be error
2323 // LCOV_EXCL_START 6: write_resourcemanagerloginfo_work will not be error
2324 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2325 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2326 "Failed to output in write_resourcemanagerloginfo_work()");
2327 // LCOV_EXCL_STOP 6: write_resourcemanagerloginfo_work will not be error
2331 // Output memory information work
2332 static int write_meminfo_work(FILE *wfp) {
2338 uint32_t used_letters;
2339 // Output meminfo: Getting info from the proc/meminfo is performed at 5-second intervals in watchMem, so it is diverted.
2340 avail = static_cast<float>((mainFree_kib + inactFile_kib));
2341 total = static_cast<float>(memTotal_kib);
2342 used = total - avail;
2343 min_remain = static_cast<float>(minRestMem);
2344 // "*MEMORY @@@@@@ Warning!! @@@@@"
2345 fprintf(wfp, "*MEMORY");
2346 if (avail * 10 < total) { // (Less than 1/10)
2347 fprintf(wfp, " @@@@@@ Warning!! @@@@@\n");
2349 fprintf(wfp, " \n");
2351 // "used/avail/total/used max xxx.xMB / xxx.xMB / xxx.xMB(xx.x%) / xxx.xMB
2359 used_rate = (uint32_t) (used * 1000 / total);
2360 if (used_rate >= 1000) {
2366 " used/avail/total/min remain %5.1fMB / %5.1fMB / %5.1fMB(%2d.%d%%) / %5.1fMB\n",
2367 used, avail, total, used_rate / 10, used_rate % 10, min_remain);
2371 used_letters = (uint32_t) (DEBUG_INFO_MEM_LETTERS * used / total);
2372 if (used_letters > DEBUG_INFO_MEM_LETTERS) {
2373 used_letters = DEBUG_INFO_MEM_LETTERS;
2376 // "------------------*******"
2378 for (i = 0; i < static_cast<int>(used_letters); i++) {
2381 for (; i < DEBUG_INFO_MEM_LETTERS; i++) {
2384 fprintf(wfp, "\n\n");
2388 // Get top information and Output work
2389 static int write_cpuinfo_work(FILE *wfp) {
2390 int32_t pipe_fd[2]; // 0:stdin,1:stdout
2392 char buf[READLINE_MAX_SIZE];
2393 int32_t logLine = 0;
2399 char fields[12][128];
2404 cpu_rate = g_cpuloadRate1000 < 0 ? 0 : g_cpuloadRate1000;
2405 fprintf(wfp, "*CPU %2d.%d%%\n", cpu_rate / 10, cpu_rate % 10);
2408 ret = pipe(pipe_fd);
2410 if (ret != 0) { // LCOV_EXCL_BR_LINE 5: pipe error case
2411 // LCOV_EXCL_START 5: pipe error case
2412 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2413 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "pipe Error");
2415 // LCOV_EXCL_STOP 5: pipe error case
2418 // Create child process
2420 if (c_pid < 0) { // LCOV_EXCL_BR_LINE 5: fork error case
2421 // LCOV_EXCL_START 5: fork error case
2422 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2423 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "fork Error");
2428 // LCOV_EXCL_STOP 5: fork error case
2432 /*******************************************************
2434 *******************************************************/
2435 if (lower_sched_priority(CPULOAD_NICEVAL) == false) { // LCOV_EXCL_BR_LINE 200: lower_sched_priority can't be false
2436 // LCOV_EXCL_START 200: lower_sched_priority can't be false
2437 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2438 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to lower scheduler");
2442 close(pipe_fd[0]); // Unneeded pipes (close stdin)
2444 close(1); // Close stdout
2445 dup2(pipe_fd[1], 1); // Duplicate stdout to pipe_fd[1]
2448 execl("/usr/bin/top", "top", "-n", "1", "-b", NULL);
2450 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "execl top Error");
2453 close(pipe_fd[1]); // Unneeded pipes(Close stdout)
2456 close(0); // Close stdin
2457 dup2(pipe_fd[0], 0); // Duplicate stdin to pipe_fd[0]
2464 struct timeval tmout = { TOP_TIMEOUT, 0 };
2467 FD_SET(STDIN_FILENO, &fds);
2468 maxFd = STDIN_FILENO;
2469 ret = select(maxFd + 1, &fds, NULL, NULL, &tmout);
2470 if (ret < 0) { // LCOV_EXCL_BR_LINE 5: select error case
2471 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2472 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "[RESM]Handle Error errno:%d", errno); // LCOV_EXCL_LINE 5: select error case
2473 } else if (FD_ISSET(STDIN_FILENO, &fds)) { // LCOV_EXCL_BR_LINE 5: FD_ISSET's error case
2476 // LCOV_EXCL_START 5: FD_ISSET's error case
2477 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2478 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2479 "[RESM]'top': No response during %d seconds", TOP_TIMEOUT);
2482 if (kill_flag) { // LCOV_EXCL_BR_LINE 200: kill_flag must be 0
2483 // LCOV_EXCL_START 200: kill_flag must be 0
2484 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2485 // Kill top after TOP_TIMEOUT sec
2486 // (Killed by child process to avoid making resm process super-user with setuid.)
2487 if (kill(c_pid, SIGKILL) == -1) {
2488 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
2489 "Failed to kill(SIGKILL), pid=%d, errno=%d", (int) c_pid,
2494 while (fgets(buf, sizeof(buf), stdin) != NULL) {
2496 if (buf[0] != 'C') {
2499 if (strstr(buf, "Cpu(s)") == NULL || strstr(buf, "sy") == NULL) {
2503 } else if (logLine == 1) {
2504 ptr = strstr(buf, "PID");
2509 } else if (logLine < (DEBUG_INFO_CPU_TOP_LINES + 2)) {
2510 ret = sscanf(buf, "%128s %128s %128s %128s %128s %128s %128s %128s %128s %128s %128s %128s", fields[0],
2511 fields[1], fields[2], fields[3], fields[4], fields[5],
2512 fields[6], fields[7], fields[8], fields[9], fields[10],
2514 fprintf(wfp, "%4s%% %s\n", fields[8], fields[11]);
2518 fprintf(wfp, "\n\n");
2522 if (kill_flag) { // LCOV_EXCL_BR_LINE 200: kill_flag must be 0
2523 // LCOV_EXCL_START 200: kill_flag must be 0
2524 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2525 const struct timespec delay = {1, 0};
2527 for (i = 0; i < WAIT_RETRY; i++) {
2528 nanosleep(&delay, NULL);
2529 if ((waitret = waitpid(c_pid, &status, WNOHANG)) == -1) {
2531 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to waitpid for top %d, errno=%d", c_pid, errno);
2533 } else if (waitret == c_pid) {
2534 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "waitpid OK");
2538 if (i >= WAIT_RETRY) {
2540 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "top Failed to exit, pid=%d", c_pid);
2544 if ((waitret = waitpid(static_cast<int>(c_pid), &status, 0)) < 0) { // LCOV_EXCL_BR_LINE 5: waitpid's error case
2545 // LCOV_EXCL_START 5: waitpid's error case
2546 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2548 FRAMEWORKUNIFIEDLOG(ZONE_RESM_DEBUG, __FUNCTION__, "waitpid(%d) Error errno(%d)", c_pid, errno);
2552 if (ret < 0) { // LCOV_EXCL_BR_LINE 200: ret must be 0
2553 // LCOV_EXCL_START 200: ret must be 0
2554 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2555 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "wait Error");
2563 dup2(save_0, 0); // Reset the stdin to 0
2570 // Get CMA information and Output work
2571 static int write_cmainfo_work(FILE *wfp) {
2577 uint32_t used_letters;
2579 avail = static_cast<float>(cmaFree_kib);
2580 total = static_cast<float>(cmaTotal_kib);
2581 used = total - avail;
2582 min_remain = static_cast<float>(minRestCma);
2583 // "*CMA MEMORY @@@@@@ Warning!! @@@@@"
2584 fprintf(wfp, "*CMA MEMORY");
2585 if (used * 5 > total * 4) { // (4/5 Or more)
2586 fprintf(wfp, " @@@@@@ Warning!! @@@@@\n");
2588 fprintf(wfp, " \n");
2590 // "used/avail/total xxx.xMB / xxx.xMB / xxx.xMB(xx.x%)
2596 used_rate = (uint32_t) (used * 1000 / total);
2600 if (used_rate >= 1000) {
2605 " used/avail/total/min remain %5.1fMB / %5.1fMB / %5.1fMB(%2d.%d%%) / %5.1fMB\n",
2606 used, avail, total, used_rate / 10, used_rate % 10, min_remain);
2610 used_letters = (uint32_t) (DEBUG_INFO_CMA_LETTERS * used / total);
2611 if (used_letters > DEBUG_INFO_CMA_LETTERS) {
2612 used_letters = DEBUG_INFO_CMA_LETTERS;
2615 // "------------------*******"
2617 for (i = 0; i < static_cast<int>(used_letters); i++) {
2620 for (; i < DEBUG_INFO_CMA_LETTERS; i++) {
2623 fprintf(wfp, "\n\n");
2627 // Write information and Output FRAMEWORKUNIFIEDLOG
2628 static int write_resourcemanagerloginfo_work(void) {
2630 char l_read[READLINE_MAX_SIZE];
2633 wfp = fopen(DEBUG_INFO_FPATH, "r");
2634 if (wfp == NULL) { // LCOV_EXCL_BR_LINE 5: fopen error case
2635 // LCOV_EXCL_START 5: fopen case error
2636 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2637 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to open %s, errno=%d",
2641 // LCOV_EXCL_STOP 5: fopen case error
2644 if (fgets(l_read, READLINE_MAX_SIZE, wfp) == NULL) {
2646 if (ret == 0) { // LCOV_EXCL_BR_LINE 5: feof case error
2647 // LCOV_EXCL_START 5: feof case error
2648 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
2649 FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "Failed to fgets %s",
2651 // LCOV_EXCL_STOP 5: feof case error
2656 line = strchr(l_read, '\n');
2660 if (l_read[0] != '\0') {
2661 FRAMEWORKUNIFIEDLOG(ZONE_PERFORMANCE, __FUNCTION__, "%s", l_read);