blob: f01e37585f244ed1cdfbba75f2749004a3959050 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
// //
// 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_StatCaptureControl_Functions
//
// Purpose:
// This module contains the implementation of Statistics Capture Control functions.
//
// Module Parameters:
// tsp_EPTF_StatCaptureControl_captureControlMode - <EPTF_StatCaptureControl_CaptureControlMode> := manual;
// set the capture mode of the capture (manual/load-based/complete)
// tsp_EPTF_StatCaptureControl_nr_of_captures - *integer* := 100;
// set the number of start-stop capture periods
// tsp_EPTF_StatCaptureControl_userVariable - <EPTF_StatCaptureControl_controlVariable>
// the user Variable which is controlling in manual control mode
// tsp_EPTF_StatCaptureControl_executionVariable - <EPTF_StatCaptureControl_controlVariable>
// the execution Variable which is controlling in complete control mode
// tsp_EPTF_StatCaptureControl_loadVariable - <EPTF_StatCaptureControl_controlVariable>
// the load Variable which is inspected in load_based_control mode
// tsp_EPTF_StatCaptureControl_loadStableToStart - *float* - := 10.0;
// so long the load Variable must be stable in order to start capture
// tsp_EPTF_StatCaptureControl_loadStableCapturePeriod - *float* - := 600.0; //ten minutes
// capture is "on" during this period.
// tsp_EPTF_StatCaptureControl_loadCaptureDelay - *float* - := 0.0
// after successful capture this delay is inserted before starting the loadStableToStart period
//
// Module depends on:
// <EPTF_CLL_StatCaptureControl_Definitions>
// <EPTF_CLL_StatCapture_Definitions>
// <EPTF_CLL_StatCapture_Functions>
// <EPTF_CLL_Base_Functions>
// <EPTF_CLL_Variable_Definitions>
// <EPTF_CLL_Variable_Functions>
// <EPTF_CLL_Common_Definitions>
// <EPTF_CLL_NameService_Definitions>
// <EPTF_CLL_NameServiceClient_Functions>
// <EPTF_CLL_Logging_Definitions>
// <EPTF_CLL_Logging_Functions>
//
// Public functions:
// <f_EPTF_StatCaptureControl_init>
//
// Current Owner:
// Andrea Darabos (EANDDAR)
//
// Last Review Date:
// 2008-01-17
//
// Detailed Comments:
// This module contains the interface functions for the EPTF Statistics Capture Control.
//
///////////////////////////////////////////////////////////////
module EPTF_CLL_StatCaptureControl_Functions {
import from EPTF_CLL_StatCaptureControl_Definitions all;
import from EPTF_CLL_StatCapture_Definitions all;
import from EPTF_CLL_StatCapture_Functions all;
import from EPTF_CLL_Base_Functions all;
import from EPTF_CLL_Variable_Definitions all;
import from EPTF_CLL_Variable_Functions all;
import from EPTF_CLL_Common_Definitions all;
import from EPTF_CLL_NameService_Definitions all;
import from EPTF_CLL_NameServiceClient_Functions all;
import from EPTF_CLL_Logging_Definitions all;
import from EPTF_CLL_Logging_Functions all;
modulepar EPTF_StatCaptureControl_CaptureControlMode tsp_EPTF_StatCaptureControl_captureControlMode := manual; //manual/load-based/complete control mode
modulepar integer tsp_EPTF_StatCaptureControl_nrOfCaptures := 100; //100 periods of start-stop capture
modulepar EPTF_StatCaptureControl_controlVariable tsp_EPTF_StatCaptureControl_userVariable; //the userVariable which we subscribe for
modulepar EPTF_StatCaptureControl_controlVariable tsp_EPTF_StatCaptureControl_executionVariable; //the executionVariable which we subscribe for
modulepar EPTF_StatCaptureControl_controlVariable tsp_EPTF_StatCaptureControl_loadVariable; //the loadVariable which we subscribe for
modulepar float tsp_EPTF_StatCaptureControl_loadStableToStart := 10.0; //the load Variable must be stable for this long to start capture
modulepar float tsp_EPTF_StatCaptureControl_loadStableCapturePeriod:= 600.0; //10 minutes long measurement
modulepar float tsp_EPTF_StatCaptureControl_loadCaptureDelay := 0.0; //the time delay between capture measurements
modulepar boolean tsp_EPTF_StatCaptureControl_debug := false;
///////////////////////////////////////////////////////////
// Function: f_EPTF_StatCaptureControl_init
//
// Purpose:
// Initializes the StatCaptureControl component and depending components.
//
// Parameters:
// selfName - *in* *charstring* - name of the component
// NS_ServerCompRef - *in* <EPTF_NS_CT> - the component reference of the EPTF Name Service Server Component
// autoControlEnabled - *in* *boolean* *optional* - optional parameter for switching off automatic capture control
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// This function initializes used components reads in module parameters and adds Postproc functions. If the automatic Control is
// disabled, the component behaves as an EPTF_StatCaptureControl_CT component, i.e. statistics capture control can be carried out
// via API calls.
//
///////////////////////////////////////////////////////////
public function f_EPTF_StatCaptureControl_init(in charstring pl_selfName, in EPTF_NS_CT pl_NS_ServerCompRef, in boolean pl_autoControlEnabled := true) runs on EPTF_StatCaptureControl_CT {
if (v_StatCaptureControl_initialized) {
return; // component is already initialized
}
var default v_def := activate(as_EPTF_StatCaptureControl_LoadBased_default()); //lowest priority
f_EPTF_Var_init_CT(pl_selfName);
f_EPTF_NS_Client_init_CT(pl_selfName, pl_NS_ServerCompRef); //NS server component reference
f_EPTF_StatCapture_init(pl_selfName);
f_EPTF_Logging_init_CT(pl_selfName);
v_StatCaptureControl_loggingMaskId := f_EPTF_Logging_registerComponentMasks(tsp_EPTF_StatCaptureControl_loggingComponentMask, c_EPTF_StatCapture_loggingEventClasses, EPTF_Logging_CLL);
if(tsp_EPTF_StatCaptureControl_debug) {
f_EPTF_Logging_enableLocalMask(v_StatCaptureControl_loggingMaskId, c_EPTF_StatCapture_loggingClassIdx_Debug);
} else {
f_EPTF_Logging_disableLocalMask(v_StatCaptureControl_loggingMaskId, c_EPTF_StatCapture_loggingClassIdx_Debug);
}
if (pl_autoControlEnabled == true) {
v_StatCaptureControl_initialized := true;
v_StatCaptureControl_nrOfCaptures := 0;
v_StatCaptureControl_loadStableToStartL := tsp_EPTF_StatCaptureControl_loadStableToStart;
v_StatCaptureControl_loadStableCapturePeriodL := tsp_EPTF_StatCaptureControl_loadStableCapturePeriod;
v_StatCaptureControl_loadStableCaptureDelayL := tsp_EPTF_StatCaptureControl_loadCaptureDelay;
var integer vl_varidx;
if (tsp_EPTF_StatCaptureControl_userVariable.componentName != ""){
var EPTF_NS_QueryResp vl_queryResp;
f_EPTF_NS_Query(tsp_EPTF_StatCaptureControl_userVariable.componentName, vl_queryResp);
if (vl_queryResp.ownerComp == omit) {
f_EPTF_StatCaptureControl_error("User Component reference does not exist");
//f_EPTF_Base_stop();
}
var EPTF_NS_Client_CT vl_remoteCompRef := vl_queryResp.ownerComp;
var EPTF_Var_SubscriptionMode vl_subscriptionMode := realtime;
var EPTF_Var_CT vl_varCompRef := f_EPTF_Var_downcast(f_EPTF_NS_Client_upcast(vl_remoteCompRef)); //up- and downcast to Variable Compref
f_EPTF_Var_subscribeRemote(vl_varCompRef, tsp_EPTF_StatCaptureControl_userVariable.varName, vl_subscriptionMode, vl_varidx, "UserVar");
v_StatCaptureControl_UserVariableID := vl_varidx;
var EPTF_Var_DirectContent vl_currentContent;
f_EPTF_Var_getContent(v_StatCaptureControl_UserVariableID, vl_currentContent);
if (not ischosen(vl_currentContent.boolVal)){ // the user must define a boolean User Variable
f_EPTF_StatCaptureControl_error("User Variable does not have a boolean value.");
//f_EPTF_Base_stop();
}
f_EPTF_Var_addPostProcFn(v_StatCaptureControl_UserVariableID, {refers(f_EPTF_StatCaptureControl_User_PostProc), {}});
f_EPTF_Var_callPostProcFns(v_StatCaptureControl_UserVariableID);
}
if (tsp_EPTF_StatCaptureControl_executionVariable.componentName != ""){
var EPTF_NS_QueryResp vl_queryResp;
f_EPTF_NS_Query(tsp_EPTF_StatCaptureControl_executionVariable.componentName, vl_queryResp);
if (vl_queryResp.ownerComp == omit) {
f_EPTF_StatCaptureControl_error("Execution Component reference does not exist");
//f_EPTF_Base_stop();
}
var EPTF_NS_Client_CT vl_remoteCompRef := vl_queryResp.ownerComp;
var EPTF_Var_SubscriptionMode vl_subscriptionMode := realtime;
var EPTF_Var_CT vl_varCompRef := f_EPTF_Var_downcast(f_EPTF_NS_Client_upcast(vl_remoteCompRef)); //up- and downcast to Variable Compref
f_EPTF_Var_subscribeRemote(vl_varCompRef, tsp_EPTF_StatCaptureControl_executionVariable.varName, vl_subscriptionMode, vl_varidx, "ExecutionVar");
v_StatCaptureControl_ExecutionVariableID := vl_varidx;
var EPTF_Var_DirectContent vl_currentContent;
f_EPTF_Var_getContent(v_StatCaptureControl_ExecutionVariableID, vl_currentContent);
if (not ischosen(vl_currentContent.boolVal)){ // the user must define a boolean Execution Variable
f_EPTF_StatCaptureControl_error("Execution Variable does not have a boolean value.");
//f_EPTF_Base_stop();
}
f_EPTF_Var_addPostProcFn(v_StatCaptureControl_ExecutionVariableID, {refers(f_EPTF_StatCaptureControl_Execution_PostProc), {}});
f_EPTF_Var_callPostProcFns(v_StatCaptureControl_ExecutionVariableID);
}
if (tsp_EPTF_StatCaptureControl_loadVariable.componentName != ""){
var EPTF_NS_QueryResp vl_queryResp;
f_EPTF_NS_Query(tsp_EPTF_StatCaptureControl_loadVariable.componentName, vl_queryResp);
if (vl_queryResp.ownerComp == omit) {
f_EPTF_StatCaptureControl_error("Load Component reference does not exist");
//f_EPTF_Base_stop();
}
var EPTF_NS_Client_CT vl_remoteCompRef := vl_queryResp.ownerComp;
var EPTF_Var_SubscriptionMode vl_subscriptionMode := realtime;
var EPTF_Var_CT vl_varCompRef := f_EPTF_Var_downcast(f_EPTF_NS_Client_upcast(vl_remoteCompRef)); //up- and downcast to Variable Compref
f_EPTF_Var_subscribeRemote(vl_varCompRef, tsp_EPTF_StatCaptureControl_loadVariable.varName, vl_subscriptionMode, vl_varidx, "LoadVar");
v_StatCaptureControl_LoadVariableID := vl_varidx;
var EPTF_Var_DirectContent vl_currentContent;
f_EPTF_Var_getContent(v_StatCaptureControl_LoadVariableID, vl_currentContent);
if (not ischosen(vl_currentContent.boolVal)){ // the user must define a boolean Load Variable
f_EPTF_StatCaptureControl_error("Load Variable does not have a boolean value.");
//f_EPTF_Base_stop();
}
f_EPTF_Var_addPostProcFn(v_StatCaptureControl_LoadVariableID, {refers(f_EPTF_StatCaptureControl_Load_PostProc), {}});
f_EPTF_Var_callPostProcFns(v_StatCaptureControl_LoadVariableID);
}
}
else { //automatic capture control is switched off: not reading in & monitoring control Variables
v_StatCaptureControl_initialized := true;
v_StatCaptureControl_nrOfCaptures := 0;
v_StatCaptureControl_loadStableToStartL := 0.0;
v_StatCaptureControl_loadStableCapturePeriodL := 0.0;
v_StatCaptureControl_loadStableCaptureDelayL := 0.0;
}
f_EPTF_Base_registerCleanup(refers(f_EPTF_StatCaptureControl_cleanup));
f_EPTF_StatCaptureControl_debug("----StatCapture INIT DONE----");
}
///////////////////////////////////////////////////////////
// Altstep: as_EPTF_StatCaptureControl_LoadBased_default
//
// Purpose:
// This altstep is monitoring load stability and starting statistics capture.
//
// Parameters:
//
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
//
//
///////////////////////////////////////////////////////////
private altstep as_EPTF_StatCaptureControl_LoadBased_default () runs on EPTF_StatCaptureControl_CT {
[] t_loadStableToStart.timeout { //load has been stable so capture can be started
if (v_StatCaptureControl_nrOfCaptures < tsp_EPTF_StatCaptureControl_nrOfCaptures){
t_loadStableCapturePeriod.start(v_StatCaptureControl_loadStableCapturePeriodL);
f_EPTF_StatCapture_startCaptureAll("load-based");
}
repeat;
}
[] t_loadStableCapturePeriod.timeout { //load has been stable during the capture period --> valid measurement
f_EPTF_StatCapture_stopCaptureAll();
t_loadCaptureDelay.start(v_StatCaptureControl_loadStableCaptureDelayL);
repeat;
}
[] t_loadCaptureDelay.timeout {
v_StatCaptureControl_nrOfCaptures := v_StatCaptureControl_nrOfCaptures + 1;
if (v_StatCaptureControl_nrOfCaptures < tsp_EPTF_StatCaptureControl_nrOfCaptures){
t_loadStableToStart.start(v_StatCaptureControl_loadStableToStartL);
}
repeat;
}
}
private function f_EPTF_StatCaptureControl_User_PostProc(in integer pl_idx, in EPTF_IntegerList pl_argList) runs on EPTF_StatCaptureControl_CT {
var integer v_userVarID := pl_idx;
var EPTF_Var_DirectContent v_varContent;
f_EPTF_Var_getContent(v_userVarID, v_varContent);
if ((v_varContent.boolVal == true) and (tsp_EPTF_StatCaptureControl_captureControlMode == manual)){
f_EPTF_StatCapture_startCaptureAll("user");
}
else if ((v_varContent.boolVal == false) and (tsp_EPTF_StatCaptureControl_captureControlMode == manual)){
f_EPTF_StatCapture_stopCaptureAll();
}
}
private function f_EPTF_StatCaptureControl_Execution_PostProc(in integer pl_idx, in EPTF_IntegerList pl_argList) runs on EPTF_StatCaptureControl_CT {
var integer v_execVarID := pl_idx;
var EPTF_Var_DirectContent v_varContent;
f_EPTF_Var_getContent(v_execVarID, v_varContent)
if ((v_varContent.boolVal == true) and (tsp_EPTF_StatCaptureControl_captureControlMode == complete)){
f_EPTF_StatCapture_startCaptureAll("execution");
}
else if (v_varContent.boolVal == false) {
f_EPTF_StatCapture_stopCaptureAll();
}
}
private function f_EPTF_StatCaptureControl_Load_PostProc(in integer pl_idx, in EPTF_IntegerList pl_argList) runs on EPTF_StatCaptureControl_CT {
var integer v_loadVarID := pl_idx;
var EPTF_Var_DirectContent v_varContent;
f_EPTF_Var_getContent(v_loadVarID, v_varContent);
if ((v_varContent.boolVal == true) and (tsp_EPTF_StatCaptureControl_captureControlMode == loadBased)){
t_loadStableToStart.start(v_StatCaptureControl_loadStableToStartL); //restarts timer
}
if ((v_varContent.boolVal == false) and (tsp_EPTF_StatCaptureControl_captureControlMode == loadBased)){ //load is not stable
f_EPTF_StatCapture_stopCaptureAll(false);
t_loadStableCapturePeriod.stop; //stops timer
t_loadStableToStart.stop; //stops timer
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Private Functions
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
group Private {
///////////////////////////////////////////////////////////
// Function: f_EPTF_StatCaptureControl_cleanup
//
// Purpose:
// Cleanup function for the StatCaptureControl component
//
// Parameters:
// -
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
private function f_EPTF_StatCaptureControl_cleanup() runs on EPTF_StatCaptureControl_CT {
if (v_StatCaptureControl_initialized == false) {
return;
}
v_StatCaptureControl_initialized := false;
f_EPTF_StatCaptureControl_debug("----- STATCAPTURECONTROL CLEANUP DONE -------");
}
group Logging {
///////////////////////////////////////////////////////////
// Function: f_EPTF_StatCaptureControl_error
//
// Purpose:
// Function to log an error from StatCaptureControl feature.
//
// Parameters:
// - pl_message - *in* *charstring* - the message to log
//
// Return Value:
// -
//
// Errors & assertions:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
private function f_EPTF_StatCaptureControl_error(in charstring pl_message)
runs on EPTF_StatCaptureControl_CT
{
f_EPTF_Logging_error(true, tsp_EPTF_StatCaptureControl_loggingComponentMask&": "&pl_message);
f_EPTF_Base_stopAll();
}
///////////////////////////////////////////////////////////
// Function: f_EPTF_StatCaptureControl_warning
//
// Purpose:
// Function to log a warning from StatCaptureControl feature.
//
// Parameters:
// - pl_message - *in* *charstring* - the message to log
//
// Return Value:
// -
//
// Errors & assertions:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
private function f_EPTF_StatCaptureControl_warning(in @lazy charstring pl_message)
runs on EPTF_StatCaptureControl_CT
{
f_EPTF_Logging_warningV2(pl_message, v_StatCaptureControl_loggingMaskId, {c_EPTF_StatCapture_loggingClassIdx_Warning});
}
///////////////////////////////////////////////////////////
// Function: f_EPTF_StatCaptureControl_debug
//
// Purpose:
// Function to log a debug message from StatCaptureControl feature.
//
// Parameters:
// - pl_message - *in* *charstring* - the message to log
//
// Return Value:
// -
//
// Errors & assertions:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
private function f_EPTF_StatCaptureControl_debug(in @lazy charstring pl_message)
runs on EPTF_StatCaptureControl_CT
{
f_EPTF_Logging_debugV2(pl_message, v_StatCaptureControl_loggingMaskId, {c_EPTF_StatCapture_loggingClassIdx_Debug});
}
///////////////////////////////////////////////////////////
// Function: f_EPTF_StatCaptureControl_debugEnabled
//
// Purpose:
// Function to check if debug is enabled for StatCaptureControl
//
// Parameters:
// -
//
// Return Value:
// *boolean* - true if debug enalbed
//
// Errors & assertions:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
private function f_EPTF_StatCaptureControl_debugEnabled()
runs on EPTF_StatCaptureControl_CT
return boolean
{
return f_EPTF_Logging_isEnabled(v_StatCaptureControl_loggingMaskId, c_EPTF_StatCapture_loggingClassIdx_Debug);
}
} // group Logging
} //group private end
} // end of module