From 8316f5e619d70d359e5b4ffa9e105d4cd4be94d0 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 7 Aug 2008 20:23:01 +0000 Subject: [PATCH] [SIGAR-117] fix Cpu.Percent ptql --- bindings/java/src/org/hyperic/sigar/test/TestPTQL.java | 10 ++++++++++ src/sigar_ptql.c | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java b/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java index c01c27c9..38321766 100644 --- a/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java +++ b/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java @@ -196,5 +196,15 @@ public class TestPTQL extends SigarTestCase { } this.qf.clear(); } + + public void testSelf() throws Exception { + Sigar sigar = getSigar(); + + //should have eaten some cpu during this test + ProcessQuery status = + this.qf.getQuery("Cpu.Percent.ge=0.01"); + long pid = sigar.getPid(); + assertTrue(status.match(sigar, pid)); + } } diff --git a/src/sigar_ptql.c b/src/sigar_ptql.c index 83f07544..834d6c11 100644 --- a/src/sigar_ptql.c +++ b/src/sigar_ptql.c @@ -624,6 +624,10 @@ static int ptql_branch_match(ptql_branch_t *branch) return branch->match.ui32(branch, *(sigar_uint32_t *)DATA_PTR(branch), branch->value.ui32); + case PTQL_VALUE_TYPE_DBL: + return branch->match.dbl(branch, + *(double *)DATA_PTR(branch), + branch->value.dbl); case PTQL_VALUE_TYPE_CHR: return branch->match.chr(branch, *(char *)DATA_PTR(branch), @@ -652,6 +656,10 @@ static int ptql_branch_match_ref(ptql_branch_t *branch, ptql_branch_t *ref) return branch->match.ui32(branch, *(sigar_uint32_t *)DATA_PTR(branch), *(sigar_uint32_t *)DATA_PTR(ref)); + case PTQL_VALUE_TYPE_DBL: + return branch->match.dbl(branch, + *(double *)DATA_PTR(branch), + *(double *)DATA_PTR(ref)); case PTQL_VALUE_TYPE_CHR: return branch->match.chr(branch, *(char *)DATA_PTR(branch), @@ -1253,7 +1261,7 @@ static ptql_lookup_t PTQL_Cpu[] = { { "User", PTQL_LOOKUP_ENTRY(proc_cpu, user, UI64) }, { "Sys", PTQL_LOOKUP_ENTRY(proc_cpu, sys, UI64) }, { "Total", PTQL_LOOKUP_ENTRY(proc_cpu, total, UI64) }, - { "Percent", PTQL_LOOKUP_ENTRY(proc_cpu, total, DBL) }, + { "Percent", PTQL_LOOKUP_ENTRY(proc_cpu, percent, DBL) }, { NULL } };