1
1
openmpi/opal/mca/pstat/test/pstat_test.c
Charles Shereda cbc6feaab2 Created opal_gethostname() as safer gethostname substitute.
The opal_gethostname() function provides a more robust mechanism
to retrieve the hostname than gethostname(), which can return
results that are not null-terminated, and which can vary in its
behavior from system to system.

opal_gethostname() just returns the value in opal_process_info.nodename;
this is populated in opal_init_gethostname() inside opal_init.c.

-Changed all gethostname calls in opal subtree to opal_gethostname
-Changed all gethostname calls in orte subtree to opal_gethostname
-Changed all gethostname calls in ompi subdir to opal_gethostname
-Changed all gethostname calls in oshmem subdir to opal_gethostname
-Changed opal_if.c in test subdir to use opal_gethostname
-Changed opal_init.c to include opal_init_gethostname. This function
 returns an int and directly sets opal_process_info.nodename per
 jsquyres' modifications.

Relates to open-mpi#6801

Signed-off-by: Charles Shereda <cpshereda@lanl.gov>
2020-01-13 08:52:17 -08:00

129 строки
3.5 KiB
C

/*
* Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2011 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include "opal/runtime/opal.h"
#include "opal/mca/pstat/pstat.h"
#include "opal/mca/pstat/base/base.h"
#include "opal/util/string_copy.h"
#include "pstat_test.h"
static int init(void);
static int query(pid_t pid,
opal_pstats_t *stats,
opal_node_stats_t *nstats);
static int fini(void);
/*
* Test pstat module
*/
const opal_pstat_base_module_t opal_pstat_test_module = {
init,
query,
fini
};
static int init(void)
{
return OPAL_SUCCESS;
}
static int fini(void)
{
return OPAL_SUCCESS;
}
static int query(pid_t pid,
opal_pstats_t *stats,
opal_node_stats_t *nstats)
{
double dtime;
const char *hostname;
if (NULL != stats) {
/* record the time of this sample */
gettimeofday(&stats->sample_time, NULL);
/* check the nstats - don't do gettimeofday twice
* as it is expensive
*/
if (NULL != nstats) {
nstats->sample_time.tv_sec = stats->sample_time.tv_sec;
nstats->sample_time.tv_usec = stats->sample_time.tv_usec;
}
} else if (NULL != nstats) {
/* record the time of this sample */
gettimeofday(&nstats->sample_time, NULL);
}
if (NULL != stats) {
hostname = opal_gethostname();
opal_string_copy(stats->node, hostname, OPAL_PSTAT_MAX_STRING_LEN);
stats->pid = pid;
opal_string_copy(stats->cmd, "UNKNOWN", OPAL_PSTAT_MAX_STRING_LEN);
stats->state[0] = 'R';
stats->priority = 2;
stats->num_threads = 1;
/* set the values to something identifiable for testing */
stats->vsize = 1.75;
stats->rss = 1.23;
stats->peak_vsize = 7.89;
/* convert to time in seconds */
dtime = 12345.678;
stats->time.tv_sec = (long)dtime;
stats->time.tv_usec = (long)(1000000.0 * (dtime - stats->time.tv_sec));
stats->priority = 2;
}
if (NULL != nstats) {
/* set the memory values to something identifiable for testing */
nstats->total_mem = 123.45;
nstats->free_mem = 0.45;
nstats->buffers = 1.33;
nstats->cached = 0.56;
nstats->swap_cached = 0.95;
nstats->swap_total = 11.45;
nstats->swap_free = 1.26;
nstats->mapped = 12.98;
/* set the load averages */
nstats->la = 0.52;
nstats->la5 = 1.03;
nstats->la15 = 0.12;
}
return OPAL_SUCCESS;
}