fix handlers print formating. add show port requests functionality
authorFilippos Giannakos <philipgian@grnet.gr>
Tue, 6 Nov 2012 17:46:26 +0000 (19:46 +0200)
committerFilippos Giannakos <philipgian@grnet.gr>
Tue, 6 Nov 2012 17:46:26 +0000 (19:46 +0200)
xseg/peers/user/Makefile
xseg/peers/user/xseg-tool.c
xseg/xtypes/xhash_exports.h

index dc8db75..d849b1c 100644 (file)
@@ -22,7 +22,7 @@ sosd: sosd.c $(BASE)/xseg/xseg.h $(BASE)/util_libs/user/sos/sos.h
        $(CC) $(CFLAGS) -o $@ $< $(INC) -L$(LIB) -lxseg -lsos
 
 xseg: xseg-tool.c $(BASE)/xseg/xseg.h
-       $(CC) $(CFLAGS) -o $@ $< $(INC) -L$(LIB) -lxseg
+       $(CC) $(CFLAGS) -o $@ $< $(BASE)/xtypes/xheap.c $(INC) -L$(LIB) -lxseg
 
 mt-sosd: mt-sosd.c peer.c peer.h
        $(CC) $(CFLAGS) -o $@ $< peer.c $(INC) -L$(LIB) -lxseg -lrados -lpthread -DMT
index a18d1d3..4b7bb88 100644 (file)
@@ -9,6 +9,8 @@
 #include <fcntl.h>
 #include <unistd.h>
 
+#include <xtypes/xhash.h>
+#include <xtypes/xobj.h>
 #include <xseg/xseg.h>
 #include <xseg/protocol.h>
 int help(void)
@@ -194,7 +196,7 @@ void report_request(struct xseg_request *req)
        //if (max > 128)
        //      max = 128;
        //data[max-1] = 0;
-       fprintf(stderr, "request %llu state %u\n", (unsigned long long)req->serial, req->state);
+       fprintf(stderr, "request %lx state %u\n", (unsigned long )req, req->state);
 }
 
 int cmd_info(char *target)
@@ -242,7 +244,6 @@ int cmd_read(char *target, uint64_t offset, uint64_t size)
        xport p;
        char *req_target;
        struct xseg_request *req = xseg_get_request(xseg, srcport, dstport, X_ALLOC);
-       printf("%x\n", req);
        if (!req) {
                fprintf(stderr, "No request\n");
                return -1;
@@ -963,14 +964,16 @@ int cmd_report(uint32_t portno)
        pq = xseg_get_queue(xseg, port, reply_queue);
        fprintf(stderr, "port %u:\n"
                "   requests: %llu/%llu  src gw: %u  dst gw: %u\n"
-               "       free_queue [%p] count : %u\n"
-               "    request_queue [%p] count : %u\n"
-               "      reply_queue [%p] count : %u\n",
-               portno, port->alloc_reqs, port->max_alloc_reqs,
-               xseg->src_gw[portno], xseg->dst_gw[portno],
-               (void *)fq, xq_count(fq),
-               (void *)rq, xq_count(rq),
-               (void *)pq, xq_count(pq));
+               "       free_queue [%p] count : %llu\n"
+               "    request_queue [%p] count : %llu\n"
+               "      reply_queue [%p] count : %llu\n",
+               portno, (unsigned long long)port->alloc_reqs, 
+               (unsigned long long)port->max_alloc_reqs,
+               xseg->src_gw[portno],
+               xseg->dst_gw[portno],
+               (void *)fq, (unsigned long long)xq_count(fq),
+               (void *)rq, (unsigned long long)xq_count(rq),
+               (void *)pq, (unsigned long long)xq_count(pq));
        return 0;
 }
 
@@ -986,6 +989,15 @@ int cmd_join(void)
        }
        return 0;
 }
+static void print_hanlder(char *name, struct xobject_h *obj_h)
+{
+       fprintf(stderr, "%20s: free: %4llu, allocated: %4llu, allocated space: %7llu (object size: %llu)\n",
+                       name,
+                       (unsigned long long) obj_h->nr_free,
+                       (unsigned long long) obj_h->nr_allocated,
+                       (unsigned long long) obj_h->allocated_space,
+                       (unsigned long long) obj_h->obj_size);
+}
 
 int cmd_reportall(void)
 {
@@ -995,26 +1007,49 @@ int cmd_reportall(void)
                return -1;
 
 
-       fprintf(stderr, "Heap usage: %llu / %llu\n", xseg->heap->cur, xseg->config.heap_size);
-       fprintf(stderr, "Requests handler: free: %llu, allocated: %llu, allocated space %llu\n", 
-                       (unsigned long long) xseg->request_h->nr_free,
-                       (unsigned long long) xseg->request_h->nr_allocated,
-                       (unsigned long long) xseg->request_h->allocated_space);
-       fprintf(stderr, "Ports handler: free: %llu, allocated: %llu, allocated space %llu\n", 
-                       (unsigned long long) xseg->port_h->nr_free,
-                       (unsigned long long) xseg->port_h->nr_allocated,
-                       (unsigned long long) xseg->port_h->allocated_space);
-       fprintf(stderr, "objects handler: free: %llu, allocated: %llu, allocated space %llu\n", 
-                       (unsigned long long) xseg->object_handlers->nr_free,
-                       (unsigned long long) xseg->object_handlers->nr_allocated,
-                       (unsigned long long) xseg->object_handlers->allocated_space);
+       fprintf(stderr, "Heap usage: %llu / %llu\n",
+                       (unsigned long long)xseg->heap->cur,
+                       (unsigned long long)xseg->config.heap_size);
+       fprintf(stderr, "Handlers: \n");
+       print_hanlder("Requests handler", xseg->request_h);
+       print_hanlder("Ports handler", xseg->port_h);
+       print_hanlder("Objects handler", xseg->object_handlers);
        fprintf(stderr, "\n");
+
        for (t = 0; t < xseg->config.nr_ports; t++)
                cmd_report(t);
 
        return 0;
 }
 
+int cmd_showrequests(xport portno)
+{
+       if (cmd_join())
+               return -1;
+
+       struct xobject_h *obj_h = xseg->request_h;
+       void *container = XPTR(&obj_h->container);
+       xhash_t *allocated = XPTR_TAKE(obj_h->allocated, container);
+       xhash_iter_t it;
+       xhash_iter_init(allocated, &it);
+       xhashidx key, val;
+       int i;
+       while (xhash_iterate(allocated, &it, &key, &val)){
+               void *mem = XPTR_TAKE(val, container);
+               struct xseg_request *req = mem, *t;
+               for (i = 0; i < xheap_get_chunk_size(mem)/obj_h->obj_size; i++) {
+                       t = req + i;
+                       if (t->src_portno == portno){
+                               fprintf(stderr, "%d ,req: %lx ", i, t);
+                               report_request(t);
+                       }
+               }
+       }
+
+       fprintf(stderr, "\n");
+       return 0;
+}
+
 int cmd_create(void)
 {
        int r = xseg_create(&cfg);
@@ -1308,6 +1343,12 @@ int main(int argc, char **argv)
                        continue;
                }
 
+               if (!strcmp(argv[i], "showreqs") && (i + 1 < argc)) {
+                       ret = cmd_showrequests(atol(argv[i+1]));
+                       i += 1;
+                       continue;
+               }
+
                if (!strcmp(argv[i], "signal") && (i + 1 < argc)) {
                        ret = cmd_signal(atol(argv[i+1]));
                        i += 1;
index 7b9561e..3660dab 100644 (file)
@@ -11,3 +11,5 @@ EXPORT_SYMBOL(xhash_freql_update);
 EXPORT_SYMBOL(xhash_delete);
 EXPORT_SYMBOL(xhash_lookup);
 EXPORT_SYMBOL(xhash_print);
+EXPORT_SYMBOL(xhash_iter_init);
+EXPORT_SYMBOL(xhash_iterate);