[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: cpu usage increase during runing script access c function.
- From: "Ong hean kuan" <mysurface@...>
- Date: Mon, 16 Jun 2008 17:47:24 +0800
Hi List:
I am writing a simulator for my company do to some load test, and uses lua script to call my c function to perform actual message send() through socket. While I carry on a simple load test, ( making 400 c function call per second from lua script), i observed that CPU usage keep increasing up to 90% until the load test end, the CPU usage goes down slowly.
As I run oprofile as back-end, i get the result list as below:
% cumulative self self total
time seconds seconds calls us/call us/call name
46.23 1.78 1.78 luaV_execute
10.65 2.19 0.41 LoadFunction
9.87 2.57 0.38 luaH_resizearray
7.53 2.86 0.29 luaH_next
4.16 3.02 0.16 luaF_newupval
3.12 3.14 0.12 luaL_ref
2.60 3.24 0.10 DumpFunction
2.34 3.33 0.09 lua_setfield
2.34 3.42 0.09 sort
1.30 3.47 0.05 errfile
1.30 3.52 0.05 luaF_newproto
1.04 3.56 0.04 luaL_findtable
1.04 3.60 0.04 tremove
0.78 3.63 0.03 newkey
0.52 3.65 0.02 auxsort
0.52 3.67 0.02 luaO_chunkid
0.52 3.69 0.02 luaO_pushvfstring
0.52 3.71 0.02 lua_cpcall
Here I show portion my codes that performs the calling, need your help to pin point the defects and suggestion to improves the performance.
int UCSimScript::Start()
{
L = lua_open();
luaL_openlibs(L);
mfInit = 1;
}
int UCSimScript::Execute(char * filename)
{
const struct luaL_reg oci [] = {
{"Call", &UCSimScript::L_Call}, //L_Call is a static function , i includes this function as below
{"CallAck", &UCSimScript::L_CallAck},
{"Alert", &UCSimScript::L_Alert},
{"Answer", &UCSimScript::L_Answer},
{"Release", &UCSimScript::L_Release},
{"ReleaseComplete", &UCSimScript::L_ReleaseComplete},
{"Refid", &UCSimScript::L_Refid},
{NULL, NULL} /* sentinel */
};
luaL_openlib(L, "oci", oci, 0);
if ( luaL_loadfile(L,filename) || lua_pcall(L, 0, 0, 0) )
{
Lua_Error("%s\n",lua_tostring(L, -1));
return -1;
}
return 1;
}
int UCSimScript::L_Call(lua_State * l)
{
int ret=0;
//tmp var
char tmp[100];
int type=-1;
//param var
int dir=1;
unsigned long long refid=0xFFFFFFFF;
int span=-1;
int chan=-1;
string ani="-1";
string dnis="-1";
int routeid=-1;
OCI* oci=0;
memset(tmp,0,sizeof tmp);
//first param (direction)
if ( lua_type(l, 1) == LUA_TNUMBER )
{
dir = lua_tointeger(l, 1);
}
else if ( lua_type(l, 1) != LUA_TNONE )
Lua_Error("Param 1 with wrong type or value");
//2nd param (refid)
if ( lua_type(l, 2) == LUA_TSTRING )
{
snprintf(tmp,sizeof tmp,"%s" , lua_tostring(l, 2) );
refid=strtoull(tmp,NULL,16);
}
else if ( lua_type(l, 2) != LUA_TNONE )
Lua_Error("Param 2 with wrong type or value");
//3nd param (span)
if ( lua_type(l, 3) == LUA_TNUMBER )
{
span = lua_tointeger(l, 3);
}
else if ( lua_type(l, 3) != LUA_TNONE )
Lua_Error("Param 3 with wrong type or value");
//4th param (chan)
if ( lua_type(l, 4) == LUA_TNUMBER )
{
chan = lua_tointeger(l, 4);
}
else if ( lua_type(l, 4) != LUA_TNONE )
Lua_Error("Param 4 with wrong type or value");
//5th param (ani)
if ( lua_type(l, 5) == LUA_TSTRING )
{
snprintf(tmp,sizeof tmp,"%s" , lua_tostring(l, 5) );
ani.assign(tmp);
}
else if ( lua_type(l, 5) != LUA_TNONE )
Lua_Error("Param 5 with wrong type or value");
//6th param (dnis)
if ( lua_type(l, 6) == LUA_TSTRING )
{
snprintf(tmp,sizeof tmp,"%s" , lua_tostring(l, 6) );
ani.assign(tmp);
}
else if ( lua_type(l, 6) != LUA_TNONE )
Lua_Error("Param 6 with wrong type or value");
//7th param (routeid)
if ( lua_type(l, 7) == LUA_TNUMBER )
{
routeid = lua_tointeger(l, 7);
}
else if ( lua_type(l, 7) != LUA_TNONE )
Lua_Error("Param 7 with wrong type or value");
//get the oci
UCOCIBuilder *OciBuilder = new UCOCIBuilder();
OciBuilder->SetCall(dir,refid,span,chan,ani,dnis,routeid);
oci = OciBuilder->GetOCI();
UCCommInterface *pCI;
if (!(pCI = UCCommInterface::GetCommInterface("comm_interface", false)))
{
printf(" cannot get comm_interface!\n");
delete OciBuilder;
return -1;
}
ret = pCI->Send(oci);
//
OciBuilder->Logging(oci,ret);
OciBuilder->Destroy();
delete OciBuilder;
return 1;
}
int UCSimScript::Stop()
{
if (L!=0 || mfInit==1)
{
lua_close(L);
L=0;
mfInit=0;
return 1;
}
return 0;
}
My class UCSimScript is a singleton class, therefore in main.cpp i execute the lua script as below:
#define SIMSCRIPT UCSimScript::Instance()
SIMSCRIPT.Start();
SIMSCRIPT.Execute(cmd);
SIMSCRIPT.Stop();
I am new to Lua, did anyone find any problems in my code?
--
Hean Kuan Ong
http://linux.byexamples.com
http://cc.byexamples.com
http://wordpress.byexamples.com