From 878b98cd8e0d25b33a0c5ccd26a93d15fe8c4b96 Mon Sep 17 00:00:00 2001 From: Danny Auble <da@llnl.gov> Date: Mon, 20 Sep 2004 20:15:27 +0000 Subject: [PATCH] broke smap into function files minor bug fixes and reality checks added. --- src/smap/Makefile.am | 4 +- src/smap/configure_functions.c | 190 +++++++++++ src/smap/grid_functions.c | 169 ++++++++++ src/smap/job_functions.c | 183 +++++++++++ src/smap/opts.c | 60 +--- src/smap/partition_functions.c | 211 ++++++++++++ src/smap/smap.c | 583 +++++++-------------------------- src/smap/smap.h | 42 ++- 8 files changed, 917 insertions(+), 525 deletions(-) create mode 100644 src/smap/configure_functions.c create mode 100644 src/smap/grid_functions.c create mode 100644 src/smap/job_functions.c create mode 100644 src/smap/partition_functions.c diff --git a/src/smap/Makefile.am b/src/smap/Makefile.am index cd894cc4a23..f70e2f793b3 100644 --- a/src/smap/Makefile.am +++ b/src/smap/Makefile.am @@ -4,7 +4,7 @@ AUTOMAKE_OPTIONS = foreign -LIBS=-lncurses +LIBS=-lcurses INCLUDES = -I$(top_srcdir) -I bin_PROGRAMS = smap @@ -13,7 +13,7 @@ smap_LDADD = \ $(top_builddir)/src/api/libslurm.la noinst_HEADERS = smap.h -smap_SOURCES = smap.c opts.c +smap_SOURCES = smap.c job_functions.c partition_functions.c configure_functions.c grid_functions.c opts.c force: $(smap_LDADD) : force diff --git a/src/smap/configure_functions.c b/src/smap/configure_functions.c new file mode 100644 index 00000000000..777f5f7602c --- /dev/null +++ b/src/smap/configure_functions.c @@ -0,0 +1,190 @@ +/*****************************************************************************\ + * configure_functions.c - Functions related to configure mode of smap. + ***************************************************************************** + * Copyright (C) 2002 The Regents of the University of California. + * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). + * Written by Danny Auble <da@llnl.gov> + * + * UCRL-CODE-2002-040. + * + * This file is part of SLURM, a resource management program. + * For details, see <http://www.llnl.gov/linux/slurm/>. + * + * SLURM is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * SLURM is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with SLURM; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +\*****************************************************************************/ + +#include "src/smap/smap.h" + +typedef struct { + int type; + char str[80]; +} command_info_t; + +void print_header_command(void); +int print_text_command(void); + +void get_command(void) +{ + command_info_t *com = xmalloc(sizeof(command_info_t)); + static node_info_msg_t *node_info_ptr; + node_info_t *node_ptr; + int text_height, text_width, text_starty, text_startx, error_code; + WINDOW *command_win; + + text_height = text_win->_maxy; // - text_win->_begy; + text_width = text_win->_maxx; // - text_win->_begx; + text_starty = text_win->_begy; + text_startx = text_win->_begx; + command_win = + newwin(3, text_width - 1, LINES - 4, text_startx + 1); + echo(); + error_code = slurm_load_node((time_t) NULL, &node_info_ptr, 0); + if (error_code) + if (quiet_flag != 1) { + clear_window(text_win); + ycord = text_win->_maxy / 2; + mvwprintw(text_win, ycord, 1, "slurm_load_node"); + return; + } + init_grid(node_info_ptr); + + if (!params.no_header) + print_header_command(); + while (strcmp(com->str, "quit")) { + print_grid(); + box(text_win, 0, 0); + box(grid_win, 0, 0); + wrefresh(text_win); + wrefresh(grid_win); + clear_window(command_win); + box(command_win, 0, 0); + mvwprintw(command_win, 0, 3, + "Input Command: (type quit to change view, exit to exit)"); + wmove(command_win, 1, 1); + wgetstr(command_win, com->str); + + if (!strcmp(com->str, "exit")) { + endwin(); + exit(0); + } else if (!strncmp(com->str, "resume", 6)) { + mvwprintw(text_win, ycord, xcord, "%s", com->str); + } else if (!strncmp(com->str, "drain", 5)) { + mvwprintw(text_win, ycord, xcord, "%s", com->str); + } else if (!strncmp(com->str, "create", 6)) { + mvwprintw(text_win, ycord, xcord, "%s", com->str); + } else if (!strncmp(com->str, "save", 4)) { + mvwprintw(text_win, ycord, xcord, "%s", com->str); + } + ycord++; + //wattron(text_win, COLOR_PAIR(fill_in_value[count].color)); + //print_text_command(&com); + //wattroff(text_win, COLOR_PAIR(fill_in_value[count].color)); + //count++; + + } + //slurm_free_node_info_msg(node_info_ptr); + params.display = 0; + noecho(); + init_grid(node_info_ptr); + clear_window(text_win); + xcord = 1; + ycord = 1; + print_date(); + get_job(); + return; +} + +void print_header_command(void) +{ + mvwprintw(text_win, ycord, xcord, "ID"); + xcord += 5; + mvwprintw(text_win, ycord, xcord, "NODE"); + xcord += 8; + mvwprintw(text_win, ycord, xcord, "STATE"); + xcord += 10; + mvwprintw(text_win, ycord, xcord, "REASON"); + xcord = 1; + ycord++; + +} + +int print_text_command() +{ + /* time_t time; + int printed = 0; + int tempxcord; + int prefixlen; + int i = 0; + int width = 0; + struct passwd *user = NULL; + long days, hours, minutes, seconds; + + mvwprintw(text_win, ycord, xcord, "%c", job_ptr->num_procs); + xcord += 8; + mvwprintw(text_win, ycord, xcord, "%d", job_ptr->job_id); + xcord += 8; + mvwprintw(text_win, ycord, xcord, "%s", job_ptr->partition); + xcord += 12; + user = getpwuid((uid_t) job_ptr->user_id); + mvwprintw(text_win, ycord, xcord, "%s", user->pw_name); + xcord += 10; + mvwprintw(text_win, ycord, xcord, "%s", job_ptr->name); + xcord += 12; + mvwprintw(text_win, ycord, xcord, "%s", + job_state_string(job_ptr->job_state)); + xcord += 10; + time = now - job_ptr->start_time; + + seconds = time % 60; + minutes = (time / 60) % 60; + hours = (time / 3600) % 24; + days = time / 86400; + + if (days) + mvwprintw(text_win, ycord, xcord, + "%ld:%2.2ld:%2.2ld:%2.2ld", days, hours, minutes, + seconds); + else if (hours) + mvwprintw(text_win, ycord, xcord, "%ld:%2.2ld:%2.2ld", + hours, minutes, seconds); + else + mvwprintw(text_win, ycord, xcord, "%ld:%2.2ld", minutes, + seconds); + + xcord += 12; + mvwprintw(text_win, ycord, xcord, "%d", job_ptr->num_nodes); + xcord += 8; + tempxcord = xcord; + width = text_win->_maxx - xcord; + while (job_ptr->nodes[i] != '\0') { + if ((printed = + mvwaddch(text_win, ycord, xcord, + job_ptr->nodes[i])) < 0) + return printed; + xcord++; + width = text_win->_maxx - xcord; + if (job_ptr->nodes[i] == '[') + prefixlen = i + 1; + else if (job_ptr->nodes[i] == ',' && (width - 9) <= 0) { + ycord++; + xcord = tempxcord + prefixlen; + } + i++; + } + + xcord = 1; + ycord++; + return printed; */ +} diff --git a/src/smap/grid_functions.c b/src/smap/grid_functions.c new file mode 100644 index 00000000000..0f2fe534f97 --- /dev/null +++ b/src/smap/grid_functions.c @@ -0,0 +1,169 @@ +/*****************************************************************************\ + * grid_functions.c - Functions related to curses display of smap. + ***************************************************************************** + * Copyright (C) 2002 The Regents of the University of California. + * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). + * Written by Danny Auble <da@llnl.gov> + * + * UCRL-CODE-2002-040. + * + * This file is part of SLURM, a resource management program. + * For details, see <http://www.llnl.gov/linux/slurm/>. + * + * SLURM is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * SLURM is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with SLURM; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +\*****************************************************************************/ + +#include "src/smap/smap.h" + +void clear_window(WINDOW * win) +{ + int x, y; + for (x = 1; x < win->_maxx; x++) + for (y = 1; y < win->_maxy; y++) + mvwaddch(win, y, x, ' '); + return; +} + +/* _init_grid - set values of every grid point */ +void init_grid(node_info_msg_t * node_info_ptr) +{ + node_info_t *node_ptr; + int x, y, z, i = 0; + for (x = 0; x < X; x++) + for (y = 0; y < Y; y++) + for (z = 0; z < Z; z++) { + node_ptr = &node_info_ptr->node_array[i]; + + grid[x][y][z].color = 7; + if (node_ptr->node_state == NODE_STATE_DOWN + || node_ptr->node_state == + NODE_STATE_DRAINED + || node_ptr->node_state == + NODE_STATE_DRAINING) { + grid[x][y][z].color = 0; + grid[x][y][z].letter = '#'; + } else { + grid[x][y][z].color = 7; + grid[x][y][z].letter = '.'; + } + grid[x][y][z].state = node_ptr->node_state; + grid[x][y][z].indecies = i++; + } + y = 65; + z = 0; + for (x = 0; x < num_of_proc; x++) { + y = y % 128; + if (y == 0) + y = 65; + fill_in_value[x].letter = y; + z = z % 7; + if (z == 0) + z = 1; + fill_in_value[x].color = z; + z++; + y++; + } + return; +} + +int set_grid(int start, int end, int count) +{ + int x, y, z; + for (y = Y - 1; y >= 0; y--) + for (z = 0; z < Z; z++) + for (x = 0; x < X; x++) { + if (grid[x][y][z].indecies >= start + && grid[x][y][z].indecies <= end) { + if (grid[x][y][z].state != + NODE_STATE_DOWN + || grid[x][y][z].state != + NODE_STATE_DRAINED + || grid[x][y][z].state != + NODE_STATE_DRAINING) { + grid[x][y][z].letter = + fill_in_value[count]. + letter; + grid[x][y][z].color = + fill_in_value[count]. + color; + } + } + } + + return 1; +} + +int set_grid_bgl(int startx, int starty, int startz, int endx, int endy, + int endz, int count) +{ + int x, y, z; + int i = 0; + assert(endx < X); + assert(startx >= 0); + assert(endy < Y); + assert(starty >= 0); + assert(endz < Z); + assert(startz >= 0); + assert(count < num_of_proc); + assert(count >= 0); + for (x = startx; x <= endx; x++) + for (y = starty; y <= endy; y++) + for (z = startz; z <= endz; z++) { + grid[x][y][z].letter = + fill_in_value[count].letter; + grid[x][y][z].color = + fill_in_value[count].color; + i++; + } + + return i; +} + +/* _print_grid - print values of every grid point */ +void print_grid(void) +{ + int x, y, z, i = 0, offset = Z; + int grid_xcord, grid_ycord = 2; + for (y = Y - 1; y >= 0; y--) { + offset = Z + 1; + for (z = 0; z < Z; z++) { + grid_xcord = offset; + + for (x = 0; x < X; x++) { + if (grid[x][y][z].color) + init_pair(grid[x][y][z].color, + grid[x][y][z].color, + COLOR_BLACK); + else + init_pair(grid[x][y][z].color, + grid[x][y][z].color, 7); + + wattron(grid_win, + COLOR_PAIR(grid[x][y][z].color)); + + mvwprintw(grid_win, grid_ycord, grid_xcord, + "%c", grid[x][y][z].letter); + wattroff(grid_win, + COLOR_PAIR(grid[x][y][z].color)); + grid_xcord++; + i++; + } + grid_ycord++; + offset--; + } + grid_ycord++; + } + return; +} diff --git a/src/smap/job_functions.c b/src/smap/job_functions.c new file mode 100644 index 00000000000..41749712aad --- /dev/null +++ b/src/smap/job_functions.c @@ -0,0 +1,183 @@ +/*****************************************************************************\ + * job_functions.c - Functions related to job display mode of smap. + ***************************************************************************** + * Copyright (C) 2002 The Regents of the University of California. + * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). + * Written by Danny Auble <da@llnl.gov> + * + * UCRL-CODE-2002-040. + * + * This file is part of SLURM, a resource management program. + * For details, see <http://www.llnl.gov/linux/slurm/>. + * + * SLURM is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * SLURM is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with SLURM; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +\*****************************************************************************/ + +#include "src/smap/smap.h" + +void print_header_job(void); +int print_text_job(job_info_t * job_ptr); + +void get_job() +{ + int error_code = -1, i, j, count = 0; + + static job_info_msg_t *job_info_ptr = NULL, *new_job_ptr; + job_info_t job; + + if (job_info_ptr) { + error_code = + slurm_load_jobs(job_info_ptr->last_update, + &new_job_ptr, 0); + if (error_code == SLURM_SUCCESS) + slurm_free_job_info_msg(job_info_ptr); + else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { + error_code = SLURM_SUCCESS; + new_job_ptr = job_info_ptr; + } + } else + error_code = + slurm_load_jobs((time_t) NULL, &new_job_ptr, 0); + + if (error_code) + if (quiet_flag != 1) { + clear_window(text_win); + ycord = text_win->_maxy / 2; + xcord = text_win->_maxx; + mvwprintw(text_win, ycord, 1, "slurm_load_job"); + + return; + } + + if (new_job_ptr->record_count && !params.no_header) + print_header_job(); + for (i = 0; i < new_job_ptr->record_count; i++) { + job = new_job_ptr->job_array[i]; + if (job.node_inx[0] != -1) { + job.num_nodes = 0; + j = 0; + while (job.node_inx[j] >= 0) { + job.num_nodes += + (job.node_inx[j + 1] + 1) - + job.node_inx[j]; + set_grid(job.node_inx[j], + job.node_inx[j + 1], count); + j += 2; + } + job.num_procs = (int) fill_in_value[count].letter; + wattron(text_win, + COLOR_PAIR(fill_in_value[count].color)); + print_text_job(&job); + wattroff(text_win, + COLOR_PAIR(fill_in_value[count].color)); + count++; + } + } + job_info_ptr = new_job_ptr; + return; +} + +void print_header_job(void) +{ + mvwprintw(text_win, ycord, xcord, "ID"); + xcord += 4; + mvwprintw(text_win, ycord, xcord, "JOBID"); + xcord += 7; + mvwprintw(text_win, ycord, xcord, "PARTITION"); + xcord += 11; + mvwprintw(text_win, ycord, xcord, "USER"); + xcord += 8; + mvwprintw(text_win, ycord, xcord, "NAME"); + xcord += 10; + mvwprintw(text_win, ycord, xcord, "ST"); + xcord += 4; + mvwprintw(text_win, ycord, xcord, "TIME"); + xcord += 10; + mvwprintw(text_win, ycord, xcord, "NODES"); + xcord += 7; + mvwprintw(text_win, ycord, xcord, "NODELIST"); + xcord = 1; + ycord++; + +} + +int print_text_job(job_info_t * job_ptr) +{ + time_t time; + int printed = 0; + int tempxcord; + int prefixlen; + int i = 0; + int width = 0; + struct passwd *user = NULL; + long days, hours, minutes, seconds; + + mvwprintw(text_win, ycord, xcord, "%c", job_ptr->num_procs); + xcord += 4; + mvwprintw(text_win, ycord, xcord, "%d", job_ptr->job_id); + xcord += 7; + mvwprintw(text_win, ycord, xcord, "%s", job_ptr->partition); + xcord += 11; + user = getpwuid((uid_t) job_ptr->user_id); + mvwprintw(text_win, ycord, xcord, "%s", user->pw_name); + xcord += 8; + mvwprintw(text_win, ycord, xcord, "%s", job_ptr->name); + xcord += 10; + mvwprintw(text_win, ycord, xcord, "%s", + job_state_string_compact(job_ptr->job_state)); + xcord += 4; + time = now - job_ptr->start_time; + + seconds = time % 60; + minutes = (time / 60) % 60; + hours = (time / 3600) % 24; + days = time / 86400; + + if (days) + mvwprintw(text_win, ycord, xcord, + "%ld:%2.2ld:%2.2ld:%2.2ld", days, hours, minutes, + seconds); + else if (hours) + mvwprintw(text_win, ycord, xcord, "%ld:%2.2ld:%2.2ld", + hours, minutes, seconds); + else + mvwprintw(text_win, ycord, xcord, "%ld:%2.2ld", minutes, + seconds); + + xcord += 10; + mvwprintw(text_win, ycord, xcord, "%d", job_ptr->num_nodes); + xcord += 7; + tempxcord = xcord; + width = text_win->_maxx - xcord; + while (job_ptr->nodes[i] != '\0') { + if ((printed = + mvwaddch(text_win, ycord, xcord, + job_ptr->nodes[i])) < 0) + return printed; + xcord++; + width = text_win->_maxx - xcord; + if (job_ptr->nodes[i] == '[') + prefixlen = i + 1; + else if (job_ptr->nodes[i] == ',' && (width - 9) <= 0) { + ycord++; + xcord = tempxcord + prefixlen; + } + i++; + } + + xcord = 1; + ycord++; + return printed; +} diff --git a/src/smap/opts.c b/src/smap/opts.c index 0cc60cea46e..0d1684e866e 100644 --- a/src/smap/opts.c +++ b/src/smap/opts.c @@ -3,7 +3,7 @@ ***************************************************************************** * Copyright (C) 2002 The Regents of the University of California. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). - * Written by Joey Ekstrom <ekstrom1@llnl.gov>, Moe Jette <jette1@llnl.gov> + * Written by Danny Auble <da@llnl.gov> * UCRL-CODE-2002-040. * * This file is part of SLURM, a resource management program. @@ -59,7 +59,6 @@ static void _usage(void); */ extern void parse_command_line(int argc, char *argv[]) { - char *env_val = NULL; int opt_char; int option_index; int tmp = 0; @@ -67,8 +66,6 @@ extern void parse_command_line(int argc, char *argv[]) {"display", required_argument, 0, 'D'}, {"noheader", no_argument, 0, 'h'}, {"iterate", required_argument, 0, 'i'}, - {"long", no_argument, 0, 'l'}, - {"sort", required_argument, 0, 'S'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"usage", no_argument, 0, OPT_LONG_USAGE}, @@ -76,18 +73,8 @@ extern void parse_command_line(int argc, char *argv[]) {NULL, 0, 0, 0} }; - if (getenv("SMAP_ALL")) - params.all_flag = true; - if ((env_val = getenv("SMAP_FORMAT"))) - params.format = xstrdup(env_val); - if ((env_val = getenv("SMAP_PARTITION"))) - params.partition = xstrdup(env_val); - if ((env_val = getenv("SMAP_SORT"))) - params.sort = xstrdup(env_val); - - while ((opt_char = - getopt_long(argc, argv, "D:hi:lS:V", + getopt_long(argc, argv, "D:hi:V", long_options, &option_index)) != -1) { switch (opt_char) { case (int) '?': @@ -102,6 +89,8 @@ extern void parse_command_line(int argc, char *argv[]) tmp = SLURMPART; else if (!strcmp(optarg, "b")) tmp = BGLPART; + else if (!strcmp(optarg, "c")) + tmp = COMMANDS; params.display = tmp; break; @@ -115,13 +104,6 @@ extern void parse_command_line(int argc, char *argv[]) exit(1); } break; - case (int) 'l': - params.long_output = true; - break; - case (int) 'S': - xfree(params.sort); - params.sort = xstrdup(optarg); - break; case (int) 'V': _print_version(); exit(0); @@ -137,29 +119,6 @@ extern void parse_command_line(int argc, char *argv[]) } } - if (params.display == SLURMPART) { - if (params.long_output) - params.format = - "%9P %.5a %.9l %.8s %.4r %.5h %.10g %.5D %.11T %N"; - else - params.format = "%9P %.5a %.9l %.5D %.6t %N"; - - } else if (params.display == JOBS) { - if (params.long_output) - params.format = - "%.7i %.9P %.8j %.8u %.8T %.10M %.9l %.6D %R"; - else - params.format = - "%.7i %.9P %.8j %.8u %.2t %.10M %.6D %R"; - - } else { - if (params.long_output) - params.format = - "%9P %.5a %.9l %.8s %.4r %.5h %.10g %.5D %.11T %N"; - else - params.format = "%9P %.5a %.9l %.5D %.6t %N"; - - } } @@ -172,19 +131,20 @@ static void _print_version(void) static void _usage(void) { printf("\ -Usage: smap [-adelNRrsv] [-i seconds] [-t states] [-p partition] [-n nodes]\n\ - [-S fields] [-o format] \n"); +Usage: smap [-hV] [-D jsbc] [-i seconds]\n"); } static void _help(void) { printf("\ Usage: smap [OPTIONS]\n\ - -D, --display set which Display mode to use (j=jobs, s=slurm partitions, b=BG/L partitions)\n\ + -D, --display set which Display mode to use\n\ + j=jobs\n\ + s=slurm partitions\n\ + b=BG/L partitions\n\ + c=set configuration\n\ -h, --noheader no headers on output\n\ -i, --iterate=seconds specify an interation period\n\ - -l, --long long output - displays more information\n\ - -S, --sort=fields comma seperated list of fields to sort on\n\ -V, --version output version information and exit\n\ \nHelp options:\n\ --help show this help message\n\ diff --git a/src/smap/partition_functions.c b/src/smap/partition_functions.c new file mode 100644 index 00000000000..d48b133f735 --- /dev/null +++ b/src/smap/partition_functions.c @@ -0,0 +1,211 @@ +/*****************************************************************************\ + * partition_functions.c - Functions related to partition display + * mode of smap. + ***************************************************************************** + * Copyright (C) 2002 The Regents of the University of California. + * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). + * Written by Danny Auble <da@llnl.gov> + * + * UCRL-CODE-2002-040. + * + * This file is part of SLURM, a resource management program. + * For details, see <http://www.llnl.gov/linux/slurm/>. + * + * SLURM is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * SLURM is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with SLURM; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +\*****************************************************************************/ + +#include "src/smap/smap.h" + +void print_header_part(void); +int print_text_part(partition_info_t * part_ptr); + +void get_part(void) +{ + int error_code, i, j, count = 0; + static partition_info_msg_t *part_info_ptr = NULL, *new_part_ptr; + partition_info_t part; + char node_entry[13]; + int start, startx, starty, startz, endx, endy, endz; + if (part_info_ptr) { + error_code = + slurm_load_partitions(part_info_ptr->last_update, + &new_part_ptr, 0); + if (error_code == SLURM_SUCCESS) + slurm_free_partition_info_msg(part_info_ptr); + else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { + error_code = SLURM_SUCCESS; + new_part_ptr = part_info_ptr; + } + } else + error_code = + slurm_load_partitions((time_t) NULL, &new_part_ptr, 0); + if (error_code) { + if (quiet_flag != 1) { + clear_window(text_win); + ycord = text_win->_maxy / 2; + xcord = text_win->_maxx; + mvwprintw(text_win, ycord, 1, + "slurm_load_partitions error"); + + } + return; + } + + if (new_part_ptr->record_count && !params.no_header) + print_header_part(); + for (i = 0; i < new_part_ptr->record_count; i++) { + j = 0; + part = new_part_ptr->partition_array[i]; + + if (params.display == BGLPART) { + memset(node_entry, 0, 13); + memcpy(node_entry, part.nodes, 12); + part.allow_groups = node_entry; + while (part.nodes[j] != '\0') { + if (part.nodes[j] == '[') { + j++; + start = atoi(part.nodes + j); + startx = start / 100; + starty = (start % 100) / 10; + startz = (start % 10); + j += 4; + start = atoi(part.nodes + j); + endx = start / 100; + endy = (start % 100) / 10; + endz = (start % 10); + j += 5; + + part.total_nodes = + set_grid_bgl(startx, starty, + startz, endx, + endy, endz, + count); + part.root_only = + (int) fill_in_value[count]. + letter; + wattron(text_win, + COLOR_PAIR(fill_in_value + [count].color)); + print_text_part(&part); + wattroff(text_win, + COLOR_PAIR(fill_in_value + [count]. + color)); + count++; + memset(node_entry, 0, 13); + memcpy(node_entry, part.nodes + j, + 12); + part.allow_groups = node_entry; + + } + j++; + } + } else { + while (part.node_inx[j] >= 0) { + + set_grid(part.node_inx[j], + part.node_inx[j + 1], count); + j += 2; + + part.root_only = + (int) fill_in_value[count].letter; + wattron(text_win, + COLOR_PAIR(fill_in_value[count]. + color)); + print_text_part(&part); + wattroff(text_win, + COLOR_PAIR(fill_in_value[count]. + color)); + count++; + } + } + } + + part_info_ptr = new_part_ptr; + return; +} + +void print_header_part(void) +{ + mvwprintw(text_win, ycord, xcord, "ID"); + xcord += 4; + mvwprintw(text_win, ycord, xcord, "PARTITION"); + xcord += 10; + mvwprintw(text_win, ycord, xcord, "AVAIL"); + xcord += 7; + mvwprintw(text_win, ycord, xcord, "TIMELIMIT"); + xcord += 11; + mvwprintw(text_win, ycord, xcord, "NODES"); + xcord += 7; + mvwprintw(text_win, ycord, xcord, "NODELIST"); + xcord = 1; + ycord++; +} + +int print_text_part(partition_info_t * part_ptr) +{ + int printed = 0; + int tempxcord; + int prefixlen; + int i = 0; + int width = 0; + char *nodes; + + mvwprintw(text_win, ycord, xcord, "%c", part_ptr->root_only); + xcord += 4; + mvwprintw(text_win, ycord, xcord, "%s", part_ptr->name); + xcord += 10; + if (part_ptr->state_up) + mvwprintw(text_win, ycord, xcord, "UP"); + else + mvwprintw(text_win, ycord, xcord, "DOWN"); + xcord += 7; + if (part_ptr->max_time == INFINITE) + mvwprintw(text_win, ycord, xcord, "UNLIMITED"); + else + mvwprintw(text_win, ycord, xcord, "%u", + part_ptr->max_time); + + xcord += 11; + mvwprintw(text_win, ycord, xcord, "%d", part_ptr->total_nodes); + xcord += 7; + + tempxcord = xcord; + width = text_win->_maxx - xcord; + if (params.display == BGLPART) + nodes = part_ptr->allow_groups; + else + nodes = part_ptr->nodes; + prefixlen = i; + while (nodes[i] != '\0') { + if ((printed = + mvwaddch(text_win, ycord, xcord, nodes[i])) < 0) + return printed; + xcord++; + width = text_win->_maxx - xcord; + if (nodes[i] == '[' && nodes[i - 1] == ',') + prefixlen = i + 1; + else if (nodes[i] == ',' && (width - 9) <= 0) { + ycord++; + xcord = tempxcord + prefixlen; + } + i++; + } + + xcord = 1; + ycord++; + + return printed; +} diff --git a/src/smap/smap.c b/src/smap/smap.c index b0aea9e06b7..106def5d1d3 100644 --- a/src/smap/smap.c +++ b/src/smap/smap.c @@ -1,10 +1,10 @@ /*****************************************************************************\ - * smap.c - -*- linux-c -*- Report overall state the system + * smap.c - Report overall state the system ***************************************************************************** * Copyright (C) 2002 The Regents of the University of California. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). - * Written by Joey Ekstrom <ekstrom1@llnl.gov>, - * Morris Jette <jette1@llnl.gov>, et. al. + * Written by Danny Auble <da@llnl.gov> + * * UCRL-CODE-2002-040. * * This file is part of SLURM, a resource management program. @@ -26,7 +26,6 @@ \*****************************************************************************/ #include "src/common/xstring.h" -#include "src/common/macros.h" #include "src/smap/smap.h" /******************** @@ -36,46 +35,85 @@ struct smap_parameters params; int quiet_flag = 0; int xcord = 1; int ycord = 1; -WINDOW *grid_win; -WINDOW *text_win; -time_t now; -axis grid[X][Y][Z]; -axis fill_in_value[num_of_proc]; +int X = 0; +int Y = 0; +int Z = 0; +int num_of_proc = 0; /************ * Functions * ************/ -static void _init_window(WINDOW * win); -static void _init_grid(void); -static void _print_grid(void); -static void _init_grid(void); -static void _get_job(void); -static void _get_part(void); -static int _print_job(job_info_t * job_ptr); -static int _print_part(partition_info_t * part_ptr); -void print_date(void); -void print_header_part(void); -void print_header_job(void); -int set_grid_bgl(int startx, int starty, int startz, int endx, int endy, - int endz, int count); -int set_grid(int start, int end, int count); +int _get_option(void); int main(int argc, char *argv[]) { log_options_t opts = LOG_OPTS_STDERR_ONLY; - - char ch; - - int height = Y * Z + Y * 2; - int width = X * 2; + node_info_msg_t *node_info_ptr; + node_info_t *node_ptr; + int error_code; + int height = 40; + int width = 100; int startx = 0; int starty = 0; int end = 0; - int i; + int i, j, start, temp; + //char *name; log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_DAEMON, NULL); parse_command_line(argc, argv); + +#ifdef HAVE_BGL + error_code = slurm_load_node((time_t) NULL, &node_info_ptr, 0); + if (error_code) { + slurm_perror("slurm_load_node"); + exit(0); + } else { + for (i = 0; i < node_info_ptr->record_count; i++) { + node_ptr = &node_info_ptr->node_array[i]; + start = atoi(node_ptr->name + 3); + temp = start / 100; + if (X < temp) + X = temp; + temp = (start % 100) / 10; + if (Y < temp) + Y = temp; + temp = start % 10; + if (Z < temp) + Z = temp; + } + X++; + Y++; + Z++; + grid = (axis ***) xmalloc(sizeof(axis **) * X); + for (i = 0; i < X; i++) { + grid[i] = (axis **) xmalloc(sizeof(axis *) * Y); + for (j = 0; j < Y; j++) + grid[i][j] = + (axis *) xmalloc(sizeof(axis) * Z); + } + num_of_proc = node_info_ptr->record_count; + + fill_in_value = + (axis *) xmalloc(sizeof(axis) * num_of_proc); + + height = Y * Z + Y * 2; + width = X * 2; + init_grid(node_info_ptr); + + + } +#else + printf("This will only run on a BGL system right now.\n"); + exit(0); +#endif initscr(); + if (COLS < (75 + width) || LINES < height) { + endwin(); + printf + ("Screen is too small make sure the screen is at least %dx%d\n", + 84 + width, height); + exit(0); + } raw(); keypad(stdscr, TRUE); noecho(); @@ -92,70 +130,41 @@ int main(int argc, char *argv[]) height = LINES; text_win = newwin(height, width, starty, startx); box(text_win, 0, 0); + wrefresh(text_win); + wrefresh(grid_win); while (!end) { - ch = getch(); - switch (ch) { - case 'b': - params.display = BGLPART; - break; - case 's': - params.display = SLURMPART; - break; - case 'j': - params.display = JOBS; - break; - case 'q': - case '\n': - endwin(); - exit(0); - break; - } + _get_option(); redraw: - _init_grid(); - _init_window(text_win); + init_grid(node_info_ptr); + clear_window(text_win); xcord = 1; ycord = 1; - //if (params.iterate && params.long_output) + print_date(); switch (params.display) { case JOBS: - _get_job(); + get_job(); + break; + case COMMANDS: + get_command(); break; default: - _get_part(); + get_part(); break; } - _print_grid(); + print_grid(); box(text_win, 0, 0); box(grid_win, 0, 0); wrefresh(text_win); wrefresh(grid_win); - //sleep(5); + if (params.iterate) { for (i = 0; i < params.iterate; i++) { sleep(1); - ch = getch(); - switch (ch) { - case 'b': - params.display = BGLPART; - goto redraw; - break; - case 's': - params.display = SLURMPART; + if (_get_option()) goto redraw; - break; - case 'j': - params.display = JOBS; - goto redraw; - break; - case 'q': - case '\n': - endwin(); - exit(0); - break; - } } } else break; @@ -164,408 +173,50 @@ int main(int argc, char *argv[]) nodelay(stdscr, FALSE); getch(); endwin(); - - exit(0); -} - -void print_date(void) -{ - now = time(NULL); - mvwprintw(text_win, ycord, xcord, "%s", ctime(&now)); - ycord++; -} - -void print_header_part(void) -{ - mvwprintw(text_win, ycord, xcord, "IDENT"); - xcord += 8; - mvwprintw(text_win, ycord, xcord, "PARTITION"); - xcord += 12; - mvwprintw(text_win, ycord, xcord, "AVAIL"); - xcord += 10; - mvwprintw(text_win, ycord, xcord, "TIMELIMIT"); - xcord += 12; - mvwprintw(text_win, ycord, xcord, "NODES"); - xcord += 8; - mvwprintw(text_win, ycord, xcord, "NODELIST"); - xcord = 1; - ycord++; -} -void print_header_job(void) -{ - mvwprintw(text_win, ycord, xcord, "IDENT"); - xcord += 8; - mvwprintw(text_win, ycord, xcord, "JOBID"); - xcord += 8; - mvwprintw(text_win, ycord, xcord, "PARTITION"); - xcord += 12; - mvwprintw(text_win, ycord, xcord, "USER"); - xcord += 10; - mvwprintw(text_win, ycord, xcord, "NAME"); - xcord += 12; - mvwprintw(text_win, ycord, xcord, "STATE"); - xcord += 10; - mvwprintw(text_win, ycord, xcord, "TIME"); - xcord += 12; - mvwprintw(text_win, ycord, xcord, "NODES"); - xcord += 8; - mvwprintw(text_win, ycord, xcord, "NODELIST"); - xcord = 1; - ycord++; - -} - -static void _get_job() -{ - int error_code = -1, i, j, count = 0; - - job_info_msg_t *job_info_ptr = NULL; - job_info_t job; - - error_code = slurm_load_jobs((time_t) NULL, &job_info_ptr, 0); - if (error_code) { - if (quiet_flag != 1) - slurm_perror("slurm_load_jobs error"); - return; - } - if (job_info_ptr->record_count && !params.no_header) - print_header_job(); - for (i = 0; i < job_info_ptr->record_count; i++) { - job = job_info_ptr->job_array[i]; - if (job.node_inx[0] != -1) { - job.num_nodes = 0; - j = 0; - while (job.node_inx[j] >= 0) { - job.num_nodes += - (job.node_inx[j + 1] + 1) - - job.node_inx[j]; - set_grid(job.node_inx[j], - job.node_inx[j + 1], count); - j += 2; - } - job.num_procs = (int) fill_in_value[count].letter; - wattron(text_win, - COLOR_PAIR(fill_in_value[count].color)); - _print_job(&job); - wattroff(text_win, - COLOR_PAIR(fill_in_value[count].color)); - count++; - } - } - return; -} - -static void _get_part(void) -{ - int error_code, i, j, count = 0; - partition_info_msg_t *part_info_ptr; - partition_info_t part; - char node_entry[13]; - int start, startx, starty, startz, endx, endy, endz; - error_code = - slurm_load_partitions((time_t) NULL, &part_info_ptr, 0); - if (error_code) { - if (quiet_flag != 1) - slurm_perror("slurm_load_partitions error"); - return; + for (i = 0; i < X; i++) { + for (j = 0; j < Y; j++) + xfree(grid[i][j]); + xfree(grid[i]); } + xfree(grid); + xfree(fill_in_value); - if (part_info_ptr->record_count && !params.no_header) - print_header_part(); - for (i = 0; i < part_info_ptr->record_count; i++) { - j = 0; - part = part_info_ptr->partition_array[i]; - - if (params.display == BGLPART) { - memset(node_entry, 0, 13); - memcpy(node_entry, part.nodes, 12); - part.allow_groups = node_entry; - while (part.nodes[j] != '\0') { - if (part.nodes[j] == '[') { - j++; - start = atoi(part.nodes + j); - startx = start / 100; - starty = (start % 100) / 10; - startz = (start % 10); - j += 4; - start = atoi(part.nodes + j); - endx = start / 100; - endy = (start % 100) / 10; - endz = (start % 10); - j += 5; - - part.total_nodes = - set_grid_bgl(startx, starty, - startz, endx, - endy, endz, - count); - part.root_only = - (int) fill_in_value[count]. - letter; - wattron(text_win, - COLOR_PAIR(fill_in_value - [count].color)); - _print_part(&part); - wattroff(text_win, - COLOR_PAIR(fill_in_value - [count]. - color)); - count++; - memset(node_entry, 0, 13); - memcpy(node_entry, part.nodes + j, - 12); - part.allow_groups = node_entry; - - } - j++; - } - } else { - while (part.node_inx[j] >= 0) { - - set_grid(part.node_inx[j], - part.node_inx[j + 1], count); - j += 2; - - part.root_only = - (int) fill_in_value[count].letter; - wattron(text_win, - COLOR_PAIR(fill_in_value[count]. - color)); - _print_part(&part); - wattroff(text_win, - COLOR_PAIR(fill_in_value[count]. - color)); - count++; - } - } - } - - return; + exit(0); } -static int _print_job(job_info_t * job_ptr) +int _get_option(void) { - time_t time; - int printed = 0; - int tempxcord; - int prefixlen; - int i = 0; - int width = 0; - struct passwd *user = NULL; - long days, hours, minutes, seconds; - - mvwprintw(text_win, ycord, xcord, "%c", job_ptr->num_procs); - xcord += 8; - mvwprintw(text_win, ycord, xcord, "%d", job_ptr->job_id); - xcord += 8; - mvwprintw(text_win, ycord, xcord, "%s", job_ptr->partition); - xcord += 12; - user = getpwuid((uid_t) job_ptr->user_id); - mvwprintw(text_win, ycord, xcord, "%s", user->pw_name); - xcord += 10; - mvwprintw(text_win, ycord, xcord, "%s", job_ptr->name); - xcord += 12; - mvwprintw(text_win, ycord, xcord, "%s", - job_state_string(job_ptr->job_state)); - xcord += 10; - time = now - job_ptr->start_time; - - seconds = time % 60; - minutes = (time / 60) % 60; - hours = (time / 3600) % 24; - days = time / 86400; - - if (days) - mvwprintw(text_win, ycord, xcord, - "%ld:%2.2ld:%2.2ld:%2.2ld", days, hours, minutes, - seconds); - else if (hours) - mvwprintw(text_win, ycord, xcord, "%ld:%2.2ld:%2.2ld", - hours, minutes, seconds); - else - mvwprintw(text_win, ycord, xcord, "%ld:%2.2ld", minutes, - seconds); - - xcord += 12; - mvwprintw(text_win, ycord, xcord, "%d", job_ptr->num_nodes); - xcord += 8; - tempxcord = xcord; - width = text_win->_maxx - xcord; - while (job_ptr->nodes[i] != '\0') { - if ((printed = - mvwaddch(text_win, ycord, xcord, - job_ptr->nodes[i])) < 0) - return printed; - xcord++; - width = text_win->_maxx - xcord; - if (job_ptr->nodes[i] == '[') - prefixlen = i + 1; - else if (job_ptr->nodes[i] == ',' && (width - 9) <= 0) { - ycord++; - xcord = tempxcord + prefixlen; - } - i++; + char ch; + ch = getch(); + switch (ch) { + case 'b': + params.display = BGLPART; + return 1; + break; + case 's': + params.display = SLURMPART; + return 1; + break; + case 'j': + params.display = JOBS; + return 1; + break; + case 'c': + params.display = COMMANDS; + return 1; + break; + case 'q': + case '\n': + endwin(); + exit(0); + break; } - - xcord = 1; - ycord++; - return printed; + return 0; } -static int _print_part(partition_info_t * part_ptr) +void print_date(void) { - int printed = 0; - int tempxcord; - int prefixlen; - int i = 0; - int width = 0; - char *nodes; - - mvwprintw(text_win, ycord, xcord, "%c", part_ptr->root_only); - xcord += 8; - mvwprintw(text_win, ycord, xcord, "%s", part_ptr->name); - xcord += 12; - if (part_ptr->state_up) - mvwprintw(text_win, ycord, xcord, "UP"); - else - mvwprintw(text_win, ycord, xcord, "DOWN"); - xcord += 10; - if (part_ptr->max_time == INFINITE) - mvwprintw(text_win, ycord, xcord, "UNLIMITED"); - else - mvwprintw(text_win, ycord, xcord, "%u", - part_ptr->max_time); - - xcord += 12; - mvwprintw(text_win, ycord, xcord, "%d", part_ptr->total_nodes); - xcord += 8; - - tempxcord = xcord; - width = text_win->_maxx - xcord; - if (params.display == BGLPART) - nodes = part_ptr->allow_groups; - else - nodes = part_ptr->nodes; - while (nodes[i] != '\0') { - if ((printed = - mvwaddch(text_win, ycord, xcord, nodes[i])) < 0) - return printed; - xcord++; - width = text_win->_maxx - xcord; - if (nodes[i] == '[') - prefixlen = i + 1; - else if (nodes[i] == ',' && (width - 9) <= 0) { - ycord++; - xcord = tempxcord + prefixlen; - } - i++; - } - - xcord = 1; + now = time(NULL); + mvwprintw(text_win, ycord, xcord, "%s", ctime(&now)); ycord++; - - return printed; -} - -int set_grid_bgl(int startx, int starty, int startz, int endx, int endy, - int endz, int count) -{ - int x, y, z; - int i = 0; - for (x = startx; x <= endx; x++) - for (y = starty; y <= endy; y++) - for (z = startz; z <= endz; z++) { - grid[x][y][z].letter = - fill_in_value[count].letter; - grid[x][y][z].color = - fill_in_value[count].color; - i++; - } - - return i; -} - -int set_grid(int start, int end, int count) -{ - int x, y, z; - for (y = Y - 1; y >= 0; y--) - for (z = 0; z < Z; z++) - for (x = 0; x < X; x++) { - if (grid[x][y][z].indecies >= start - && grid[x][y][z].indecies <= end) { - grid[x][y][z].letter = - fill_in_value[count].letter; - grid[x][y][z].color = - fill_in_value[count].color; - } - } - - return 1; -} - -/* _init_window - clear window */ -static void _init_window(WINDOW * win) -{ - int x, y; - for (x = 1; x < win->_maxx; x++) - for (y = 1; y < ycord; y++) - mvwaddch(win, y, x, ' '); - return; -} - -/* _init_grid - set values of every grid point */ -static void _init_grid(void) -{ - int x, y, z, i = 0; - for (x = 0; x < X; x++) - for (y = 0; y < Y; y++) - for (z = 0; z < Z; z++) { - grid[x][y][z].color = 7; - grid[x][y][z].letter = '.'; - grid[x][y][z].indecies = i++; - } - y = 65; - z = 0; - for (x = 0; x < num_of_proc; x++) { - fill_in_value[x].letter = y; - z = z % 7; - if (z == 0) - z = 1; - fill_in_value[x].color = z; - z++; - y++; - } - return; -} - -/* _print_grid - print values of every grid point */ -static void _print_grid(void) -{ - int x, y, z, i = 0, offset = Z; - int grid_xcord, grid_ycord = 2; - for (y = Y - 1; y >= 0; y--) { - offset = Z + 1; - for (z = 0; z < Z; z++) { - grid_xcord = offset; - - for (x = 0; x < X; x++) { - init_pair(grid[x][y][z].color, - grid[x][y][z].color, - COLOR_BLACK); - wattron(grid_win, - COLOR_PAIR(grid[x][y][z].color)); - //printf("%d%d%d %c",x,y,z,grid[x][y][z].letter); - mvwprintw(grid_win, grid_ycord, grid_xcord, - "%c", grid[x][y][z].letter); - wattroff(grid_win, - COLOR_PAIR(grid[x][y][z].color)); - grid_xcord++; - i++; - } - grid_ycord++; - offset--; - } - grid_ycord++; - } - return; } diff --git a/src/smap/smap.h b/src/smap/smap.h index 0386617959e..9cd63f1c7f7 100644 --- a/src/smap/smap.h +++ b/src/smap/smap.h @@ -3,7 +3,7 @@ ***************************************************************************** * Copyright (C) 2002 The Regents of the University of California. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). - * Written by Joey Ekstrom <ekstrom1@llnl.gov>, Moe Jette <jette1@llnl.gov> + * Written by Danny Auble <da@llnl.gov> * UCRL-CODE-2002-040. * * This file is part of SLURM, a resource management program. @@ -38,7 +38,7 @@ #include <string.h> #include <time.h> #include <unistd.h> -#include <ncurses.h> +#include <curses.h> #if HAVE_INTTYPES_H # include <inttypes.h> @@ -53,7 +53,7 @@ #include "src/common/slurm_protocol_api.h" #include "src/common/xmalloc.h" -enum { JOBS, SLURMPART, BGLPART }; +enum { JOBS, SLURMPART, BGLPART, COMMANDS }; /* Input parameters */ struct smap_parameters { @@ -82,14 +82,42 @@ extern struct smap_parameters params; extern void parse_command_line(int argc, char *argv[]); -#define X 8 -#define Y 4 -#define Z 4 -#define num_of_proc 128 typedef struct { char letter; int color; int indecies; + int state; } axis; +extern int quiet_flag; +extern int xcord; +extern int ycord; +extern int X; +extern int Y; +extern int Z; +extern int num_of_proc; + +WINDOW *grid_win; +WINDOW *text_win; + +time_t now; + + +axis ***grid; +axis *fill_in_value; + +void clear_window(WINDOW * win); + +void init_grid(node_info_msg_t * node_info_ptr); +int set_grid(int start, int end, int count); +int set_grid_bgl(int startx, int starty, int startz, int endx, int endy, + int endz, int count); +void print_grid(void); + +void print_date(void); + +void get_part(void); +void get_job(void); +void get_command(void); + #endif -- GitLab