File: pstat_test.c

package info (click to toggle)
openmpi 3.1.3-11
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 118,572 kB
  • sloc: ansic: 628,972; f90: 17,993; makefile: 13,761; sh: 7,051; java: 6,360; perl: 3,215; cpp: 2,225; python: 1,350; lex: 988; fortran: 52; tcl: 12
file content (124 lines) | stat: -rw-r--r-- 3,465 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * 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$
 *
 * 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/mca/pstat/pstat.h"
#include "opal/mca/pstat/base/base.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;
    char hostname[OPAL_MAXHOSTNAMELEN];

    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) {
        gethostname(hostname, sizeof(hostname));
        strncpy(stats->node, hostname, OPAL_PSTAT_MAX_STRING_LEN);

        stats->pid = pid;
        strncpy(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;
}