1
1

Add new database component for printing "add_log" info

This commit was SVN r27989.
Этот коммит содержится в:
Ralph Castain 2013-01-31 15:19:39 +00:00
родитель 8d80af6c10
Коммит 9625757a71
4 изменённых файлов: 338 добавлений и 0 удалений

38
orte/mca/db/print/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,38 @@
#
# Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
sources = \
db_print.h \
db_print_component.c \
db_print.c
# Make the output library in this directory, and name it either
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
# (for static builds).
if MCA_BUILD_orte_db_print_DSO
component_noinst =
component_install = mca_db_print.la
else
component_noinst = libmca_db_print.la
component_install =
endif
mcacomponentdir = $(pkglibdir)
mcacomponent_LTLIBRARIES = $(component_install)
mca_db_print_la_CPPFLAGS = $(db_print_CPPFLAGS)
mca_db_print_la_SOURCES = $(sources)
mca_db_print_la_LDFLAGS = -module -avoid-version $(db_print_LDFLAGS)
mca_db_print_la_LIBADD = $(db_print_LIBS)
noinst_LTLIBRARIES = $(component_noinst)
libmca_db_print_la_CPPFLAGS = $(db_print_CPPFLAGS)
libmca_db_print_la_SOURCES =$(sources)
libmca_db_print_la_LDFLAGS = -module -avoid-version $(db_print_LDFLAGS)
libmca_db_print_la_LIBADD = $(db_print_LIBS)

179
orte/mca/db/print/db_print.c Обычный файл
Просмотреть файл

@ -0,0 +1,179 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#include "orte_config.h"
#include "orte/constants.h"
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#include <stdio.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "opal/class/opal_pointer_array.h"
#include "opal/util/argv.h"
#include "orte/util/name_fns.h"
#include "orte/util/proc_info.h"
#include "orte/runtime/orte_globals.h"
#include "orte/mca/db/base/base.h"
#include "db_print.h"
static int init(void);
static void finalize(void);
static int add_log(const char *table,
const opal_value_t *kvs, int nkvs);
orte_db_base_module_t orte_db_print_module = {
init,
finalize,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
add_log
};
static opal_pointer_array_t tables;
static FILE *fpout=NULL;
static int init(void)
{
OBJ_CONSTRUCT(&tables, opal_pointer_array_t);
opal_pointer_array_init(&tables, 1, INT_MAX, 1);
if (0 == strcmp(mca_db_print_component.filename, "-")) {
fpout = stdout;
} else if (0 == strcmp(mca_db_print_component.filename, "+")) {
fpout = stderr;
} else if (NULL == (fpout = fopen(mca_db_print_component.filename, "w"))) {
opal_output(0, "ERROR: cannot open log file %s", mca_db_print_component.filename);
return ORTE_ERROR;
}
return ORTE_SUCCESS;
}
static void finalize(void)
{
int i;
char *ptr;
for (i=0; i < tables.size; i++) {
if (NULL != (ptr = (char*)opal_pointer_array_get_item(&tables, i))) {
free(ptr);
}
}
OBJ_DESTRUCT(&tables);
if (NULL != fpout &&
stdout != fpout &&
stderr != fpout) {
fclose(fpout);
fpout = NULL;
}
}
static int add_log(const char *table,
const opal_value_t *kvs, int nkvs)
{
char **cmdargs=NULL, *vstr;
time_t nowtime;
struct tm *nowtm;
char tbuf[1024];
int i;
bool found;
opal_output_verbose(2, orte_db_base.output,
"%s Logging data for table %s",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), table);
found = false;
for (i=0; i < tables.size; i++) {
if (NULL == (vstr = (char*)opal_pointer_array_get_item(&tables, i))) {
continue;
}
if (0 == strcmp(vstr, table)) {
/* already handled this one */
found = true;
break;
}
}
if (!found) {
/* record that we have it */
vstr = strdup(table);
opal_pointer_array_add(&tables, vstr);
/* create and print the column headers */
for (i=0; i < nkvs; i++) {
opal_argv_append_nosize(&cmdargs, kvs[i].key);
}
vstr = opal_argv_join(cmdargs, '|');
fprintf(fpout, "%s\n", vstr);
free(vstr);
opal_argv_free(cmdargs);
cmdargs = NULL;
}
/* cycle through the provided values and print them */
for (i=0; i < nkvs; i++) {
switch (kvs[i].type) {
case OPAL_STRING:
snprintf(tbuf, sizeof(tbuf), "%s", kvs[i].data.string);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT32:
snprintf(tbuf, sizeof(tbuf), "%d", kvs[i].data.int32);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT16:
snprintf(tbuf, sizeof(tbuf), "%d", (int)kvs[i].data.int16);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_PID:
snprintf(tbuf, sizeof(tbuf), "%lu", (unsigned long)kvs[i].data.pid);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT64:
snprintf(tbuf, sizeof(tbuf), "%ld", (long int)kvs[i].data.int64);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_FLOAT:
snprintf(tbuf, sizeof(tbuf), "%f", kvs[i].data.fval);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_TIMEVAL:
/* we only care about seconds */
nowtime = kvs[i].data.tv.tv_sec;
nowtm = localtime(&nowtime);
strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", nowtm);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
}
}
/* assemble the value string */
vstr = opal_argv_join(cmdargs, ',');
/* print it */
fprintf(fpout, "%s\n", vstr);
free(vstr);
return ORTE_SUCCESS;
}

27
orte/mca/db/print/db_print.h Обычный файл
Просмотреть файл

@ -0,0 +1,27 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef ORTE_DB_PRINT_H
#define ORTE_DB_PRINT_H
#include "orte/mca/db/db.h"
BEGIN_C_DECLS
typedef struct {
orte_db_base_component_t super;
char *filename;
} orte_db_print_component_t;
ORTE_MODULE_DECLSPEC extern orte_db_print_component_t mca_db_print_component;
ORTE_DECLSPEC extern orte_db_base_module_t orte_db_print_module;
END_C_DECLS
#endif /* ORTE_DB_PRINT_H */

94
orte/mca/db/print/db_print_component.c Обычный файл
Просмотреть файл

@ -0,0 +1,94 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
* These symbols are in a file by themselves to provide nice linker
* semantics. Since linkers generally pull in symbols by object
* files, keeping these symbols as the only symbols in this file
* prevents utility programs such as "ompi_info" from having to import
* entire components just to query their version and parameters.
*/
#include "orte_config.h"
#include "orte/constants.h"
#include "opal/mca/base/base.h"
#include "opal/mca/base/mca_base_param.h"
#include "orte/util/proc_info.h"
#include "orte/mca/db/db.h"
#include "orte/mca/db/base/base.h"
#include "db_print.h"
extern orte_db_base_module_t orte_db_print_module;
static int print_component_open(void);
static int print_component_close(void);
static int print_component_query(mca_base_module_t **module, int *priority);
/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
orte_db_print_component_t mca_db_print_component = {
{
{
ORTE_DB_BASE_VERSION_1_0_0,
/* Component name and version */
"print",
ORTE_MAJOR_VERSION,
ORTE_MINOR_VERSION,
ORTE_RELEASE_VERSION,
/* Component open and close functions */
print_component_open,
print_component_close,
print_component_query
},
{
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
}
}
};
static int print_component_open(void)
{
mca_base_component_t *c = &mca_db_print_component.super.base_version;
mca_base_param_reg_string(c, "file",
"Print to the indicated file (- => stdout, + => stderr)",
false, false, NULL, &mca_db_print_component.filename);
return ORTE_SUCCESS;
}
static int print_component_query(mca_base_module_t **module, int *priority)
{
if (NULL == mca_db_print_component.filename) {
*priority = 0;
*module = NULL;
return ORTE_ERROR;
}
/* put us at the top of the list */
*priority = 100;
*module = (mca_base_module_t*)&orte_db_print_module;
return ORTE_SUCCESS;
}
static int print_component_close(void)
{
if (NULL != mca_db_print_component.filename) {
free(mca_db_print_component.filename);
}
return ORTE_SUCCESS;
}