-f fields option
authorAleš Křenek <ljocha@ics.muni.cz>
Thu, 16 Oct 2008 16:07:22 +0000 (16:07 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Thu, 16 Oct 2008 16:07:22 +0000 (16:07 +0000)
org.glite.lb.utils/Makefile
org.glite.lb.utils/src/state_history.c

index c1634ff..3e03c34 100644 (file)
@@ -53,9 +53,11 @@ EXT_LIBS:= \
        ${expatlib} -lexpat
 COMMON_LIB:=-lglite_lb_common_${nothrflavour}
 CLIENT_LIB:=-lglite_lb_client_${nothrflavour}
+PLUS_LIB:=-lglite_lb_clientpp_${nothrflavour}
 JP_LIBS:=-lglite_jp_common_${nothrflavour}
 
-UTILS:=mon purge dump load dump_exporter state_history
+UTILS:=mon purge dump load dump_exporter
+ALLUTILS:=${UTILS} state_history statistics
 STATISTICS_OBJS:=statistics.o process_attrs.o process_attrs2.o
 
 MAN_GZ:=glite-lb-mon.1.gz
@@ -64,7 +66,7 @@ MAN = $(MAN_GZ:.gz=)
 
 default: all
 
-compile all: ${UTILS} ${MAN_GZ} statistics
+compile all: ${ALLUTILS} ${MAN_GZ}
 
 ${UTILS}: %: %.o
        ${LINK} -o $@ $< ${COMMON_LIB} ${CLIENT_LIB} ${EXT_LIBS} -lglite_lbu_maildir
@@ -73,7 +75,7 @@ statistics: ${STATISTICS_OBJS}
        ${LINK} -rdynamic -o $@ ${STATISTICS_OBJS} ${COMMON_LIB} ${JP_LIBS} ${EXT_LIBS} 
 
 state_history: state_history.o
-       ${LINK} -o $@ state_history.o -L${stagedir}/lib -lglite_lb_statemachine ${CLIENT_LIB} ${COMMON_LIB}
+       ${LINK} -o $@ state_history.o -L${stagedir}/lib -lglite_lb_statemachine ${PLUS_LIB}
 
 check: compile 
 
@@ -97,10 +99,9 @@ install:
        ${INSTALL} -m 644 ${MAN_GZ} ${PREFIX}/share/man/man1
        ${INSTALL} -m 755 ${top_srcdir}/src/glite-lb-bkpurge-offline.sh ${PREFIX}/bin/glite-lb-bkpurge-offline
 
-       for p in ${UTILS} ; do \
+       for p in ${ALLUTILS} ; do \
                ${INSTALL} -m 755 "$$p" "${PREFIX}/bin/glite-lb-$$p"; \
        done
-       ${INSTALL} -m 755 statistics ${PREFIX}/bin/glite-lb-statistics
 
 clean:
        rm -rfv ${UTILS} statistics ${MAN_GZ} *.{lo,o} .libs/
index 6fbdf6a..6c38ba1 100644 (file)
@@ -1,26 +1,45 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "glite/lb/context.h"
 #include "glite/lb/consumer.h"
 
 #include "glite/lb/intjobstat.h"
 #include "glite/lb/seqcode_aux.h"
+#include "glite/lb/stat_fields.h"
+#include "glite/lb/process_event.h"
 
-/*comment */
+#define usage() { \
+       fprintf(stderr,"usage: %s [-f fields] <jobid>\n",argv[0]); \
+       fprintf(stderr,"\navailable fields:\n\t"); \
+       glite_lb_dump_stat_fields(); \
+       putc(10,stderr); \
+}
 
 int main (int argc, char ** argv)
 {
        edg_wll_Context ctx;
        edg_wll_QueryRec        jc[2];
        edg_wll_Event   *events;
-       int     i,n;
+       int     i,n,opt;
        intJobStat      is;
+       char    *farg = "network_server,jdl:VirtualOrganisation,destination,done_code,reason";
+       void    *fields;
+
+       while ((opt = getopt(argc,argv,"f:")) != -1) switch (opt) {
+               case 'f': farg = optarg; break;
+               default: usage(); return 1;
+       }
+
 
        memset(&jc,0,sizeof jc);
-       if (argc != 2 || glite_jobid_parse(argv[1],&jc[0].value.j)) {
-               fprintf(stderr,"usage: %s <jobid>\n",argv[0]);
+       if (optind+1 != argc
+                       || glite_jobid_parse(argv[optind],&jc[0].value.j)
+                       || glite_lb_parse_stat_fields(farg,&fields))
+       {
+               usage();
                return 1;
        }
 
@@ -39,18 +58,20 @@ int main (int argc, char ** argv)
        for (n=0; events[n].type; n++);
 
        init_intJobStat(&is);
+       glite_jobid_dup(jc[0].value.j,&is.pub.jobId);
 
        qsort(events,n,sizeof *events,compare_events_by_seq);
 
        for (i=0; i<n; i++) {
-               char    *err;
+               char    *err,*evnt = NULL;
                if (processEvent(&is,events+i,0,0,&err) == RET_FATAL) {
                        fprintf(stderr,"event %d: %s\n",i,err);
                        return 1;
                }
 
-               printf ("%s %s\n",edg_wll_EventToString(events[i].type),
-                               edg_wll_StatToString(is.pub.state));
+               printf("%s\t",evnt = edg_wll_EventToString(events[i].type));
+               free(evnt); evnt = NULL;
+               glite_lb_print_stat_fields(fields,&is.pub);   
        }
 
        return 0;