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

initial release

parents
Loading
Loading
Loading
Loading

Makefile

0 → 100644
+35 −0
Original line number Diff line number Diff line
# $Id: Makefile,v 1.1.1.1 2006/03/13 18:31:16 bino Exp $

# variables
PROGRAM=pbsacct
CC=c++
CFLAGS=-O -c
LFLAGS=-O
INSTALL_DIR=/usr/local/sbin

# make
VPATH=./

all: $(PROGRAM)

OBJECTS=main.o alloc.o read.o print.o

$(PROGRAM): $(OBJECTS)
	$(CC) $(LFLAGS) -o $(PROGRAM) $(OBJECTS)
	rm $(OBJECTS)

$(OBJECTS): main.h

$(OBJECTS): %.o: %.cpp
	$(CC) $(CFLAGS) $<

clean:
	rm -f $(PROGRAM) $(OBJECTS)

install:
	cp $(PROGRAM) $(INSTALL_DIR)
	cp mk_pbsacct   $(INSTALL_DIR)

uninstall:
	rm -f $(INSTALL_DIR)/$(PROGRAM)
	rm -f $(INSTALL_DIR)/mk_pbsacct

alloc.cpp

0 → 100644
+81 −0
Original line number Diff line number Diff line
//
//  alloc.cpp
//  pbsAccounting
//
//  Created by Fabio Roberto Vitello on 16/06/17.
//  Copyright © 2017 Fabio Roberto Vitello. All rights reserved.
//

#include "alloc.hpp"

/* $Id: alloc.c,v 1.1.1.1 2006/03/13 18:31:16 bino Exp $ */

#include <stdlib.h>
#include <string.h>
#include "main.h"

/* Allocation new group */
GROUP * new_group()
{
    GROUP *ptr;
    
    ptr = (GROUP *)malloc(sizeof(GROUP));
    if (ptr != NULL) {
        ptr->groupname[0]  = '\0';
        ptr->num_jobs      = 0;
        ptr->nodes         = 0;
        ptr->cpu_time      = 0.0;
        ptr->wall_time     = 0.0;
        ptr->all_cpu_time  = 0.0;
        ptr->all_wall_time = 0.0;
        ptr->p_next        = NULL;
        return(ptr);
    } else
        return(NULL);
}

/* Allocation new user */
USER * new_user()
{
    USER *ptr;
    
    ptr = (USER *)malloc(sizeof(USER));
    if (ptr != NULL) {
        ptr->username[0]   = '\0';
        ptr->num_jobs      = 0;
        ptr->nodes         = 0;
        ptr->cpu_time      = 0.0;
        ptr->wall_time     = 0.0;
        ptr->all_cpu_time  = 0.0;
        ptr->all_wall_time = 0.0;
        ptr->pg            = NULL;
        ptr->p_next        = NULL;
        return(ptr);
    } else
        return(NULL);
}


/* Clean groups */
void clean_groups(GROUP *ptr)
{
    GROUP *ptr_aux;
    
    while (ptr != NULL) {
        ptr_aux = ptr;
        ptr = ptr->p_next;
        free(ptr_aux);
    }
}

/* Clean users */
void clean_users(USER *ptr)
{
    USER *ptr_aux;
    
    while (ptr != NULL) {
        ptr_aux = ptr;
        ptr = ptr->p_next;
        free(ptr_aux);
    }
}

alloc.hpp

0 → 100644
+22 −0
Original line number Diff line number Diff line
//
//  alloc.hpp
//  pbsAccounting
//
//  Created by Fabio Roberto Vitello on 16/06/17.
//  Copyright © 2017 Fabio Roberto Vitello. All rights reserved.
//

#ifndef alloc_hpp
#define alloc_hpp

#include <stdio.h>
#include "main.h"

typedef struct group GROUP;
typedef struct user  USER;


void clean_groups(GROUP *ptr);
void clean_users(USER *ptr);

#endif /* alloc_hpp */

main.cpp

0 → 100644
+165 −0
Original line number Diff line number Diff line
/*
 * $Id: pbsacct.c,v 1.1.1.1 2006/03/13 18:31:16 bino Exp $
 *
 * pbsacct - program to make summary and report for PBS system.
 *
 * written by:  Albino Aveleda, bino@bino.eng.br
 *
 * options:
 *   -a          : report users and groups
 *   -u          : report users
 *   -g          : report groups
 *   -b value    : cost per hour
 *   -n opt      : opt = [0..3]
 *                 0: value * cputime
 *                 1: value * walltime (default)
 *                 2: value * cputime  * ncpus per job
 *                 3: value * walltime * ncpus per job
 *   -c          : cputime information
 *   -s          : statistic information
 *   -h          : help
 */

#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "main.h"

/* 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;
char   unit[4]={"SBU"};
double value;
int cpuvalue;

/* usage use */
void usage_exit(void)
{
    fputs("usage: pbsacct -h\n", stderr);
    exit(2);
}

/* Help */
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][-c][-s][-h] [file(s)]");
    puts("\toptions:");
    puts("\t-a       : report per-user and per-group usage");
    puts("\t-u       : report per-user usage");
    puts("\t-g       : report per-group usage");
    puts("\t-b value : cost per hour (working with -n options)");
    puts("\t-n opt   : select how the cost is calculate");
    puts("\t           opt = [0..3] where:");
    puts("\t           0: value * cputime");
    puts("\t           1: value * walltime (default)");
    puts("\t           2: value * cputime  * ncpus per job");
    puts("\t           3: value * walltime * ncpus per job");
    puts("\t           99: Custom Option added by Fabio Vitello to compute che cost for CHIPP in MUP Cluster");
    puts("\t-c       : include information about cputime");
    puts("\t           (if your operations system support)");
    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-h       : help");
    puts("\tIf there isn't input file, it use the stdin.\n");
    puts("\tExamples:");
    puts("\t- Make a statistic report per-user usage on 20 and 21");
    puts("\t  days in October, 2002.");
    puts("\t% pbsacct -u -s -p 24 -c 20021020 20021021\n");
    puts("\t- Make a report from a linux cluster in October, 2002");
    puts("\t  with informations per-user and per-group, where the");
    puts("\t  cost per hour is SBU=10.00 per CPU.");
    puts("\t% cat 200210* | pbsacct -a -p 24 -b 10.00 -n 3\n");
    exit(0);
}

/* parse args */
void parse_args(int ac, char **av)
{
    int options, err=0;
    
    while ((options = getopt(ac, av, "augb:B:np:sch"))!=EOF)
        switch(options) {
            case 'a':
                f_user = f_group = 1;
                break;
            case 'u':
                f_user = 1;
                break;
            case 'g':
                f_group = 1;
                break;
            case 'b':
                f_bill = 1;
                value = atof(optarg);
                if (value < 0.0) err=1;
                break;
            case 'n':
                opt = atoi(optarg);
                //99 is custom option for MUP cluster customizatio, author Fabio Vitello
                if ( ((opt < 0) && (opt > 3)) || (opt!=99) ) err=1;
                break;
            case 's':
                f_stat = 1;
                break;
            case 'c':
                f_cpu = 1;
                break;
            case 'p':
                cpuvalue = atoi(optarg);
                break;
            case 'h':
                help();
                break;
            default:
                usage_exit();
                break;
        }
    if (err) usage_exit();
}

/* Main program */
int main (int argc, char **argv)
{
    int  i;
    char myname[MAX_HOSTNAME_SIZE + 1] = {"\0"};
    
    /* check if there is argument */
    parse_args(argc, argv);
    
    /* check parameters */
    if ((f_user == 0)&&(f_group == 0)){
        fputs("Please, select per-user, per-group or both usage for make report.\n",stderr);
        fputs("For help typing: ./pbsacct -h\n",stderr);
        exit(2);
    }
    if (((opt == 0)||(opt == 2))&&(f_cpu == 0)){
        fputs("Please, use '-c' option with '-n 0' and '-n 2'.\n",stderr);
        exit(2);
    }
    /* get the hostname */
    gethostname(myname, sizeof(myname));
    
    /* initialize pointers */
    pgroups = NULL;
    pusers  = NULL;
    
    /* read file(s) */
    if (optind < argc)
        for (i=optind; i < argc; i++) {
            /* printf("argv[%d]=%s\n",i,argv[i]); */
            read_file(argv[i]);
        } else {
            f_stdin++;
            read_file("\0");
        }
    
    /* print report */
    print_report(myname);
    
    /* clean memory */
    clean_groups(pgroups);
    clean_users(pusers);
}

main.h

0 → 100644
+60 −0
Original line number Diff line number Diff line
//
//  main.h
//  pbsAccounting
//
//  Created by Fabio Roberto Vitello on 16/06/17.
//  Copyright © 2017 Fabio Roberto Vitello. All rights reserved.
//

#ifndef main_h
#define main_h

#include "read.hpp"
#include "print.hpp"
#include "alloc.hpp"

/* $Id: pbsacct.h,v 1.1.1.1 2006/03/13 18:31:16 bino Exp $ */

#define MAX_HOSTNAME_SIZE 256      /* max length of hostname */
#define MAX_NAME_SIZE     20       /* max length of name     */

typedef struct group GROUP;
typedef struct user  USER;

struct group {
    char   groupname[MAX_NAME_SIZE];
    int    num_jobs;
    int    nodes;
    double cpu_time;
    double wall_time;
    double all_cpu_time;
    double all_wall_time;
    GROUP  *p_next;
};

struct user {
    char   username[MAX_NAME_SIZE];
    int    num_jobs;
    int    nodes;
    double cpu_time;
    double wall_time;
    double all_cpu_time;
    double all_wall_time;
    GROUP  *pg;
    USER   *p_next;
};

/* global variables */
extern GROUP  *pgroups;
extern USER   *pusers;
extern int    f_user, f_group, f_bill, f_stat, f_cpu, f_stdin, opt;
extern char   unit[4];
extern double value;
extern int cpuvalue;


/* functions */
extern GROUP * new_group();
extern USER  * new_user();

#endif /* main_h */