Permalink
Browse files

new tag

  • Loading branch information...
2 parents c1127a0 + d09d578 commit 027331b39b00de5188dfd5ec7991234d897f4edc @dannyauble dannyauble committed Dec 30, 2008
Showing with 91 additions and 3 deletions.
  1. +24 −0 src/sreport/common.c
  2. +1 −0 src/sreport/sreport.h
  3. +66 −3 src/sreport/user_reports.c
View
@@ -433,3 +433,27 @@ extern int sort_assoc_dec(sreport_assoc_rec_t *assoc_a,
return 0;
}
+extern int get_uint(char *in_value, uint32_t *out_value, char *type)
+{
+ char *ptr = NULL, *meat = NULL;
+ long num;
+
+ if(!(meat = strip_quotes(in_value, NULL))) {
+ error("Problem with strip_quotes");
+ return SLURM_ERROR;
+ }
+ num = strtol(meat, &ptr, 10);
+ if ((num == 0) && ptr && ptr[0]) {
+ error("Invalid value for %s (%s)", type, meat);
+ xfree(meat);
+ return SLURM_ERROR;
+ }
+ xfree(meat);
+
+ if (num < 0)
+ *out_value = INFINITE; /* flag to clear */
+ else
+ *out_value = (uint32_t) num;
+ return SLURM_SUCCESS;
+}
+
View
@@ -153,5 +153,6 @@ extern int sort_cluster_dec(sreport_cluster_rec_t *cluster_a,
extern int sort_assoc_dec(sreport_assoc_rec_t *assoc_a,
sreport_assoc_rec_t *assoc_b);
+extern int get_uint(char *in_value, uint32_t *out_value, char *type);
#endif /* HAVE_SREPORT_H */
View
@@ -49,7 +49,7 @@ enum {
static List print_fields_list = NULL; /* types are of print_field_t */
static bool group_accts = false;
-static int top_limit = 10;
+static uint32_t top_limit = 10;
static int _set_cond(int *start, int argc, char *argv[],
acct_user_cond_t *user_cond, List format_list)
@@ -131,6 +131,11 @@ static int _set_cond(int *start, int argc, char *argv[],
MAX(command_len, 1))) {
assoc_cond->usage_start = parse_time(argv[i]+end, 1);
set = 1;
+ } else if (!strncasecmp (argv[i], "TopCount",
+ MAX(command_len, 1))) {
+ if (get_uint(argv[i]+end, &top_limit, "TopCount")
+ != SLURM_SUCCESS)
+ exit_code = 1;
} else {
exit_code=1;
fprintf(stderr, " Unknown condition: %s\n"
@@ -240,17 +245,20 @@ extern int user_top(int argc, char *argv[])
{
int rc = SLURM_SUCCESS;
acct_user_cond_t *user_cond = xmalloc(sizeof(acct_user_cond_t));
+ acct_cluster_cond_t cluster_cond;
ListIterator itr = NULL;
ListIterator itr2 = NULL;
ListIterator itr3 = NULL;
ListIterator cluster_itr = NULL;
List format_list = list_create(slurm_destroy_char);
List user_list = NULL;
+ List usage_cluster_list = NULL;
List cluster_list = list_create(destroy_sreport_cluster_rec);
char *object = NULL;
int i=0;
acct_user_rec_t *user = NULL;
+ acct_cluster_rec_t *cluster = NULL;
acct_association_rec_t *assoc = NULL;
acct_accounting_rec_t *assoc_acct = NULL;
sreport_user_rec_t *sreport_user = NULL;
@@ -274,6 +282,58 @@ extern int user_top(int argc, char *argv[])
fprintf(stderr, " Problem with user query.\n");
goto end_it;
}
+ /* We have to get the clusters here or we will be unable to
+ get the correct total time for the cluster if associations
+ are not enforced.
+ */
+ memset(&cluster_cond, 0, sizeof(acct_cluster_cond_t));
+ cluster_cond.with_usage = 1;
+ cluster_cond.with_deleted = 1;
+ cluster_cond.usage_end = user_cond->assoc_cond->usage_end;
+ cluster_cond.usage_start = user_cond->assoc_cond->usage_start;
+ cluster_cond.cluster_list = user_cond->assoc_cond->cluster_list;
+ usage_cluster_list = acct_storage_g_get_clusters(
+ db_conn, my_uid, &cluster_cond);
+ if(!usage_cluster_list) {
+ exit_code=1;
+ fprintf(stderr, " Problem with cluster query.\n");
+ goto end_it;
+ }
+
+ itr = list_iterator_create(usage_cluster_list);
+ while((cluster = list_next(itr))) {
+ cluster_accounting_rec_t *accting = NULL;
+
+ /* check to see if this cluster is around during the
+ time we are looking at */
+ if(!cluster->accounting_list
+ || !list_count(cluster->accounting_list))
+ continue;
+
+ sreport_cluster = xmalloc(sizeof(sreport_cluster_rec_t));
+
+ list_append(cluster_list, sreport_cluster);
+
+ sreport_cluster->name = xstrdup(cluster->name);
+ sreport_cluster->user_list =
+ list_create(destroy_sreport_user_rec);
+
+ /* get the amount of time and the average cpu count
+ during the time we are looking at */
+ cluster_itr = list_iterator_create(cluster->accounting_list);
+ while((accting = list_next(cluster_itr))) {
+ sreport_cluster->cpu_secs += accting->alloc_secs
+ + accting->down_secs + accting->idle_secs
+ + accting->resv_secs;
+ sreport_cluster->cpu_count += accting->cpu_count;
+ }
+ list_iterator_destroy(cluster_itr);
+
+ sreport_cluster->cpu_count /=
+ list_count(cluster->accounting_list);
+ }
+ list_iterator_destroy(itr);
+ list_destroy(usage_cluster_list);
if(print_fields_have_header) {
char start_char[20];
@@ -367,6 +427,9 @@ extern int user_top(int argc, char *argv[])
}
}
if(!sreport_cluster) {
+ error("This cluster '%s' hasn't "
+ "registered yet, but we have jobs "
+ "that ran?", assoc->cluster);
sreport_cluster =
xmalloc(sizeof(sreport_cluster_rec_t));
list_append(cluster_list, sreport_cluster);
@@ -399,8 +462,8 @@ extern int user_top(int argc, char *argv[])
while((assoc_acct = list_next(itr3))) {
sreport_user->cpu_secs +=
(uint64_t)assoc_acct->alloc_secs;
- sreport_cluster->cpu_secs +=
- (uint64_t)assoc_acct->alloc_secs;
+/* sreport_cluster->cpu_secs += */
+/* (uint64_t)assoc_acct->alloc_secs; */
}
list_iterator_destroy(itr3);
}

0 comments on commit 027331b

Please sign in to comment.