From 7fea14b407c9769f24c6020e7bd47f40cf7047e0 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 18 Dec 2006 08:19:42 +0000 Subject: [PATCH] sort queries based on expense --- src/sigar_ptql.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/sigar_ptql.c b/src/sigar_ptql.c index dbceb097..b43e1021 100644 --- a/src/sigar_ptql.c +++ b/src/sigar_ptql.c @@ -648,6 +648,16 @@ static int ptql_branch_add(ptql_parse_branch_t *parsed, return SIGAR_OK; } +static int ptql_branch_compare(const void *b1, const void *b2) +{ + /* XXX can do better */ + ptql_branch_t *branch1 = (ptql_branch_t *)b1; + ptql_branch_t *branch2 = (ptql_branch_t *)b2; + return + branch1->lookup->type - + branch2->lookup->type; +} + SIGAR_DECLARE(int) sigar_ptql_query_create(sigar_t *sigar, sigar_ptql_query_t **queryp, char *ptql) @@ -699,7 +709,12 @@ SIGAR_DECLARE(int) sigar_ptql_query_create(sigar_t *sigar, *queryp = NULL; } - /* XXX qsort query->branches.data */ + if (query->branches.number > 1) { + qsort(query->branches.data, + query->branches.number, + sizeof(query->branches.data[0]), + ptql_branch_compare); + } return status; }