blob: b4930f196c7c6558b38ce3a0eddaa8f91df37831 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2000-2017 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_LGenBasePerformTest_MTCFunctions
//
// Purpose:
// This module provides functions for testing LGenBase
//
// Module depends on:
// -
//
// Current Owner:
// Laszlo Skumat (ELSZSKU)
//
// Last Review Date:
// 2008-09-11
//
// Detailed Comments:
// Provide functions to test LGenBase
//
//
///////////////////////////////////////////////////////////////
module EPTF_LGenBasePerformTest_MTCFunctions
{
import from EPTF_LGenBasePerformTest_MTCDefinitions all
import from PIPEasp_Types all
import from EPTF_CLL_Base_Functions all
#ifdef R3
import from EPTF_CLL_Common_Definitions all
#endif
#ifdef R2
import from EPTF_CLL_Definitions all
#endif
function f_EPTF_LGenBasePerformanceTest_sendQuery(in charstring pl_command) // pl_commad - script
runs on EPTF_LGenBasePerformTest_MTC_CT
return charstring
{
log("Sending command on PIPE test port: " & pl_command);
const float c_guard := 300.0
var ASP_PExecute vl_pExecute := { command := "bash ", stdin := pl_command & "; exit" }
var ASP_PResult v_pResult
v_pipe_PCO.send(vl_pExecute);
timer t_guard
t_guard.start(c_guard);
alt
{
[] v_pipe_PCO.receive(ASP_PResult:?) -> value v_pResult
{
t_guard.stop;
if (v_pResult.stderr == "")
{
log("Received answer on PIPE test port: " & v_pResult.stdout);
return v_pResult.stdout;
}
else
{
log("PIPE test port error has occured: " & v_pResult.stderr);
f_EPTF_Base_stop()
}
return "";
}
[] t_guard.timeout
{
log("PIPE answer lost!");
f_EPTF_Base_stop()
}
}
log("Shouldn't be reached!");
f_EPTF_Base_stop()
return ""//v_pStdout.stdout;
}
function f_EPTF_LGenBasePerformanceTest_getMemUsage(
in charstring pl_processId)
runs on EPTF_LGenBasePerformTest_MTC_CT
return float
{
//it works only in linux
var charstring vl_cmd := "cat /proc/" & pl_processId & "/status | sed -ne '12p' | awk '{ print $2 }'";
var charstring vl_tmp := f_EPTF_LGenBasePerformanceTest_sendQuery(vl_cmd);
return int2float(str2int(vl_tmp)) / 1024.0;
}
function f_EPTF_LGenBasePerformanceTest_getCPUsage(
in charstring pl_processId)
runs on EPTF_LGenBasePerformTest_MTC_CT
return float
{
/* Solaris
var charstring vl_cmd := "prstat -c -p " & pl_processId & " 1 1 | sed -ne '2p' | awk '{ print $9 }' ";
/*/
// Linux
var charstring vl_cmd := "top -b -n 1 -p " & pl_processId & " | sed -ne '8p' | awk '{ print $9 }' "
//*/
var float vl_cpu;
var charstring vl_tmp;
vl_cpu := -1.0;
vl_tmp := f_EPTF_LGenBasePerformanceTest_sendQuery(vl_cmd);
if (vl_tmp == "") { return vl_cpu; };
if (vl_tmp[lengthof(vl_tmp) - 1] == "%") { vl_tmp := substr(vl_tmp, 0, lengthof(vl_tmp) - 1); };
if (regexp(vl_tmp, "([0-9]#(1,))", 0) != "")
{
//vl_cpu := int2float(v_TSTM_HostAdmin_Base_numCPUs) * str2float(vl_tmp);
vl_cpu := int2float(str2int(vl_tmp));
}
else if (regexp(vl_tmp, "([0-9]#(1,).[0-9]#(1,))", 0) != "")
{
//vl_cpu := int2float(v_TSTM_HostAdmin_Base_numCPUs) * str2float(vl_tmp);
vl_cpu := str2float(vl_tmp);
}
log(log2str("Acquired CPU usage: ", vl_cpu));
return vl_cpu;
}
} // end of module