|
@@ -13,8 +13,8 @@
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
* GNU General Public License for more details.
|
|
|
*
|
|
|
- * You should have received a copy of the GNU General Public License
|
|
|
- * along with this program; if not, write to the Free Software
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
+ * along with this program; if not, write to the Free Software
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
*
|
|
|
*/
|
|
@@ -23,7 +23,7 @@
|
|
|
#include "../../rpc_lookup.h"
|
|
|
/*??? #include "rpc.h" */
|
|
|
/*??? #include "top.h" */
|
|
|
-#include "../../timer.h" /* ticks_t */
|
|
|
+#include "../../timer.h" /* ticks_t */
|
|
|
|
|
|
#include "../../dprint.h"
|
|
|
#include "pike_top.h"
|
|
@@ -44,11 +44,11 @@ static void traverse_subtree( struct ip_node *node, int depth, int options )
|
|
|
static unsigned char ip_addr[MAX_DEPTH];
|
|
|
|
|
|
struct ip_node *foo;
|
|
|
-
|
|
|
+
|
|
|
DBG("pike:rpc traverse_subtree, depth: %d, byte: %d", depth, node->byte);
|
|
|
|
|
|
assert( depth < MAX_DEPTH );
|
|
|
-
|
|
|
+
|
|
|
ip_addr[depth] = node->byte;
|
|
|
|
|
|
if ( node->flags & NODE_IPLEAF_FLAG ) {
|
|
@@ -73,7 +73,7 @@ static void traverse_subtree( struct ip_node *node, int depth, int options )
|
|
|
DBG("pike:rpc traverse_subtree, not IP leaf, depth: %d, ip: %d.%d.%d.%d hits[%d,%d], expires: %d",
|
|
|
depth, ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3], node->hits[0], node->hits[1], node->expires - get_ticks());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
foo = node->kids;
|
|
|
while (foo) {
|
|
|
traverse_subtree( foo, depth + 1, options );
|
|
@@ -88,7 +88,7 @@ static void collect_data(int options)
|
|
|
g_max_hits = get_max_hits();
|
|
|
|
|
|
DBG("pike: collect_data");
|
|
|
-
|
|
|
+
|
|
|
// maybe try_lock first and than do the rest?
|
|
|
for(i=0;i<MAX_IP_BRANCHES;i++) {
|
|
|
if (get_tree_branch(i)==0)
|
|
@@ -98,7 +98,7 @@ static void collect_data(int options)
|
|
|
if (get_tree_branch(i))
|
|
|
traverse_subtree( get_tree_branch(i), 0, options );
|
|
|
unlock_tree_branch(i);
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/* do not use static buffer with this function */
|
|
@@ -107,7 +107,7 @@ static char *concat(char *buff, size_t buffsize, const char *first, int second)
|
|
|
{
|
|
|
int rv;
|
|
|
size_t size;
|
|
|
-
|
|
|
+
|
|
|
while ( (rv = snprintf(buff, buffsize, "%s%d", first, second)) >= buffsize ) {
|
|
|
size = rv > 128 ? rv : 128;
|
|
|
buff = (char *)realloc(buff, size);
|
|
@@ -141,13 +141,13 @@ static void pike_top(rpc_t *rpc, void *c)
|
|
|
int options = 0;
|
|
|
|
|
|
DBG("pike: top");
|
|
|
-
|
|
|
+
|
|
|
/* obtain params */
|
|
|
if (rpc->scan(c, "s", &stropts) <= 0)
|
|
|
stropts = "HOT";
|
|
|
|
|
|
DBG("pike:top: string options: '%s'", stropts);
|
|
|
- if ( strstr(stropts, "ALL") ) {
|
|
|
+ if ( strstr(stropts, "ALL") ) {
|
|
|
options = NODE_STATUS_ALL;
|
|
|
} else if ( strstr(stropts, "HOT") ) {
|
|
|
options |= NODE_STATUS_HOT;
|
|
@@ -161,14 +161,14 @@ static void pike_top(rpc_t *rpc, void *c)
|
|
|
rpc->fault(c, 500, "Bad argument. Select: ALL, HOT or WARM");
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
print_tree( 0 );
|
|
|
-
|
|
|
+
|
|
|
collect_data(options);
|
|
|
top_list_root = pike_top_get_root();
|
|
|
DBG("pike_top: top_list_root = %p", top_list_root);
|
|
|
-
|
|
|
+
|
|
|
rpc->add(c, "{", &handle);
|
|
|
rpc->struct_add(handle, "d", "max_hits", get_max_hits());
|
|
|
i = 0; // it is passed as number of rows
|
|
@@ -180,7 +180,7 @@ static void pike_top(rpc_t *rpc, void *c)
|
|
|
pike_top_print_addr(ti->ip_addr, ti->addr_len, addr_buff, sizeof(addr_buff));
|
|
|
DBG("pike:top: result[%d]: %s leaf_hits[%d,%d] hits[%d,%d] expires: %d status: 0x%02x",
|
|
|
i, addr_buff, ti->leaf_hits[0], ti->leaf_hits[1],
|
|
|
- ti->hits[0], ti->hits[1], ti->expires, ti->status);
|
|
|
+ ti->hits[0], ti->hits[1], ti->expires, ti->status);
|
|
|
rpc->struct_add(handle, "sddds",
|
|
|
concat(ip_addr, ip_addr_size, "ip_addr", i), addr_buff,
|
|
|
concat(leaf_hits_prev, leaf_hits_prev_size, "leaf_hits_prev", i), ti->leaf_hits[0],
|
|
@@ -197,7 +197,7 @@ static void pike_top(rpc_t *rpc, void *c)
|
|
|
free(expires);
|
|
|
free(status);
|
|
|
pike_top_list_clear();
|
|
|
-
|
|
|
+
|
|
|
rpc->send(c);
|
|
|
}
|
|
|
|
|
@@ -209,8 +209,8 @@ static const char* pike_top_doc[] = {
|
|
|
0 /* Method signature(s) */
|
|
|
};
|
|
|
|
|
|
-/*
|
|
|
- * RPC Methods exported by this module
|
|
|
+/*
|
|
|
+ * RPC Methods exported by this module
|
|
|
*/
|
|
|
|
|
|
rpc_export_t pike_rpc_methods[] = {
|