Skip to content

Commit

Permalink
cmd/flux-debug: add debug command
Browse files Browse the repository at this point in the history
  • Loading branch information
garlick committed Feb 28, 2017
1 parent 20e91a4 commit 25e7ff1
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cmd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ flux_SOURCES = \
builtin/hwloc.c \
builtin/nodeset.c \
builtin/heaptrace.c \
builtin/proxy.c
builtin/proxy.c \
builtin/debug.c
nodist_flux_SOURCES = \
builtin-cmds.c

Expand Down
96 changes: 96 additions & 0 deletions src/cmd/builtin/debug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*****************************************************************************\
* Copyright (c) 2017 Lawrence Livermore National Security, LLC. Produced at
* the Lawrence Livermore National Laboratory (cf, AUTHORS, DISCLAIMER.LLNS).
* LLNL-CODE-658032 All rights reserved.
*
* This file is part of the Flux resource manager framework.
* For details, see https://github.com/flux-framework.
*
* This program 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.
*
* Flux 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 terms and conditions of the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* See also: http://www.gnu.org/licenses/
\*****************************************************************************/
#include "builtin.h"

static struct optparse_option debug_opts[] = {
{ .name = "clear", .key = 'C', .has_arg = 0,
.usage = "Set debug flags to 0", },
{ .name = "set", .key = 'S', .has_arg = 1,
.usage = "Set debug flags to MASK", },
{ .name = "setbit", .key = 's', .has_arg = 1,
.usage = "Set one debug flag to 1", },
{ .name = "clearbit", .key = 'c', .has_arg = 1,
.usage = "Set one debug flag to 0", },
OPTPARSE_TABLE_END,
};


static int cmd_debug (optparse_t *p, int ac, char *av[])
{
int n;
flux_t *h;
char *topic = NULL;
const char *op = "setbit";
int flags = 0;
flux_rpc_t *rpc = NULL;

if ((n = optparse_option_index (p)) != ac - 1)
log_msg_exit ("flux-debug requires service argument");
topic = xasprintf ("%s.debug", av[n]);

if (!(h = builtin_get_flux_handle (p)))
log_err_exit ("flux_open");
if (optparse_hasopt (p, "clear")) {
op = "clr";
flags = strtoul (optparse_get_str (p, "clear", NULL), NULL, 0);
}
else if (optparse_hasopt (p, "set")) {
op = "set";
flags = strtoul (optparse_get_str (p, "set", NULL), NULL, 0);
}
else if (optparse_hasopt (p, "clearbit")) {
op = "clrbit";
flags = strtoul (optparse_get_str (p, "clearbit", NULL), NULL, 0);
}
else if (optparse_hasopt (p, "setbit")) {
op = "setbit";
flags = strtoul (optparse_get_str (p, "setbit", NULL), NULL, 0);
}
if (!(rpc = flux_rpcf (h, topic, FLUX_NODEID_ANY, 0, "{s:s s:i}",
"op", op, "flags", flags)))
log_err_exit ("%s", topic);
if (flux_rpc_getf (rpc, "{s:i}", "flags", &flags) < 0)
log_err_exit ("%s", topic);
printf ("0x%x\n", flags);
flux_close (h);
free (topic);
return (0);
}

int subcommand_debug_register (optparse_t *p)
{
optparse_err_t e;
e = optparse_reg_subcommand (p,
"debug",
cmd_debug,
"service [OPTIONS...]",
"Get/set service debug flags",
0,
debug_opts);
return (e == OPTPARSE_SUCCESS ? 0 : -1);
}

/*
* vi: ts=4 sw=4 expandtab
*/

0 comments on commit 25e7ff1

Please sign in to comment.