Newer
Older
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
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* ExampleEnginePlugin.cpp This plugin does nothing but write API calls out to a
* log file.
*
* Created on: Jul 31, 2017
* Author: Chuck Atkins <chuck.atkins@kitware.com>
*/
#include "ExampleEnginePlugin.h"
#include <cstdio>
#include <cstring>
#include <ctime>
#ifndef _WIN32_
#include <sys/time.h>
#endif
namespace
{
std::string now()
{
tm *timeInfo;
#ifdef _WIN32
time_t rawTime;
std::time(&rawTime);
timeInfo = std::localtime(&rawtime);
#else
timeval curTime;
gettimeofday(&curTime, nullptr);
timeInfo = std::localtime(&curTime.tv_sec);
#endif
char timeBuf[80];
std::memset(timeBuf, 0, sizeof(timeBuf));
std::strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%dT%H:%M:%S", timeInfo);
#ifdef _WIN32
return std::string(timeBuf);
#else
double subSec = curTime.tv_usec / 1e6;
char subSecBuf[9];
std::memset(subSecBuf, 0, sizeof(subSecBuf));
std::sprintf(subSecBuf, "%1.6f", subSec);
return std::string(timeBuf) + std::string(&subSecBuf[1]);
#endif
}
}
namespace adios2
{
ExampleEnginePlugin::ExampleEnginePlugin(IO &io, const std::string &name,
const OpenMode openMode,
MPI_Comm mpiComm)
: adios2::PluginEngineInterface(io, name, openMode, mpiComm)
{
Init();
}
ExampleEnginePlugin::~ExampleEnginePlugin() { m_Log.close(); }
void ExampleEnginePlugin::Close(const int transportIndex)
{
m_Log << now() << " Close with transportIndex " << transportIndex
<< std::endl;
}
void ExampleEnginePlugin::Init()
{
std::string logName = "ExamplePlugin.log";
auto paramLogNameIt = m_IO.m_Parameters.find("LogName");
if (paramLogNameIt != m_IO.m_Parameters.end())
{
logName = paramLogNameIt->second;
}
m_Log.open(logName);
if (!m_Log)
{
throw std::ios_base::failure(
"ExampleEnginePlugin: Failed to open log file " + logName);
}
m_Log << now() << " Init" << std::endl;
}
#define define(T) \
void ExampleEnginePlugin::DoWrite(Variable<T> &variable, const T *values) \
{ \
m_Log << now() << " Writing variable \"" << variable.m_Name << "\"" \
<< std::endl; \
}
ADIOS2_FOREACH_TYPE_1ARG(define)
#undef define
void ExampleEnginePlugin::DoWrite(VariableCompound &variable,
const void *values)
{
m_Log << now() << " Writing variable \"" << variable.m_Name << "\""
<< std::endl;
}
} // end namespace adios2