From 1fc3061a58ac5dc64221ea423b3f3bfcc17d4d61 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sat, 21 Apr 2007 18:17:06 +0000 Subject: [PATCH] Avoid scanning the process list for single Pid.* queries --- .../src/org/hyperic/sigar/test/TestPTQL.java | 1 + src/sigar_ptql.c | 27 +++++++------------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java b/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java index 0e1bf36e..e8cba8c1 100644 --- a/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java +++ b/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java @@ -60,6 +60,7 @@ public class TestPTQL extends SigarTestCase { "Port.tcp.eq=8080,Cred.Uid.eq=1003", //dougm owned jboss port "Pid.PidFile.eq=pid.file", "Pid.Pid.eq=1", + "Pid.Pid.eq=$$", "Pid.Service.eq=Eventlog", "Pid.Service.eq=NOSUCHSERVICE", "Pid.Service.eq=Hyperic HQ Agent", diff --git a/src/sigar_ptql.c b/src/sigar_ptql.c index c15f0757..651c962e 100644 --- a/src/sigar_ptql.c +++ b/src/sigar_ptql.c @@ -710,23 +710,6 @@ static int ptql_pid_match(sigar_t *sigar, return (pid == match_pid) ? SIGAR_OK : !SIGAR_OK; } -static int sigar_ptql_pid_get(sigar_t *sigar, - sigar_ptql_query_t *query, - sigar_pid_t *query_pid) -{ - ptql_branch_t *branch; - - if (query->branches.number != 0) { - return ERANGE; - } - branch = &query->branches.data[0]; - if (!(branch->op_flags & PTQL_OP_FLAG_PID)) { - return EINVAL; - } - - return ptql_pid_get(sigar, branch, query_pid); -} - static int ptql_args_branch_init(ptql_parse_branch_t *parsed, ptql_branch_t *branch) { @@ -1369,9 +1352,17 @@ SIGAR_DECLARE(int) sigar_ptql_query_find_process(sigar_t *sigar, sigar_pid_t *pid) { sigar_proc_list_t pids; - int status = sigar_proc_list_get(sigar, &pids); + int status; int i, matches=0; + if ((query->branches.number == 1) && + (query->branches.data[0].op_flags & PTQL_OP_FLAG_PID)) + { + /* avoid scanning the process list for single Pid.* queries */ + return ptql_pid_get(sigar, &query->branches.data[0], pid); + } + + status = sigar_proc_list_get(sigar, &pids); if (status != SIGAR_OK) { return status; }