Commit 7ebb43c9 authored by Fabio Roberto Vitello's avatar Fabio Roberto Vitello
Browse files

bug fix on memory accounting

parent 28708394
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -20,6 +20,11 @@
 *   -h          : help
 */

//  Created by Fabio Roberto Vitello on 16/06/17.
//  Copyright © 2017 Fabio Roberto Vitello. All rights reserved.
//


#include <cstdlib>
#include <stdio.h>
#include <string.h>
@@ -29,7 +34,7 @@
/* global variables */
GROUP  *pgroups;
USER   *pusers;
int    f_user=0, f_group=0, f_bill=0, f_stat=0, f_cpu=0, f_stdin=0, opt=1, memorypernode;
int    f_user=0, f_group=0, f_bill=0, f_stat=0, f_cpu=0, f_stdin=0, opt=1, memorypernode,noverbose=0;
char   unit[4]={"SBU"};
double value;
int cpuvalue;
@@ -45,7 +50,7 @@ void usage_exit(void)
void help()
{
    puts("pbsacct:  program to make summary and report for PBS system.");
    puts("usage:  pbsacct [-a][-u][-g][-b value][-n opt][-p value][-m value][-c][-s][-h] [file(s)]");
    puts("usage:  pbsacct [-a][-u][-g][-b value][-n opt][-p value][-m value][-z][-c][-s][-h] [file(s)]");
    puts("\toptions:");
    puts("\t-a       : report per-user and per-group usage");
    puts("\t-u       : report per-user usage");
@@ -63,6 +68,7 @@ void help()
    puts("\t-s       : include statistic information");
    puts("\t-p       Custom Option added by Fabio Vitello: set the number of core to compute the to compute cputime in case of exclusive node request");
    puts("\t-m       Custom Option added by Fabio Vitello: set the memory per node in GB");
    puts("\t-z       Custom Option added by Fabio Vitello: no verbose");
    puts("\t-h       : help");
    puts("\tIf there isn't input file, it use the stdin.\n");
    puts("\tExamples:");
@@ -87,7 +93,7 @@ void parse_args(int ac, char **av)
    f_cpu = 1;
*/
    
    while ((options = getopt(ac, av, "augb:B:np:m:sch"))!=EOF)
    while ((options = getopt(ac, av, "augb:B:np:m:zsch"))!=EOF)
        switch(options) {
            case 'a':
                f_user = f_group = 1;
@@ -120,6 +126,9 @@ void parse_args(int ac, char **av)
            case 'm':
                memorypernode = atoi(optarg);
                break;
            case 'z':
                noverbose=1;
                break;
            case 'h':
                help();
                break;
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ struct user {
/* global variables */
extern GROUP  *pgroups;
extern USER   *pusers;
extern int    f_user, f_group, f_bill, f_stat, f_cpu, f_stdin, opt;
extern int    f_user, f_group, f_bill, f_stat, f_cpu, f_stdin, opt,noverbose;
extern char   unit[4];
extern double value;
extern int cpuvalue;
+24 −11
Original line number Diff line number Diff line
@@ -21,9 +21,11 @@ void print_report(char *hostname)
    USER   *pu;
    double total;
    
    if (!noverbose)
    {
        printf("\n*** Portable Batch System accounting ***\n");
        printf("Server Name: %s\n", hostname);
    
    }
    f_cpu=false;
    f_stat=false;
    /* print report user */
@@ -86,23 +88,33 @@ void print_report(char *hostname)
    
    /* print report group */
    if (f_group) {
        if (!noverbose)
        {
            printf("\n*** PBS Per-Group Usage Report ***\n");
            printf("Group     #Jobs    Wall(h)");
        if (f_cpu) {
        }
        if (f_cpu && !noverbose) {
            printf("     CPU(h)");
            if (f_stat) printf("  Efcy(%)");
        }
        if (f_stat) {
        if (f_stat && !noverbose) {
            printf("  Av.Wall(h)");
            if (f_cpu) printf("  Av.CPU(h)");
            printf("  Av.#CPU");
        }
        printf("   Sum Wall(h)");
        if (f_cpu) printf("   Sum CPU(h)");
        if (f_bill) printf("%14s",unit);
        printf("\n");
        if ( !noverbose)        printf("   Sum Wall(h)");
        if (f_cpu && !noverbose) printf("   Sum CPU(h)");
        if (f_bill && !noverbose) printf("%14s",unit);
        if ( !noverbose)  printf("\n");
        pg = pgroups;
        while (pg != NULL){
            if (noverbose)
            {
                printf("%-9s ",pg->groupname);
                printf(" %13.4f",(pg->all_wall_time/60));
            }
            else
            {
            printf("%-9s %5d %10.4f",pg->groupname,
                   pg->num_jobs,(pg->wall_time/60));
            if (f_cpu) {
@@ -133,6 +145,7 @@ void print_report(char *hostname)
                }
                printf("%14.2f",total);
            }
            }
            printf("\n");
            pg = pg->p_next;
        }
+23 −7
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
/* read file(s) */
void read_file(char *file)
{
    int    len, nodes, hour, min, sec, test, linenum = 0, reqmemory,corememory;
    int    len, nodes,cpu, hour, min, sec, test, linenum = 0, reqmemory,corememory=0;
    double cpu_used, wall_used, memorypercore;
    char   buffer[BUFSIZ], *p, *ptr, *line;
    char   uid[MAX_NAME_SIZE], gid[MAX_NAME_SIZE];
@@ -64,8 +64,8 @@ void read_file(char *file)
                    p[strlen(p)-2] = 0;
                    reqmemory = atoi(p);
                    corememory = floor((float)reqmemory/((float)memorypernode/cpuvalue));
                    if (corememory>cpuvalue)
                        corememory=cpuvalue;
              //      if (corememory>cpuvalue)
                //        corememory=cpuvalue;
                }
                //    nodes = atoi(p);
            }
@@ -82,16 +82,29 @@ void read_file(char *file)
            if (ptr != NULL) {
                p = strtok(ptr, "=");
                p = strtok(NULL, "=");
                nodes = atoi(p);
                cpu = atoi(p);
                
               
                if (corememory>nodes)
                    nodes=corememory;
                
                strcpy(line, buffer);
                ptr = strstr(line, "Resource_List.nodect");
                p = strtok(ptr, "=");
                p = strtok(NULL, "=");
                nodes *= atoi(p);
                nodes = atoi(p);
                
                corememory=corememory/nodes;
                if (corememory>cpuvalue)
                    corememory=cpuvalue;
                
                if (corememory>(cpu/nodes))
                {
                    nodes=corememory*nodes;
                }
                else
                {
                    nodes=cpu;

                }
                
            } else {
                nodes = 1;
@@ -156,9 +169,12 @@ void read_file(char *file)
                strcpy(line, buffer);
                ptr = strstr(line, "resources_used.cput");
                if (ptr == NULL) {
                    if(!noverbose)
                    {
                    fprintf(stderr,
                            "Warning: No used.cput data on line %d, skipping...\n",
                            linenum);
                    }
                    free(line);
                    continue;
                }