|
@@ -35,6 +35,7 @@
|
|
|
#define TAG SPBASE_TAG("sp_mod")
|
|
|
|
|
|
#include "toolkit.h"
|
|
|
+#include "StartUpBase.h"
|
|
|
|
|
|
#define BUFSIZE 10240
|
|
|
#define MOD_CMD_INIT 0
|
|
@@ -943,18 +944,20 @@ static int create_module_process(const char *mod_name, int epid, int range, int
|
|
|
CloseHandle(hUserTokenDup);
|
|
|
CloseHandle(hThisToken);
|
|
|
|
|
|
- DbgWithLinkForC(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM, "begin start mod by pipe, %s", mod_name);
|
|
|
+ addStartupStep(entity_id, "start_mod", "", 0, 0, 0);
|
|
|
//通过管道通知进程创建实体线程
|
|
|
if (NULL != (groupProcess = findGroupProcessInfo(group, mod_name)) && 0 == startModByPipe(groupProcess, writeParam)) {
|
|
|
char dstParam[10][MAX_PATH];
|
|
|
int paramNum = 0;
|
|
|
ZeroMemory(dstParam, sizeof(dstParam));
|
|
|
- DbgWithLinkForC(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM, "query mod by pipe, %s", mod_name);
|
|
|
+ addStartupStep(entity_id, "query_mod", "", 0, 0, 0);
|
|
|
if (-1 != (paramNum = queryModByPipe(groupProcess, mod_name, dstParam))) //return paramNum
|
|
|
{
|
|
|
+ char processId[20];
|
|
|
HANDLE processMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, dstParam[2]);
|
|
|
new_process->pid = (int)groupProcess->pid;
|
|
|
- DbgWithLinkForC(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM, "return processId %d", new_process->pid);
|
|
|
+ sprintf(processId, "%d", new_process->pid);
|
|
|
+ addStartupStep(entity_id, "open_process_id", processId, 0, 0, 0);
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
@@ -1021,7 +1024,7 @@ static void mgr_on_entity_state(sp_mod_mgr_t *mgr, sp_entity_t *entity, int trig
|
|
|
mgr_bcast_entity_state_event(mgr, entity, SP_PKT_MOD|MOD_CMD_RECORD_STATE_EVENT, pkt);
|
|
|
iobuffer_dec_ref(pkt);
|
|
|
|
|
|
- DbgWithLinkForC(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM, "entity %s change state from %d to %d", entity->cfg->name, last_state, curr_state);
|
|
|
+ addStartupStep(entity->cfg->idx, "state_change", "", last_state, curr_state, 0);
|
|
|
|
|
|
// gui显示实体状态变化
|
|
|
env = sp_get_env();
|
|
@@ -1775,8 +1778,7 @@ static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id,
|
|
|
{
|
|
|
int rc = 0;
|
|
|
sp_env_t *env = sp_get_env();
|
|
|
-
|
|
|
- DbgWithLinkForC(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM, "begin load module %s", mod->cfg->name);
|
|
|
+ addStartupStep(mod->cfg->idx, "begin_load", "", 0, 0, 0);
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
@@ -1817,18 +1819,18 @@ static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id,
|
|
|
DWORD dwRet;
|
|
|
dwRet = WaitForSingleObject(mod->process.handle, (DWORD)interval); //wait for entity thread end
|
|
|
if (dwRet == WAIT_OBJECT_0) {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM, "detect %s's process exit exception!", mod->cfg->name);
|
|
|
+ addStartupStep(mod->cfg->idx, "mod_online", "process exit exception!", 0, 0, Error_Exception);
|
|
|
rc = Error_Exception;
|
|
|
break;
|
|
|
}
|
|
|
} else {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM, "mod is online now!, %s", mod->cfg->name);
|
|
|
+ addStartupStep(mod->cfg->idx, "mod_online", "", 0, 0, 0);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "get epid state failed!");
|
|
|
+ addStartupStep(mod->cfg->idx, "mod_online", "get epid state failed!", 0, 0, Error_Exception);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -1836,9 +1838,9 @@ static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id,
|
|
|
if (rc == 0)
|
|
|
rc = sp_svc_send(mgr->shell_svc, mod->cfg->idx, SP_INVALID_SVC_ID, SP_PKT_MOD|MOD_CMD_INIT, 0, NULL);
|
|
|
if (rc) {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM, "send out mod init cmd to %s(%d) failed: %s", mod->cfg->name, mod->cfg->idx, sp_strerror(rc));
|
|
|
+ addStartupStep(mod->cfg->idx, "send_init", "failed", 0, 0, rc);
|
|
|
} else {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM, "send out mod init cmd ok!, %s", mod->cfg->name);
|
|
|
+ addStartupStep(mod->cfg->idx, "send_init", "", 0, 0, 0);
|
|
|
for (i = 0; i < tries; ++i) {
|
|
|
#ifdef _WIN32
|
|
|
HANDLE hs[] = { mod->evt_wait_handle, mod->process.handle }; //wait for entity thread end
|
|
@@ -1853,21 +1855,22 @@ static int load_module(sp_mod_mgr_t *mgr, sp_mod_t *mod, int trigger_entity_id,
|
|
|
}
|
|
|
#endif //_WIN32
|
|
|
if (dwRet == WAIT_OBJECT_0) {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM, "receive reply from module %s ok!", mod->cfg->name);
|
|
|
+ addStartupStep(mod->cfg->idx, "entity_reply", "", 0, 0, 0);
|
|
|
rc = mod->wait_result;
|
|
|
if (rc != 0) {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "receive reply from module %s ok! but wait rc: %s", mod->cfg->name, sp_strerror(rc));
|
|
|
+ addStartupStep(mod->cfg->idx, "entity_reply", "failed", 0, 0, rc);
|
|
|
}
|
|
|
break;
|
|
|
} else if (dwRet == WAIT_OBJECT_0+1) {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "detect %s's process exit exception!", mod->cfg->name);
|
|
|
+ addStartupStep(mod->cfg->idx, "entity_reply", "process end", 0, 0, Error_Exception);
|
|
|
rc = Error_Exception;
|
|
|
break;
|
|
|
} else if(dwRet == WAIT_TIMEOUT) {
|
|
|
+ addStartupStep(mod->cfg->idx, "entity_reply", "timeout", 0, 0, Error_TimeOut);
|
|
|
rc = Error_TimeOut;
|
|
|
}
|
|
|
else {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM, "wait for multi object failed!! err=%d", GetLastError());
|
|
|
+ addStartupStep(mod->cfg->idx, "entity_reply", "multi obj", 0, 0, Error_Unexpect);
|
|
|
rc = Error_Unexpect;
|
|
|
break;
|
|
|
}
|
|
@@ -2084,7 +2087,7 @@ static int start_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, const char *cmdline
|
|
|
int rc = 0;
|
|
|
sp_mod_t *mod = ent->mod;
|
|
|
|
|
|
- DbgWithLinkForC(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM, "begin start entity %s", ent->cfg->name);
|
|
|
+ addStartupLog(mod->cfg->name, mod->cfg->idx);
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
sp_mod_mgr_lockEx(mod->cfg->idx);
|
|
@@ -2101,7 +2104,7 @@ static int start_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, const char *cmdline
|
|
|
rc = sp_svc_send(mgr->shell_svc, mod->cfg->idx, ent->cfg->idx, SP_PKT_MOD|MOD_CMD_START, ent->cfg->idx, &pkt);
|
|
|
if (rc == 0) {
|
|
|
int last_state = ent->state;
|
|
|
- DbgWithLinkForC(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM, "start entity %s, send cmd start ok!", ent->cfg->name);
|
|
|
+ addStartupStep(mod->cfg->idx, "send_start", "", 0, 0, 0);
|
|
|
ent->state_start_time = y2k_time_now();
|
|
|
if (ent->first_start_time == 0)
|
|
|
ent->first_start_time = ent->state_start_time;
|
|
@@ -2109,16 +2112,16 @@ static int start_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, const char *cmdline
|
|
|
ent->state = EntityState_Starting;
|
|
|
mgr_on_entity_state(mgr, ent, trigger_entity_id, last_state, ent->state);
|
|
|
} else {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM, "start entity %s, send cmd start failed!", ent->cfg->name);
|
|
|
+ addStartupStep(mod->cfg->idx, "send_start", "failed", 0, 0, Error_Unexpect);
|
|
|
}
|
|
|
if (pkt)
|
|
|
iobuffer_dec_ref(pkt);
|
|
|
} else {
|
|
|
rc = Error_InvalidState;
|
|
|
- DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "%s: entity %s state is not correct! current state: %d", __FUNCTION__, ent->cfg->name, (int)ent->state);
|
|
|
+ addStartupStep(mod->cfg->idx, "send_start", "state is not correct", 0, 0, Error_InvalidState);
|
|
|
}
|
|
|
} else {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "entity's %s 's module is not load!", ent->cfg->name);
|
|
|
+ addStartupStep(mod->cfg->idx, "send_start", "module is not load", 0, 0, Error_InvalidState);
|
|
|
rc = Error_InvalidState;
|
|
|
}
|
|
|
#ifdef _WIN32
|
|
@@ -2132,16 +2135,16 @@ static int start_entity(sp_mod_mgr_t *mgr, sp_entity_t *ent, const char *cmdline
|
|
|
HANDLE hs[] = {mod->evt_app_exit, ent->evt_wait_handle};
|
|
|
DWORD dwRet = WaitForMultipleObjects(array_size(hs), &hs[0], FALSE, PROCESS_TIMEOUT);
|
|
|
if (dwRet == WAIT_OBJECT_0) {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM, "wait for start entity %s result, app exit!", ent->cfg->name);
|
|
|
+ addStartupStep(mod->cfg->idx, "wait_result", "app exit", 0, 0, Error_Unexpect);
|
|
|
rc = Error_Unexpect;
|
|
|
} else if (dwRet == WAIT_OBJECT_0+1) {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM, "wait for start entity %s result ok, result = %d!", ent->cfg->name, ent->wait_result);
|
|
|
+ addStartupStep(mod->cfg->idx, "wait_result", "", 0, 0, 0);
|
|
|
rc = ent->wait_result;
|
|
|
if (rc != 0) {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM, "wait for starting entity %s and turned out result: %s!", ent->cfg->name, sp_strerror(ent->wait_result));
|
|
|
+ addStartupStep(mod->cfg->idx, "wait_result", "turned out result", 0, 0, ent->wait_result);
|
|
|
}
|
|
|
} else {
|
|
|
- DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "wait for start entity %s timeout!", ent->cfg->name);
|
|
|
+ addStartupStep(mod->cfg->idx, "wait_result", "timeout", 0, 0, Error_TimeOut);
|
|
|
rc = Error_TimeOut;
|
|
|
}
|
|
|
|