From b31af8e7e38554449c81184e37489b1951d1f18f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zden=C4=9Bk=20=C5=A0ustr?= Date: Mon, 4 Dec 2006 17:00:10 +0000 Subject: [PATCH] edg_wll_JobStatus() now accepts flags to distinguish between fast/thorough histrogram computation. edg_wll_GetSubjobHistogram() declaration changed (it seems more logical to refer only to the histogram array instead of the whole state structure. The job_staus example now accepts "-fasthist" or "-fullhist" arguments and passes the appropriate flag. --- org.glite.lb.client/examples/job_status.c | 61 +++++++++++++++++++------------ org.glite.lb.server/src/jobstat.c | 41 +++++++++++++++------ org.glite.lb.server/src/jobstat.h | 2 +- 3 files changed, 68 insertions(+), 36 deletions(-) diff --git a/org.glite.lb.client/examples/job_status.c b/org.glite.lb.client/examples/job_status.c index a10612c..48e8e3b 100644 --- a/org.glite.lb.client/examples/job_status.c +++ b/org.glite.lb.client/examples/job_status.c @@ -26,7 +26,7 @@ int main(int argc,char *argv[]) { edg_wll_Context sctx[MAX_SERVERS]; char *servers[MAX_SERVERS]; - int i, result=0, nsrv=0; + int i, result=0, nsrv=0, wasaflag, histflags = 0; myname = argv[0]; @@ -98,30 +98,43 @@ int main(int argc,char *argv[]) memset(&status,0,sizeof status); + wasaflag = 0; // Indicates that the argument was a flag - if (edg_wlc_JobIdParse(argv[i],&job)) { - fprintf(stderr,"%s: %s: cannot parse jobId\n", myname,argv[i]); - continue; + if ( !strcmp(argv[i], "-fullhist") ) { + wasaflag = 1; + histflags = EDG_WLL_STAT_CHILDHIST_THOROUGH; + } + + if ( !strcmp(argv[i], "-fasthist") ) { + wasaflag = 1; + histflags = EDG_WLL_STAT_CHILDHIST_FAST; + } + + if (!wasaflag) { + if (edg_wlc_JobIdParse(argv[i],&job)) { + fprintf(stderr,"%s: %s: cannot parse jobId\n", myname,argv[i]); + continue; + } + bserver = edg_wlc_JobIdGetServer(job); + if (!bserver) { + fprintf(stderr,"%s: %s: cannot extract bookkeeping server address\n", myname,argv[i]); + edg_wlc_JobIdFree(job); + continue; + } + for ( j = 0; j < nsrv && strcmp(bserver, servers[j]); j++ ); + if ( j == nsrv ) { + if ( i > 0 ) edg_wll_InitContext(&sctx[j]); + nsrv++; + servers[j] = bserver; + } + + if (edg_wll_JobStatus(sctx[j], job, EDG_WLL_STAT_CLASSADS | EDG_WLL_STAT_CHILDREN | EDG_WLL_STAT_CHILDSTAT | histflags, &status)) { + dgerr(sctx[j],"edg_wll_JobStatus"); result = 1; + } else printstat(status,0); + + if (job) edg_wlc_JobIdFree(job); + if (status.state) edg_wll_FreeStatus(&status); } - bserver = edg_wlc_JobIdGetServer(job); - if (!bserver) { - fprintf(stderr,"%s: %s: cannot extract bookkeeping server address\n", myname,argv[i]); - edg_wlc_JobIdFree(job); - continue; - } - for ( j = 0; j < nsrv && strcmp(bserver, servers[j]); j++ ); - if ( j == nsrv ) { - if ( i > 0 ) edg_wll_InitContext(&sctx[j]); - nsrv++; - servers[j] = bserver; - } - - if (edg_wll_JobStatus(sctx[j], job, EDG_WLL_STAT_CLASSADS | EDG_WLL_STAT_CHILDREN | EDG_WLL_STAT_CHILDSTAT, &status)) { - dgerr(sctx[j],"edg_wll_JobStatus"); result = 1; - } else printstat(status,0); - - if (job) edg_wlc_JobIdFree(job); - if (status.state) edg_wll_FreeStatus(&status); } for ( i = 0; i < nsrv; i++ ) edg_wll_FreeContext(sctx[i]); @@ -131,7 +144,7 @@ int main(int argc,char *argv[]) static void usage(char *name) { - fprintf(stderr,"Usage: %s job_id [-x lb_proxy_serve_sock] [job_id [...]]\n", name); + fprintf(stderr,"Usage: %s job_id [-x lb_proxy_serve_sock] [-fasthist|-fullhist] [job_id [...]]\n", name); fprintf(stderr," %s -all\n", name); } diff --git a/org.glite.lb.server/src/jobstat.c b/org.glite.lb.server/src/jobstat.c index 8c6c491..7c71d96 100644 --- a/org.glite.lb.server/src/jobstat.c +++ b/org.glite.lb.server/src/jobstat.c @@ -165,18 +165,26 @@ int edg_wll_JobStatus( #if DAG_ENABLE if (stat->jobtype == EDG_WLL_STAT_DAG || stat->jobtype == EDG_WLL_STAT_COLLECTION) { -// printf("edg_wll_JobStatus:i EDG_WLL_STAT_DAG || EDG_WLL_STAT_COLLECTION\n"); -// printf("flags: %d",flags); +// XXX: The users does not want any histogram. What do we do about it? +// if ((!(flags & EDG_WLL_STAT_CHILDHIST_FAST))&&(!(flags & EDG_WLL_STAT_CHILDHIST_THOROUGH))) { /* No Histogram */ +// if (stat->children_hist != NULL) { /* No histogram will be sent even if there was one */ +// +// printf("\nNo Histogram required\n\n"); +// +// free(stat->children_hist); +// } +// +// } if (flags & EDG_WLL_STAT_CHILDHIST_FAST) { /* Fast Histogram */ -// printf("edg_wll_JobStatus: EDG_WLL_STAT_CHILDHIST_FAST\n"); - - edg_wll_GetSubjobHistogram(ctx, job, stat); - + if (stat->children_hist == NULL) { + // If the histogram exists, assume that it was already filled during job state retrieval + stat->children_hist = (int*) calloc(1+EDG_WLL_NUMBER_OF_STATCODES, sizeof(int)); + edg_wll_GetSubjobHistogram(ctx, job, stat->children_hist); + } } if (flags & EDG_WLL_STAT_CHILDHIST_THOROUGH) { /* Full (thorough) Histogram */ -// printf("edg_wll_JobStatus: EDG_WLL_STAT_CHILDHIST_THOROUGH\n"); char *out[2]; edg_wll_Stmt sh; @@ -188,7 +196,7 @@ int edg_wll_JobStatus( } else { /* If hist is loaded, it probably contain only incomplete histogram - * builded in update_parent_status. Count it from scratch... + * built in update_parent_status. Count it from scratch... */ for (i=1; i<=EDG_WLL_NUMBER_OF_STATCODES; i++) stat->children_hist[i] = 0; @@ -997,13 +1005,14 @@ edg_wll_ErrorCode edg_wll_StepIntState(edg_wll_Context ctx, } -edg_wll_ErrorCode edg_wll_GetSubjobHistogram(edg_wll_Context ctx, edg_wlc_JobId parent_jobid, intJobStat **ijs) +edg_wll_ErrorCode edg_wll_GetSubjobHistogram(edg_wll_Context ctx, edg_wlc_JobId parent_jobid, int *hist) { - char *stmt = NULL,*out = NULL; + char *stmt = NULL,*out = NULL, *rest = NULL; edg_wll_Stmt sh; - int f = -1; + int f = -1, i; char *jobid_md5; + intJobStat *ijs = NULL; jobid_md5 = edg_wlc_JobIdGetUnique(parent_jobid); @@ -1023,9 +1032,19 @@ edg_wll_ErrorCode edg_wll_GetSubjobHistogram(edg_wll_Context ctx, edg_wlc_JobId out = NULL; edg_wll_SetError(ctx, ENOENT, NULL); } + else { + // Ready to read the histogram from the record returned + rest = (char *)calloc(1,strlen(out)); + ijs = dec_intJobStat(out, &rest); + for (i=0;i<=EDG_WLL_NUMBER_OF_STATCODES;i++) hist[i] = ijs->pub.children_hist[i]; + } } edg_wll_FreeStmt(&sh); free(stmt); + if (rest==NULL) free(rest); + if (ijs==NULL) free(rest); + + return edg_wll_Error(ctx, NULL, NULL); } diff --git a/org.glite.lb.server/src/jobstat.h b/org.glite.lb.server/src/jobstat.h index dace952..2d346db 100644 --- a/org.glite.lb.server/src/jobstat.h +++ b/org.glite.lb.server/src/jobstat.h @@ -85,7 +85,7 @@ int edg_wll_compare_seq(const char *, const char *); void init_intJobStat(intJobStat *p); -edg_wll_ErrorCode edg_wll_GetSubjobHistogram(edg_wll_Context, edg_wlc_JobId parent_jobid, intJobStat **ijs); +edg_wll_ErrorCode edg_wll_GetSubjobHistogram(edg_wll_Context, edg_wlc_JobId parent_jobid, int *hist); edg_wll_ErrorCode edg_wll_StoreSubjobHistogram(edg_wll_Context, edg_wlc_JobId parent_jobid, intJobStat *ijs); #endif -- 1.8.2.3