[SIGAR-90] move Service to its own class

This commit is contained in:
Doug MacEachern 2008-03-05 04:19:39 +00:00
parent b74e11d769
commit da6d72a31e
2 changed files with 38 additions and 27 deletions

View File

@ -67,10 +67,10 @@ public class TestPTQL extends SigarTestCase {
"Pid.PidFile.eq=pid.file", "Pid.PidFile.eq=pid.file",
"Pid.Pid.eq=1", "Pid.Pid.eq=1",
THIS_PROCESS, THIS_PROCESS,
"Pid.Service.eq=Eventlog", "Pid.Service.eq=Eventlog", //compat -> Service.Name
"Pid.Service.eq=NOSUCHSERVICE", "Service.Name.eq=NOSUCHSERVICE",
"Pid.Service.ct=Oracle", "Service.Name.ct=Oracle",
"Pid.ServiceDisplay.re=DHCP|DNS", "Service.DisplayName.re=DHCP|DNS",
OTHER_JAVA_PROCESS, //all java procs cept this one OTHER_JAVA_PROCESS, //all java procs cept this one
"Cpu.Percent.ge=0.2", "Cpu.Percent.ge=0.2",
"State.Name.sw=java,Args.*.eq=org.jboss.Main", //jboss "State.Name.sw=java,Args.*.eq=org.jboss.Main", //jboss

View File

@ -665,8 +665,29 @@ enum {
#endif #endif
#define PID_SERVICE_ATTR "Service" static int ptql_branch_init_service(ptql_parse_branch_t *parsed,
#define PID_SERVICE_ATTR_LEN (sizeof(PID_SERVICE_ATTR)-1) ptql_branch_t *branch,
sigar_ptql_error_t *error)
{
branch->op_flags |= PTQL_OP_FLAG_PID;
if (strEQ(parsed->attr, "Name")) {
branch->flags = PTQL_PID_SERVICE;
}
else if (strEQ(parsed->attr, "DisplayName")) {
branch->flags = PTQL_PID_SERVICE_DISPLAY;
}
else {
return ptql_error(error, "Unsupported %s attribute: %s",
parsed->name, parsed->attr);
}
#ifdef WIN32
branch->data.str = sigar_strdup(parsed->value);
branch->data_size = strlen(parsed->value);
#endif
return SIGAR_OK;
}
static int ptql_branch_init_pid(ptql_parse_branch_t *parsed, static int ptql_branch_init_pid(ptql_parse_branch_t *parsed,
ptql_branch_t *branch, ptql_branch_t *branch,
@ -694,27 +715,6 @@ static int ptql_branch_init_pid(ptql_parse_branch_t *parsed,
branch->data_size = strlen(parsed->value); branch->data_size = strlen(parsed->value);
return SIGAR_OK; return SIGAR_OK;
} }
else if (strnEQ(parsed->attr,
PID_SERVICE_ATTR, PID_SERVICE_ATTR_LEN))
{
char *attr = parsed->attr + PID_SERVICE_ATTR_LEN;
branch->flags = 0;
if (*attr) {
if (strEQ(attr, "Display")) {
branch->flags = PTQL_PID_SERVICE_DISPLAY;
}
}
else {
branch->flags = PTQL_PID_SERVICE;
}
if (branch->flags) {
#ifdef WIN32
branch->data.str = sigar_strdup(parsed->value);
branch->data_size = strlen(parsed->value);
#endif
return SIGAR_OK;
}
}
return ptql_error(error, "Unsupported %s attribute: %s", return ptql_error(error, "Unsupported %s attribute: %s",
parsed->name, parsed->attr); parsed->name, parsed->attr);
@ -1124,6 +1124,10 @@ static ptql_lookup_t PTQL_Pid[] = {
{ NULL, ptql_pid_match, 0, 0, PTQL_VALUE_TYPE_ANY, ptql_branch_init_pid } { NULL, ptql_pid_match, 0, 0, PTQL_VALUE_TYPE_ANY, ptql_branch_init_pid }
}; };
static ptql_lookup_t PTQL_Service[] = {
{ NULL, ptql_pid_match, 0, 0, PTQL_VALUE_TYPE_ANY, ptql_branch_init_service }
};
static ptql_entry_t ptql_map[] = { static ptql_entry_t ptql_map[] = {
{ "Time", PTQL_Time }, { "Time", PTQL_Time },
{ "Cpu", PTQL_Cpu }, { "Cpu", PTQL_Cpu },
@ -1137,6 +1141,7 @@ static ptql_entry_t ptql_map[] = {
{ "Env", PTQL_Env }, { "Env", PTQL_Env },
{ "Port", PTQL_Port }, { "Port", PTQL_Port },
{ "Pid", PTQL_Pid }, { "Pid", PTQL_Pid },
{ "Service", PTQL_Service },
{ NULL } { NULL }
}; };
@ -1192,6 +1197,12 @@ static int ptql_branch_parse(char *query, ptql_parse_branch_t *branch,
return ptql_error(error, "Missing query"); return ptql_error(error, "Missing query");
} }
/* Pid.Service -> Service.Name */
if (strEQ(branch->attr, "Service")) {
branch->name = branch->attr;
branch->attr = "Name";
}
return SIGAR_OK; return SIGAR_OK;
} }