root/opal/mca/pstat/test/pstat_test.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. init
  2. fini
  3. query

   1 /*
   2  * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2007-2011 Cisco Systems, Inc.  All rights reserved.
  13  * Copyright (c) 2008      Sun Microsystems, Inc.  All rights reserved.
  14  *
  15  * $COPYRIGHT$
  16  *
  17  * Additional copyrights may follow
  18  *
  19  * $HEADER$
  20  */
  21 
  22 #include "opal_config.h"
  23 #include "opal/constants.h"
  24 
  25 #ifdef HAVE_UNISTD_H
  26 #include <unistd.h>
  27 #endif
  28 #include <string.h>
  29 #ifdef HAVE_SYS_TIME_H
  30 #include <sys/time.h>
  31 #endif
  32 
  33 #include "opal/mca/pstat/pstat.h"
  34 #include "opal/mca/pstat/base/base.h"
  35 #include "opal/util/string_copy.h"
  36 
  37 #include "pstat_test.h"
  38 
  39 static int init(void);
  40 static int query(pid_t pid,
  41                  opal_pstats_t *stats,
  42                  opal_node_stats_t *nstats);
  43 static int fini(void);
  44 
  45 /*
  46  * Test pstat module
  47  */
  48 const opal_pstat_base_module_t opal_pstat_test_module = {
  49     init,
  50     query,
  51     fini
  52 };
  53 
  54 static int init(void)
  55 {
  56     return OPAL_SUCCESS;
  57 }
  58 
  59 static int fini(void)
  60 {
  61     return OPAL_SUCCESS;
  62 }
  63 
  64 static int query(pid_t pid,
  65                  opal_pstats_t *stats,
  66                  opal_node_stats_t *nstats)
  67 {
  68     double dtime;
  69     char hostname[OPAL_MAXHOSTNAMELEN];
  70 
  71     if (NULL != stats) {
  72         /* record the time of this sample */
  73         gettimeofday(&stats->sample_time, NULL);
  74         /* check the nstats - don't do gettimeofday twice
  75          * as it is expensive
  76          */
  77         if (NULL != nstats) {
  78             nstats->sample_time.tv_sec = stats->sample_time.tv_sec;
  79             nstats->sample_time.tv_usec = stats->sample_time.tv_usec;
  80         }
  81     } else if (NULL != nstats) {
  82         /* record the time of this sample */
  83         gettimeofday(&nstats->sample_time, NULL);
  84     }
  85 
  86     if (NULL != stats) {
  87         gethostname(hostname, sizeof(hostname));
  88         opal_string_copy(stats->node, hostname, OPAL_PSTAT_MAX_STRING_LEN);
  89 
  90         stats->pid = pid;
  91         opal_string_copy(stats->cmd, "UNKNOWN", OPAL_PSTAT_MAX_STRING_LEN);
  92         stats->state[0] = 'R';
  93         stats->priority = 2;
  94         stats->num_threads = 1;
  95 
  96         /* set the values to something identifiable for testing */
  97         stats->vsize = 1.75;
  98         stats->rss = 1.23;
  99         stats->peak_vsize = 7.89;
 100 
 101         /* convert to time in seconds */
 102         dtime = 12345.678;
 103         stats->time.tv_sec = (long)dtime;
 104         stats->time.tv_usec = (long)(1000000.0 * (dtime - stats->time.tv_sec));
 105         stats->priority = 2;
 106     }
 107 
 108     if (NULL != nstats) {
 109         /* set the memory values to something identifiable for testing */
 110         nstats->total_mem = 123.45;
 111         nstats->free_mem = 0.45;
 112         nstats->buffers = 1.33;
 113         nstats->cached = 0.56;
 114         nstats->swap_cached = 0.95;
 115         nstats->swap_total = 11.45;
 116         nstats->swap_free = 1.26;
 117         nstats->mapped = 12.98;
 118         /* set the load averages */
 119         nstats->la = 0.52;
 120         nstats->la5 = 1.03;
 121         nstats->la15 = 0.12;
 122     }
 123 
 124     return OPAL_SUCCESS;
 125 }

/* [<][>][^][v][top][bottom][index][help] */