static char * FormatDeltaTime(char * pszDest, int cchDest, int tmDelta, const char * pszDeltaZero) { if (pszDeltaZero && tmDelta <= 0) { CopyAndPadToWidth(pszDest, pszDeltaZero, cchDest, ' ', PAD_LEFT); } else { CopyAndPadToWidth(pszDest, format_time_nosecs (tmDelta), cchDest, ' ', PAD_LEFT); } return pszDest; }
void new_record(int cluster, int proc, int start_time, int evict_time, int good_time, int cpu_usage, char const *host) { static bool initialized = false; char hash[40]; int wall_time = evict_time-start_time; // We detect bad records here. One cause of bad records is the // fact that userlogs timestamps do not contain years, so we // always assume we are in the same year, which causes time to run // backwards at the turn of the year. if (wall_time < 0 || good_time < 0 || cpu_usage < 0) { if (debug_mode) { fprintf(stderr, "internal error: negative time computed for " "%d.%d!\n", cluster, proc); fprintf(stderr, " (records around the turn of " "the year are not handled correctly)\n"); } return; } sprintf(hash, "%d.%d", cluster, proc); HashKey jobkey(hash); JobStatistics *js; if (Stats.lookup(jobkey, js) < 0) { js = new JobStatistics(cluster, proc); Stats.insert(jobkey, js); numJobStats++; } js->allocations++; js->kills += (wall_time != good_time); js->wall_time += wall_time; js->good_time += good_time; js->cpu_usage += cpu_usage; char ip_addr[128]; // only use the IP address in the key [TODO:IPV6] Parse IPv6 Addr strncpy(ip_addr, host+1, sizeof(ip_addr)-1); ip_addr[sizeof(ip_addr)-1] = '\0'; for (int i=0; i < 128; i++) { if (ip_addr[i] == ':') { ip_addr[i] = '\0'; break; } } HostStatistics *hs; HashKey hostkey(ip_addr); if (HStats.lookup(hostkey, hs) < 0) { condor_sockaddr addr; const char* hostname = NULL; MyString hostname_str; addr.from_sinful(host); if (!avoid_dns) { hostname_str = get_hostname(addr); hostname = hostname_str.Value(); } if (hostname == NULL) { hostname = ip_addr; } hs = new HostStatistics(hostname); HStats.insert(hostkey, hs); numHostStats++; } hs->allocations++; hs->kills += (wall_time != good_time); hs->wall_time += wall_time; hs->good_time += good_time; hs->cpu_usage += cpu_usage; if (!totals_only) { if (!raw_data && !initialized) { printf("\n"); printf("%-8.8s %-15.15s %-11.11s %-11.11s %9s %9s %9s\n", "Job", "Host", "Start Time", "Evict Time", "Wall Time", "Good Time", "CPU Usage"); initialized = true; } printf("%-8.8s %-15.15s ", hash, hs->host); printf("%11s ", format_date(start_time)); printf("%11s ", format_date(evict_time)); printf("%9s ", format_time_nosecs(wall_time)); printf("%9s ", format_time_nosecs(good_time)); printf("%9s\n", format_time_nosecs(cpu_usage)); } }
void display_stats() { int i; // display HostStatistics printf("%-15.15s %9.9s %9.9s %9.9s %9.9s %9.9s %7.7s %6.6s\n", "Host/Job", "Wall Time", "Good Time", "CPU Usage", "Avg Alloc", "Avg Lost", "Goodput", "Util."); printf("\n"); HostStatistics *hs; HStats.startIterations(); while (HStats.iterate(hs) == 1) { printf("%-15.15s ", hs->host); printf("%9.9s ", format_time_nosecs(hs->wall_time)); printf("%9.9s ", format_time_nosecs(hs->good_time)); printf("%9.9s ", format_time_nosecs(hs->cpu_usage)); printf("%9.9s ", format_time_nosecs(hs->wall_time/hs->allocations)); printf("%9.9s ", hs->kills ? format_time_nosecs((hs->wall_time-hs->good_time)/hs->kills) : "0+00:00"); printf("%6.1f%% %5.1f%%\n", hs->wall_time ? float(hs->good_time)/float(hs->wall_time)*100 : 0.0, hs->good_time ? float(hs->cpu_usage)/float(hs->good_time)*100 : 0.0); delete hs; } HStats.clear(); printf("\n"); // display JobStatistics JobStatistics **statarray = new JobStatistics* [numJobStats]; JobStatistics *js; Stats.startIterations(); for (i=0; Stats.iterate(js) == 1; i++) { statarray[i] = js; } qsort(statarray, numJobStats, sizeof(JobStatistics *), statsort); int allocations=0, kills=0; int wall_time=0, good_time=0, cpu_usage=0; char job[40]; for (i=0; i < numJobStats; i++) { js = statarray[i]; sprintf(job, "%d.%d", js->cluster, js->proc); printf("%-15.15s ", job); printf("%9.9s ", format_time_nosecs(js->wall_time)); printf("%9.9s ", format_time_nosecs(js->good_time)); printf("%9.9s ", format_time_nosecs(js->cpu_usage)); printf("%9.9s ", format_time_nosecs(js->wall_time/js->allocations)); printf("%9.9s ", js->kills ? format_time_nosecs((js->wall_time-js->good_time)/js->kills) : "0+00:00"); printf("%6.1f%% %5.1f%%\n", js->wall_time ? float(js->good_time)/float(js->wall_time)*100 : 0.0, js->good_time ? float(js->cpu_usage)/float(js->good_time)*100 : 0.0); allocations += js->allocations; kills += js->kills; wall_time += js->wall_time; good_time += js->good_time; cpu_usage += js->cpu_usage; delete js; } printf("\n"); printf("%-15.15s ", "Total"); printf("%9.9s ", format_time_nosecs(wall_time)); printf("%9.9s ", format_time_nosecs(good_time)); printf("%9.9s ", format_time_nosecs(cpu_usage)); printf("%9.9s ", allocations ? format_time_nosecs(wall_time/allocations) : "0+00:00"); printf("%9.9s ", kills ? format_time_nosecs((wall_time-good_time)/kills) : "0+00:00"); printf("%6.1f%% %5.1f%%\n", wall_time ? float(good_time)/float(wall_time)*100 : 0.0, good_time ? float(cpu_usage)/float(good_time)*100 : 0.0); Stats.clear(); delete [] statarray; }