RDK Documentation (Open Sourced RDK Components)
CPU Proc Data Types

Description

Data Structures

struct  stPrevData
 Holds status of previous data such as Total Major Faults Raised,Total CPU Used Time,User Used CPU Time,System Used CPU Time. More...
 
struct  stCPUInfo
 Holds status of CPU information such as Total Time and Idle Time of CPU. More...
 
struct  EnvVarNode
 
struct  stProcData
 Holds status of Process data such as : More...
 

Macros

#define LINE_LIMIT   256
 FILE LINE LIMIT.
 
#define NAME_LIMIT   20
 FILE NAME LIMIT.
 
#define SLEEP_SECS   60
 Sleep Interval for the data collection.
 
#define TIME_TO_RUN_SECS   0
 0 means, tool should run until it is killed manually
 
#define BUFF_SIZE_64   64
 
#define BUFF_SIZE_16   16
 
#define DEFAULT_MEM_THRESHOLD   1536
 
#define MONITOR_ALL_PROC_DEF   0
 
#define DEFAULT_DYNAMIC   1
 
#define ITERATION_THRESHOLD   25
 
#define TELEMETRY_ONLY_DEF   0
 
#define CPU_MASK   0x10
 
#define MEMORY_MASK   0x08
 
#define FDCOUNT_MASK   0x04
 
#define THREADCOUNT_MASK   0x02
 
#define LOADAVG_MASK   0x02
 
#define CLICOUNT_MASK   0x01
 
#define SYS_DEF_MASK   0x1F
 
#define PROC_DEF_MASK   0x1E
 
#define MAX(x, y)   ((x>y)?x:y)
 
#define PROC_EVENT_NONE   0x00000000
 
#define PROC_EVENT_FORK   0x00000001
 
#define PROC_EVENT_EXEC   0x00000002
 
#define CONFIG_PATH   "/opt"
 
#define LOG_PATH   "/opt/logs"
 

Typedefs

typedef unsigned int uint
 
typedef struct EnvVarNode EnvVarNode
 

Functions

char * removespaces (char *str)
 
int read_config_param (const char *paramname, const char *filename, char *res)
 
char * GetCurTimeStamp ()
 This function gives Current Date and Time in the format Year-Month-Day and Hours-Minutes-Seconds. More...
 
void GetMemParams (char *filename, unsigned long *memParam, char *param)
 This function gives information about the Memory parameters. More...
 
void GetLoadAverage (float *loadavg)
 This function gives Load Average values. More...
 
void GetUsedMemory (unsigned long *mem)
 This function gives information about Used memory. More...
 
void GetIdlePercent (float *idlePercent)
 This function gives the Idle percent value. More...
 
void CreateExclusionList ()
 This function to exclude the process list of least concern.
 
void GetFDCount (char *filename, int *FDCount)
 This function gives information about the File Descriptors in process. More...
 
void GetFDCountSystem (int *FDCountSystem)
 This function gives information about the File Descriptors at system level. More...
 
uint SetMask (char *res)
 This is to set the bit mask for System/Process.
 
int LogProcData (stProcData *procData, int ppid=0, char *pname="", int is_dynamic=0, bool telemetryOnly=0)
 This function gives status information about the process. More...
 
static int netlink_connect ()
 
static int subscribe_proc_events (int netlink_sock, bool enable)
 
static int handle_process_events (int netlink_sock)
 
static void * handle_proc_ev_thread (void *arg)
 
int checkifdigit (char *ch, int size)
 
bool CheckMemLimit (int itr, unsigned long memLimit)
 
int main (int argc, char **argv)
 Main Function. More...
 
const char * rdk_logger_module_fetch (void)
 

Variables

uint PROC_MASK = 0x1E
 
uint SYS_MASK = 0x1F
 
pthread_mutex_t mtx
 
struct stCPUInfo prevCPUInfo
 
map< unsigned int, struct stPrevDataprevData
 
FILE * fp_selectedps = NULL
 
FILE * fp_stat = NULL
 
FILE * fp_dataOut = NULL
 
string outputDir = "/opt/logs" "/cpuprocanalyzer/"
 
string outputDynamicDir = "/opt/logs" "/cpuprocanalyzer/dynamic/"
 
long totalTimeElapsed_sec = 0
 
char strTime [80]
 
list< string > exclude_process_list
 
list< string >::iterator it
 
static volatile bool need_exit = false
 

Data Structure Documentation

◆ stPrevData

struct stPrevData

Holds status of previous data such as Total Major Faults Raised,Total CPU Used Time,User Used CPU Time,System Used CPU Time.

Definition at line 135 of file cpuproc_analyzer.cpp.

Collaboration diagram for stPrevData:
Collaboration graph
Data Fields
unsigned int prevTotalMajFaultsRaised
unsigned long prevTotalUsedCPUTime
unsigned long prevUserUsedCPUTime
unsigned long prevSystemUsedCPUTime
double prevTotalCPUTime_usec
bool status

◆ stCPUInfo

struct stCPUInfo

Holds status of CPU information such as Total Time and Idle Time of CPU.

Definition at line 150 of file cpuproc_analyzer.cpp.

Collaboration diagram for stCPUInfo:
Collaboration graph
Data Fields
unsigned long long total
unsigned long long idle

◆ EnvVarNode

struct EnvVarNode

Definition at line 46 of file rdk_logger_util.c.

Collaboration diagram for EnvVarNode:
Collaboration graph
Data Fields
int number
char * name
char * value
struct EnvVarNode * next

◆ stProcData

struct stProcData

Holds status of Process data such as :

  • PID of process, Process State, Parent PID, Process Group ID, Session ID of the Process.
  • The Kernel Flags word of the Process, Major Faults, Minor Faults, Nice value, Number of threads in the process.
  • Resident Set Size, Virtual memory size, Real-time scheduling priority, Scheduling Policy.

Definition at line 499 of file cpuproc_analyzer.cpp.

Collaboration diagram for stProcData:
Collaboration graph

Public Member Functions

void ReadProcStat (FILE *fp_procStat)
 This function reads status of the Process and gives information like : More...
 
void OutFilename (char *outProcFilename, int is_dynamic)
 This function constructs a file name based on parameters such as - output Directory Name,PID value,s_comm data,PID value,s_comm data. For example : "/opt/logs/cpuprocanalyzer/<PID value>/s_comm/<PID value>/s_comm". More...
 
void OutFilename (char *outProcFilename, int ppid, char *pname)
 This function constructs a file name based on parameters such as - output Directory Name,PPID value,Parent process Name,PID value,s_comm data. For example : "/opt/logs/cpuprocanalyzer/<PPID value>/<Parent process name>/<PID value>/s_comm". More...
 
void GetTotalUsedTime (unsigned long *outTotalTime)
 This function gives Total CPU used time. More...
 
void GetUserUsedTime (unsigned long *outUserTime)
 This function gives User used CPU time. More...
 
void GetSystemUsedTime (unsigned long *outSystemTime)
 This function gives information about System used CPU time. More...
 
void GetTotalMjrFlts (unsigned int *outTotalMjrFlts)
 This function gives the information about Total Major Faults. More...
 

Data Fields

int d_pid
 
char s_comm [1000]
 
char c_state
 
int d_ppid
 
int d_pgrp
 
int d_session
 
int d_tty_nr
 
int d_tpgid
 
unsigned u_flags
 
unsigned long lu_minflt
 
unsigned long lu_cminflt
 
unsigned long lu_majflt
 
unsigned long lu_cmajflt
 
unsigned long lu_utime
 
unsigned long lu_stime
 
long ld_cutime
 
long ld_cstime
 
long ld_priority
 
long ld_nice
 
long ld_num_threads
 
long ld_itrealvalue
 
unsigned long long llu_starttime
 
unsigned long lu_vsize
 
long ld_rss
 
unsigned long lu_rsslim
 
unsigned long lu_startcode
 
unsigned long lu_endcode
 
unsigned long lu_startstack
 
unsigned long lu_kstkesp
 
unsigned long lu_kstkeip
 
unsigned long lu_signal
 
unsigned long lu_blocked
 
unsigned long lu_sigignore
 
unsigned long lu_sigcatch
 
unsigned long lu_wchan
 
unsigned long lu_nswap
 
unsigned long lu_cnswap
 
int d_exit_signal
 
int d_processor
 
unsigned int u_rt_priority
 
unsigned int u_policy
 
unsigned long long llu_delayacct_blkio_ticks
 
unsigned long lu_guest_time
 
long ld_cguest_time
 

Function Documentation

◆ GetCurTimeStamp()

char* GetCurTimeStamp ( )

This function gives Current Date and Time in the format Year-Month-Day and Hours-Minutes-Seconds.

@ret Returns date and time in string format.

Definition at line 628 of file cpuproc_analyzer.cpp.

◆ GetMemParams()

void GetMemParams ( char *  filename,
unsigned long *  memParam,
char *  param 
)

This function gives information about the Memory parameters.

  • Information such as Virtual Memory Size, Resident Set Size and Size Of Stack
Parameters
[in]filenameName of the File
[out]memParamMemory Parameters
[in]paramIt can be parameter like Virtual Memory Size, Resident Set Size and Size Of Stack.

Definition at line 649 of file cpuproc_analyzer.cpp.

◆ GetLoadAverage()

void GetLoadAverage ( float *  loadavg)

This function gives Load Average values.

Output Example = 0.75 0.33 0.25 1/25 1747 where :

  • First three fields : Load averages over the last 1,5 and 15 minutes.
  • The fourth field consists of two numbers separated by a slash (/), where : First number is the number of currently executing kernel scheduling entities(processes,threads); this will be less than or equal to the number of CPUs.
  • The value after the slash is the number of kernel scheduling entities that currently exist on the system.
  • The fifth field is the PID of the process.
Parameters
[out]loadavgLoad Average value

Definition at line 692 of file cpuproc_analyzer.cpp.

◆ GetUsedMemory()

void GetUsedMemory ( unsigned long *  mem)

This function gives information about Used memory.

  • It reports statistics about memory usage on the system and gives information like Total usable RAM and Free Memory.
  • Used Memory is calculated by subtracting Free Memory from Total Memory.
Parameters
[out]memUsed Memory value

Definition at line 715 of file cpuproc_analyzer.cpp.

◆ GetIdlePercent()

void GetIdlePercent ( float *  idlePercent)

This function gives the Idle percent value.

  • Idle time is the amount of time the CPU was not busy or otherwise, the amount of time it executed the System Idle process.
  • Idle time actually measures unused CPU capacity.
Parameters
[out]idlepercentIdle Percent Value

Definition at line 765 of file cpuproc_analyzer.cpp.

◆ GetFDCount()

void GetFDCount ( char *  filename,
int *  FDCount 
)

This function gives information about the File Descriptors in process.

Parameters
[in]d_pidPID of process
[in]FDCountFile Descriptor in process

Definition at line 817 of file cpuproc_analyzer.cpp.

◆ GetFDCountSystem()

void GetFDCountSystem ( int *  FDCountSystem)

This function gives information about the File Descriptors at system level.

Parameters
[in]FDCountSystemFile Descriptors at system level

Definition at line 839 of file cpuproc_analyzer.cpp.

◆ LogProcData()

int LogProcData ( stProcData procData,
int  ppid = 0,
char *  pname = "",
int  is_dynamic = 0,
bool  telemetryOnly = 0 
)

This function gives status information about the process.

  • Information such as Process Name, PID of the parent, Virtual memory size, Resident set size, Size of Stack.
Parameters
[in]procDataProcess Data
[in]ppidParent pid,default to 0
[in]pnameParent Name
[in]is_dynamicFlag to check dynamically created process.

Definition at line 923 of file cpuproc_analyzer.cpp.

◆ main()

int main ( int  argc,
char **  argv 
)

Main Function.

Fetches information such as Load Average value, Used Memory value and Idle Percent value for all the Processes in the list from /opt/logs/cpuprocanalyzer/loadandmem.data.

Definition at line 1471 of file cpuproc_analyzer.cpp.