IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42900


Ignore:
Timestamp:
Jun 18, 2025, 9:16:15 AM (13 months ago)
Author:
eugene
Message:

add output option to hoststats

Location:
tags/ipp-unions-20250528/Ohana/src/opihi
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-unions-20250528/Ohana/src/opihi/pantasks/controller_hoststats.c

    r42899 r42900  
    44
    55  int N, status;
    6   char command[1024];
    76  IOBuffer buffer;
    87
     
    1312  }
    1413
     14  char *filename = NULL;
     15  if ((N = get_argument (argc, argv, "-file"))) {
     16    remove_argument (N, &argc, argv);
     17    filename = strcreate (argv[N]);
     18    remove_argument (N, &argc, argv);
     19  }
    1520  if (argc != 2) {
    16     gprint (GP_ERR, "USAGE: controller hoststats (stack)\n");
     21    gprint (GP_ERR, "USAGE: controller hoststats (stack) [-reset] [-file output]\n");
    1722    gprint (GP_ERR, "       (stack) : all, idle, busy, done, down, off, resp\n");
     23    FREE (filename);
    1824    return (FALSE);
    1925  }
     
    2329  if (!status) {
    2430    gprint (GP_LOG, "controller is not active\n");
     31    FREE (filename);
    2532    return (TRUE);
    2633  }
    2734
    2835  // XXX this has an error?  test this out...
    29   if (Reset) {
    30     sprintf (command, "hoststats %s -reset", argv[1]);
    31   } else {
    32     sprintf (command, "hoststats %s", argv[1]);
    33   }
     36  char *command = NULL;
     37  strextend (&command, "hoststats %s", argv[1]);
     38  if (Reset) { strextend (&command, " -reset"); }
     39  if (filename) { strextend (&command, " -file %s", filename); }
     40
    3441  InitIOBuffer (&buffer, 0x100);
    3542
    3643  status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
     44  free (command);
    3745
    3846  if (status) {
  • tags/ipp-unions-20250528/Ohana/src/opihi/pcontrol/hoststats.c

    r42899 r42900  
    1313  }
    1414
     15  char *filename = NULL;
     16  if ((N = get_argument (argc, argv, "-file"))) {
     17    remove_argument (N, &argc, argv);
     18    filename = strcreate (argv[N]);
     19    remove_argument (N, &argc, argv);
     20  }
     21
    1522  if (argc != 2) {
    16     gprint (GP_ERR, "USAGE: hoststats (stack) [-reset]\n");
     23    gprint (GP_ERR, "USAGE: hoststats (stack) [-reset] [-file output]\n");
    1724    gprint (GP_ERR, "       (stack) : all, idle, busy, done, down, off, resp\n");
     25    FREE (filename);
    1826    return (FALSE);
    1927  }
     
    2230  stack = GetHostStackByName (argv[1]);
    2331  if (stack == NULL) {
    24     gprint (GP_ERR, "hoststack not found\n");
     32    gprint (GP_LOG, "hoststack not found\n");
     33    FREE (filename);
    2534    return (FALSE);
     35  }
     36
     37  FILE *fout = NULL;
     38  if (filename) {
     39    fout = fopen (filename, "a");
     40    if (!fout) {
     41      gprint (GP_LOG, "error opening %s for output\n", filename);
     42      FREE (filename);
     43      return (FALSE);
     44    }
    2645  }
    2746
    2847  /* print list */
    2948  LockStack (stack);
    30   gprint (GP_LOG, "Nhosts: %d\n", stack[0].Nobject);
     49  if (filename) {
     50    fprintf (fout, "Nhosts: %d\n", stack[0].Nobject);
     51  } else {
     52    gprint (GP_LOG, "Nhosts: %d\n", stack[0].Nobject);
     53  }
    3154  for (i = 0; i < stack[0].Nobject; i++) {
    3255    host = stack[0].object[i];
    33     gprint (GP_LOG, "%lld %s %d : %f %d %d %d\n", host[0].HostID, host[0].hostname, host[0].pid, host[0].read_time, host[0].read_N_Pclient, host[0].read_N_GetJobOutput, host[0].N_jobs_total);
     56    if (filename) {
     57      fprintf (fout, "%lld %s %d : %f %d %d %d\n", host[0].HostID, host[0].hostname, host[0].pid, host[0].read_time, host[0].read_N_Pclient, host[0].read_N_GetJobOutput, host[0].N_jobs_total);
     58    } else {
     59      gprint (GP_LOG, "%lld %s %d : %f %d %d %d\n", host[0].HostID, host[0].hostname, host[0].pid, host[0].read_time, host[0].read_N_Pclient, host[0].read_N_GetJobOutput, host[0].N_jobs_total);
     60    }
    3461    if (Reset) {
    3562      host[0].read_time = 0.0;
     
    4168  UnlockStack (stack);
    4269
     70  if (filename) {
     71    free (filename);
     72    fclose (fout);
     73  }
    4374  return (TRUE);
    4475}
Note: See TracChangeset for help on using the changeset viewer.