| /////////////////////////////////////////////////////////////////////////////// |
| // // |
| // Copyright (c) 2000-2019 Ericsson Telecom AB // |
| // // |
| // All rights reserved. This program and the accompanying materials // |
| // are made available under the terms of the Eclipse Public License v2.0 // |
| // which accompanies this distribution, and is available at // |
| // https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html // |
| /////////////////////////////////////////////////////////////////////////////// |
| |
| /////////////////////////////////////////////////////////// |
| // Module: EPTF_CLL_HostAdmin_BaseFunctions |
| // |
| // Purpose: |
| // This module contains function definitions for EPTF HostAdmin Base |
| // |
| // Module Parameters: |
| // tsp_debug_EPTF_HostAdmin_Base_Functions - *boolean* - debug messages on/off |
| // tsp_debug_EPTF_HostAdmin_Base_Functions_smoothing - *boolean* - debug messages of smoothing on/off |
| // tsp_EPTF_HostAdmin_loadMeasurementExponentialSmoothingFactor - *float* - smoothing |
| // factor used for smoothing. Its value should be between 0.0 and 1.0 |
| // tsp_EPTF_HostAdmin_loadMeasurementRefreshTime - *float* - define the periodical refresh time |
| // |
| // Module depends on: |
| // <EPTF_CLL_HostAdmin_BaseDefinitions> |
| // <LOADMEASasp_PortType> |
| // <EPTF_CLL_Base_Functions> |
| // <EPTF_CLL_Common_Functions> |
| // |
| // Current Owner: |
| // Gabor Tatarka (egbotat) |
| // Bence Molnar (ebenmol) |
| // |
| // Last Review Date: |
| // 2008-02-14 |
| // |
| // Detailed Comments: |
| // - |
| /////////////////////////////////////////////////////////// |
| module EPTF_CLL_HostAdmin_BaseFunctions |
| { |
| |
| //========================================================================= |
| // Imports |
| //======================================================================= |
| import from EPTF_CLL_HostAdmin_BaseDefinitions all; |
| import from LOADMEASasp_PortType all; |
| import from EPTF_CLL_Base_Functions all; |
| import from EPTF_CLL_Common_Functions all; |
| |
| modulepar boolean tsp_debug_EPTF_HostAdmin_Base_Functions := false; |
| modulepar boolean tsp_debug_EPTF_HostAdmin_Base_Functions_smoothing := false; |
| modulepar float tsp_EPTF_HostAdmin_loadMeasurementExponentialSmoothingFactor := 0.5; // should be between 0.0:extreme smoothing and 1,0:no smoothing |
| modulepar float tsp_EPTF_HostAdmin_loadMeasurementRefreshTime := 1.0; // default 1 secs |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_init_CT |
| // |
| // Purpose: |
| // Load measurement interface initialisation for EPTF_HostAdmin_Base_CT |
| // |
| // Parameters: |
| // pl_selfName - *charstring* - EPTF self name |
| // |
| // Return Value: |
| // - |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // Also initializes constant measurement data: number of CPUs and physical memory size. |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_init_CT(in charstring pl_selfName) runs on EPTF_HostAdmin_Base_CT |
| { |
| if(tsp_debug_EPTF_HostAdmin_Base_Functions and v_EPTF_HostAdmin_Base_initialized) { |
| f_EPTF_Common_user(%definitionId&": already initialized."); |
| } |
| |
| if(tsp_debug_EPTF_HostAdmin_Base_Functions) { f_EPTF_Common_user("f_EPTF_HostAdmin_Base_initCT(): started"); } |
| map(self:v_EPTF_HostAdmin_CPUloadOnHost_PCO, system:v_EPTF_HostAdmin_CPUloadOnHost_PCO); |
| |
| f_EPTF_Base_init_CT(pl_selfName); |
| |
| v_EPTF_HostAdmin_ASP_LOADMEAS := { loadType := CPU, msg := { startMeas := {} } }; |
| v_EPTF_HostAdmin_CPUloadOnHost_PCO.send(v_EPTF_HostAdmin_ASP_LOADMEAS); |
| |
| v_EPTF_HostAdmin_ASP_LOADMEAS := { loadType := CPU, msg := { setPeriod := {periodTime := tsp_EPTF_HostAdmin_loadMeasurementRefreshTime} } }; |
| v_EPTF_HostAdmin_CPUloadOnHost_PCO.send(v_EPTF_HostAdmin_ASP_LOADMEAS); |
| |
| v_EPTF_HostAdmin_ASP_LOADMEAS := { loadType := MEMORY, msg := { startMeas := {} } }; |
| v_EPTF_HostAdmin_CPUloadOnHost_PCO.send(v_EPTF_HostAdmin_ASP_LOADMEAS); |
| |
| v_EPTF_HostAdmin_ASP_LOADMEAS := { loadType := MEMORY, msg := { setPeriod := {periodTime := tsp_EPTF_HostAdmin_loadMeasurementRefreshTime} } }; |
| v_EPTF_HostAdmin_CPUloadOnHost_PCO.send(v_EPTF_HostAdmin_ASP_LOADMEAS); |
| |
| v_EPTF_HostAdmin_numCPUs := getNumCPUs(v_EPTF_HostAdmin_CPUloadOnHost_PCO); |
| for(var integer i:=0; i<v_EPTF_HostAdmin_numCPUs; i:=i+1) { v_EPTF_HostAdmin_CPULoads[i] := 0.0; } |
| |
| v_EPTF_HostAdmin_physicalMemory := getPhysicalMemory(v_EPTF_HostAdmin_CPUloadOnHost_PCO); |
| |
| v_EPTF_HostAdmin_Base_initialized := true; |
| f_EPTF_Base_registerCleanup(refers(f_EPTF_HostAdmin_Base_cleanup_CT)); |
| |
| if(tsp_debug_EPTF_HostAdmin_Base_Functions) { f_EPTF_Common_user("f_EPTF_HostAdmin_Base_initCT(): finished"); } |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_getNumCPUs |
| // |
| // Purpose: |
| // Returns the number of CPUs |
| // |
| // Parameters: |
| // - |
| // |
| // Return Value: |
| // integer - the number of CPUs |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_getNumCPUs() runs on EPTF_HostAdmin_Base_CT return integer { |
| return v_EPTF_HostAdmin_numCPUs; |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_getPhysicalMemory |
| // |
| // Purpose: |
| // Returns the physical memory |
| // |
| // Parameters: |
| // - |
| // |
| // Return Value: |
| // integer - the physical memory |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_getPhysicalMemory() runs on EPTF_HostAdmin_Base_CT return integer { |
| return v_EPTF_HostAdmin_physicalMemory; |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_getTesterHostLoad |
| // |
| // Purpose: |
| // Returns the load on the tester host |
| // |
| // Parameters: |
| // - |
| // |
| // Return Value: |
| // float - the load on the tester host |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_getTesterHostLoad() runs on EPTF_HostAdmin_Base_CT return float { |
| return v_EPTF_HostAdmin_testerHostLoad; |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_getFreeMemory |
| // |
| // Purpose: |
| // Returns the free memory |
| // |
| // Parameters: |
| // - |
| // |
| // Return Value: |
| // integer - the free memory |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_getFreeMemory() runs on EPTF_HostAdmin_Base_CT return integer { |
| return v_EPTF_HostAdmin_freeMemory; |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_getCPULoads |
| // |
| // Purpose: |
| // Returns the load on the given CPU |
| // |
| // Parameters: |
| // pl_idx - *in integer* - the index of the CPU |
| // |
| // Return Value: |
| // float - the load on the given CPU |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_getCPULoads(in integer pl_idx) runs on EPTF_HostAdmin_Base_CT return float { |
| if(pl_idx < sizeof(v_EPTF_HostAdmin_CPULoads) and pl_idx >= 0) { |
| return v_EPTF_HostAdmin_CPULoads[pl_idx]; |
| } else { |
| return 0.0; |
| } |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_getProcessName |
| // |
| // Purpose: |
| // Function for getting the name of a process by its pid |
| // |
| // Parameters: |
| // pl_pid - *integer* - process id |
| // |
| // Return Value: |
| // *charstring* |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_getProcessName(in integer pl_pid) |
| runs on EPTF_HostAdmin_Base_CT |
| return charstring |
| { |
| return getProcessName(v_EPTF_HostAdmin_CPUloadOnHost_PCO, pl_pid); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_addProcessStat |
| // |
| // Purpose: |
| // Function for adding statistics for a process by its pid |
| // |
| // Parameters: |
| // pl_pid - *integer* - process id |
| // |
| // Return Value: |
| // *integer* - index |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_addProcessStat(in integer pl_pid) |
| runs on EPTF_HostAdmin_Base_CT |
| return integer |
| { |
| return addProcessStat(v_EPTF_HostAdmin_CPUloadOnHost_PCO, pl_pid); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_removeProcessStat |
| // |
| // Purpose: |
| // Function for removing statistics for a process by its pid |
| // |
| // Parameters: |
| // pl_pid - *integer* - process id |
| // |
| // Return Value: |
| // - |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_removeProcessStat(in integer pl_pid) |
| runs on EPTF_HostAdmin_Base_CT |
| { |
| removeProcessStat(v_EPTF_HostAdmin_CPUloadOnHost_PCO, pl_pid); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_removeProcessStatByIdx |
| // |
| // Purpose: |
| // Function for removing statistics for a process by its index |
| // |
| // Parameters: |
| // pl_pid - *integer* - process id |
| // |
| // Return Value: |
| // - |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_removeProcessStatByIdx(in integer pl_idx) |
| runs on EPTF_HostAdmin_Base_CT |
| { |
| removeProcessStatByIdx(v_EPTF_HostAdmin_CPUloadOnHost_PCO, pl_idx); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_getProcessCpuLoad |
| // |
| // Purpose: |
| // Function for getting the CPU load of a previously added process by its pid |
| // |
| // Parameters: |
| // pl_pid - *integer* - process id |
| // |
| // Return Value: |
| // *float* - the CPU load in percentage (similar to `top`) |
| // |
| // Detailed Comments: |
| // The process must be added with addProcessStat first. |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_getProcessCpuLoad(in integer pl_pid) |
| runs on EPTF_HostAdmin_Base_CT |
| return float |
| { |
| return getProcessCpuLoad(v_EPTF_HostAdmin_CPUloadOnHost_PCO, pl_pid); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_getProcessCpuLoadByIdx |
| // |
| // Purpose: |
| // Function for getting the CPU load of a previously added process by its index |
| // |
| // Parameters: |
| // pl_pid - *integer* - process id |
| // |
| // Return Value: |
| // *float* - the CPU load in percentage (similar to `top`) |
| // |
| // Detailed Comments: |
| // The process must be added with addProcessStat first. |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_getProcessCpuLoadByIdx(in integer pl_idx) |
| runs on EPTF_HostAdmin_Base_CT |
| return float |
| { |
| return getProcessCpuLoadByIdx(v_EPTF_HostAdmin_CPUloadOnHost_PCO, pl_idx); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_getProcessMemUsage |
| // |
| // Purpose: |
| // Function for getting the memory usage of a previously added process by its pid |
| // |
| // Parameters: |
| // pl_pid - *integer* - process id |
| // |
| // Return Value: |
| // *integer* - memory usage of the process in kB |
| // |
| // Detailed Comments: |
| // The process must be added with addProcessStat first. |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_getProcessMemUsage(in integer pl_pid) |
| runs on EPTF_HostAdmin_Base_CT |
| return integer |
| { |
| return getProcessMemUsage(v_EPTF_HostAdmin_CPUloadOnHost_PCO, pl_pid); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_getProcessMemUsageByIdx |
| // |
| // Purpose: |
| // Function for getting the memory usage of a previously added process by its index |
| // |
| // Parameters: |
| // pl_pid - *integer* - process id |
| // |
| // Return Value: |
| // *integer* - memory usage of the process in kB |
| // |
| // Detailed Comments: |
| // The process must be added with addProcessStat first. |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_getProcessMemUsageByIdx(in integer pl_idx) |
| runs on EPTF_HostAdmin_Base_CT |
| return integer |
| { |
| return getProcessMemUsageByIdx(v_EPTF_HostAdmin_CPUloadOnHost_PCO, pl_idx); |
| } |
| |
| group Private { |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_cleanup_CT |
| // |
| // Purpose: |
| // Load measurement interface cleanup for EPTF_HostAdmin_Base_CT |
| // |
| // Parameters: |
| // - |
| // |
| // Return Value: |
| // - |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // Private function, call f_EPTF_Base_cleanup_CT to perform cleanup. |
| /////////////////////////////////////////////////////////// |
| private function f_EPTF_HostAdmin_Base_cleanup_CT() runs on EPTF_HostAdmin_Base_CT |
| { |
| if(tsp_debug_EPTF_HostAdmin_Base_Functions) { f_EPTF_Common_user(%definitionId&": started"); } |
| |
| if(not v_EPTF_HostAdmin_Base_initialized) { |
| f_EPTF_Common_warning(%definitionId&": not initialized."); |
| } |
| |
| v_EPTF_HostAdmin_ASP_LOADMEAS := { loadType := CPU, msg := { stopMeas := {} } }; |
| v_EPTF_HostAdmin_CPUloadOnHost_PCO.send(v_EPTF_HostAdmin_ASP_LOADMEAS); |
| |
| v_EPTF_HostAdmin_ASP_LOADMEAS := { loadType := MEMORY, msg := { stopMeas := {} } }; |
| v_EPTF_HostAdmin_CPUloadOnHost_PCO.send(v_EPTF_HostAdmin_ASP_LOADMEAS); |
| |
| unmap(self:v_EPTF_HostAdmin_CPUloadOnHost_PCO, system:v_EPTF_HostAdmin_CPUloadOnHost_PCO); |
| |
| v_EPTF_HostAdmin_testerHostLoad := 0.0; |
| v_EPTF_HostAdmin_numCPUs := 0; |
| v_EPTF_HostAdmin_CPULoads := {}; |
| v_EPTF_HostAdmin_physicalMemory := 0; |
| v_EPTF_HostAdmin_freeMemory := 0; |
| |
| v_EPTF_HostAdmin_Base_initialized := false; |
| |
| if(tsp_debug_EPTF_HostAdmin_Base_Functions) { f_EPTF_Common_user(%definitionId&": finished"); } |
| } |
| |
| } // group Private |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_Base_update |
| // |
| // Purpose: |
| // Updates measurement variables from the testport. |
| // |
| // Parameters: |
| // - |
| // |
| // Return Value: |
| // - |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // At least one second has to elapse between successive calls to this function. |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_Base_update() runs on EPTF_HostAdmin_Base_CT |
| { |
| v_EPTF_HostAdmin_testerHostLoad := f_EPTF_HostAdmin_exponentialSmoothingFunction(getCPULoadAvg(v_EPTF_HostAdmin_CPUloadOnHost_PCO), |
| v_EPTF_HostAdmin_testerHostLoad, tsp_EPTF_HostAdmin_loadMeasurementExponentialSmoothingFactor); |
| |
| for(var integer i:=0; i<v_EPTF_HostAdmin_numCPUs; i:=i+1) { |
| v_EPTF_HostAdmin_CPULoads[i] := f_EPTF_HostAdmin_exponentialSmoothingFunction(getCPULoad(v_EPTF_HostAdmin_CPUloadOnHost_PCO, i), |
| v_EPTF_HostAdmin_CPULoads[i], tsp_EPTF_HostAdmin_loadMeasurementExponentialSmoothingFactor); |
| } |
| |
| v_EPTF_HostAdmin_freeMemory := getFreeMemory(v_EPTF_HostAdmin_CPUloadOnHost_PCO); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_exponentialSmoothingFunction |
| // |
| // Purpose: |
| // This function is used to smooth the measured load using exponential smoothing |
| // |
| // Parameters: |
| // pl_measuredLoad - *in* *float* - value of the currently measured load |
| // |
| // pl_prevLoad - *in* *float* - value of the previous smoothed load |
| // |
| // pl_smoothingFactor - *in* *float* - smoothing factor, should be between |
| // 0.0 (extreme smoothing) and 1.0 (no smoothing) |
| // |
| // Return Value: |
| // float - smoothed load |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // This function can be used to remove high fluctuations of the measured data. |
| // The function uses exponetial smoothing, which is based on the following formula: |
| // |
| // s_0 = x_0 |
| // |
| // s_t = alpha * x_t + (1-alpha) * s_(t-1) |
| // |
| // x_t is the measured data at t iteration, s_t is the smoothed value |
| // |
| /////////////////////////////////////////////////////////// |
| private function f_EPTF_HostAdmin_exponentialSmoothingFunction(in float pl_measuredLoad, in float pl_prevLoad, in float pl_smoothingFactor) |
| return float |
| { |
| if(tsp_debug_EPTF_HostAdmin_Base_Functions_smoothing) { f_EPTF_Common_user(log2str("f_EPTF_exponentialSmoothingFunction: measured load: " & float2str(pl_measuredLoad))); } |
| var float vl_currLoad := pl_smoothingFactor*pl_measuredLoad+(1.0-pl_smoothingFactor)*pl_prevLoad; |
| if(tsp_debug_EPTF_HostAdmin_Base_Functions_smoothing) { f_EPTF_Common_user(log2str("f_EPTF_exponentialSmoothingFunction: smoothed load: " & float2str(vl_currLoad))); } |
| |
| return vl_currLoad; |
| } |
| |
| |
| } // module |
| |