Skip to content

Commit 691703a

Browse files
committed
Tracing for HDF5
1 parent f0d364f commit 691703a

File tree

8 files changed

+208
-19
lines changed

8 files changed

+208
-19
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ endif()
440440
if(openPMD_HAVE_LOGGING)
441441
add_library(openPMD::thirdparty::spdlog INTERFACE IMPORTED)
442442
if(openPMD_USE_INTERNAL_SPDLOG)
443-
target_include_directories(openPMD::thirdparty::spdlog SYSTEM INTERFACE
443+
target_include_directories(openPMD PUBLIC
444444
$<BUILD_INTERFACE:${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/spdlog/include>
445445
)
446446
message(STATUS "spdlog: Using INTERNAL version 1.3.1")

include/openPMD/auxiliary/Logging.hpp

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/* Copyright 2019 Fabian Koller
2+
*
3+
* This file is part of openPMD-api.
4+
*
5+
* openPMD-api is free software: you can redistribute it and/or modify
6+
* it under the terms of of either the GNU General Public License or
7+
* the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* openPMD-api is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License and the GNU Lesser General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* and the GNU Lesser General Public License along with openPMD-api.
19+
* If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
#pragma once
22+
23+
#if openPMD_HAVE_LOGGING
24+
# include <spdlog/spdlog.h>
25+
#endif
26+
27+
namespace openPMD
28+
{
29+
namespace auxiliary
30+
{
31+
namespace log
32+
{
33+
34+
enum class Level
35+
{
36+
TRACE,
37+
DEBUG,
38+
INFO,
39+
WARN,
40+
ERROR,
41+
CRITICAL,
42+
OFF
43+
}; // Level
44+
45+
#if openPMD_HAVE_LOGGING
46+
static void
47+
set_level(Level level)
48+
{
49+
switch( level ) {
50+
case Level::TRACE:
51+
spdlog::set_level(spdlog::level::trace);
52+
return;
53+
case Level::DEBUG:
54+
spdlog::set_level(spdlog::level::debug);
55+
return;
56+
case Level::INFO:
57+
spdlog::set_level(spdlog::level::info);
58+
return;
59+
case Level::WARN:
60+
spdlog::set_level(spdlog::level::warn);
61+
return;
62+
case Level::ERROR:
63+
spdlog::set_level(spdlog::level::err);
64+
return;
65+
case Level::CRITICAL:
66+
spdlog::set_level(spdlog::level::critical);
67+
return;
68+
case Level::OFF:
69+
spdlog::set_level(spdlog::level::off);
70+
return;
71+
default:
72+
throw std::runtime_error("Logging level not supported!");
73+
}
74+
}
75+
# define LOG_SET_LEVEL(LEVEL) { set_level((LEVEL)); }
76+
# define LOG_TRACE(...) { spdlog::trace(__VA_ARGS__); }
77+
# define LOG_DEBUG(...) { spdlog::debug(__VA_ARGS__); }
78+
# define LOG_INFO(...) { spdlog::info(__VA_ARGS__); }
79+
# define LOG_WARN(...) { spdlog::warn(__VA_ARGS__); }
80+
# define LOG_ERROR(...) { spdlog::error(__VA_ARGS__); }
81+
# define LOG_CRITICAL(...) { spdlog::critical(__VA_ARGS__); }
82+
#else
83+
# define NOOP do{ (void)sizeof(void); } while( 0 )
84+
# define LOG_SET_LEVEL(LEVEL) NOOP
85+
# define LOG_TRACE(...) NOOP
86+
# define LOG_DEBUG(...) NOOP
87+
# define LOG_INFO(...) NOOP
88+
# define LOG_WARN(...) NOOP
89+
# define LOG_ERROR(...) NOOP
90+
# define LOG_CRITICAL(...) NOOP
91+
#endif
92+
} // log
93+
} // auxiliary
94+
} // openPMD

include/openPMD/auxiliary/StringManip.hpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,43 @@ strip(std::string s, std::vector< char > to_remove)
165165
return s;
166166
}
167167

168+
template< typename T >
168169
inline std::string
169-
join(std::vector< std::string > const& vs, std::string const& delimiter)
170+
join(std::vector< T > const& vt, std::string const& delimiter)
170171
{
171-
switch( vs.size() )
172+
switch( vt.size() )
172173
{
173174
case 0:
174175
return "";
175176
case 1:
176-
return vs[0];
177+
return std::to_string(vt[0]);
177178
default:
178179
std::ostringstream ss;
179-
std::copy(vs.begin(),
180-
vs.end() - 1,
180+
std::transform(vt.begin(),
181+
vt.end() - 1,
182+
std::ostream_iterator< std::string >(ss, delimiter.c_str()),
183+
[](T const& t) -> std::string { return std::to_string(t); });
184+
ss << std::to_string(*(vt.end() - 1));
185+
return ss.str();
186+
}
187+
}
188+
189+
template< >
190+
inline std::string
191+
join< std::string >(std::vector< std::string > const& vt, std::string const& delimiter)
192+
{
193+
switch( vt.size() )
194+
{
195+
case 0:
196+
return "";
197+
case 1:
198+
return vt[0];
199+
default:
200+
std::ostringstream ss;
201+
std::copy(vt.begin(),
202+
vt.end() - 1,
181203
std::ostream_iterator< std::string >(ss, delimiter.c_str()));
182-
ss << *(vs.end() - 1);
204+
ss << *(vt.end() - 1);
183205
return ss.str();
184206
}
185207
}

include/openPMD/openPMD.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
#include "openPMD/IO/AccessType.hpp"
4646

47+
#include "openPMD/auxiliary/Logging.hpp"
4748
#include "openPMD/auxiliary/OutOfRangeMsg.hpp"
4849
#include "openPMD/auxiliary/ShareRaw.hpp"
4950
#include "openPMD/auxiliary/Variant.hpp"

src/IO/AbstractIOHandlerHelper.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
* You should have received a copy of the GNU General Public License
1818
* and the GNU Lesser General Public License along with openPMD-api.
1919
* If not, see <http://www.gnu.org/licenses/>.
20-
*/
20+
*/
21+
#include "openPMD/auxiliary/Logging.hpp"
2122
#include "openPMD/IO/AbstractIOHandlerHelper.hpp"
2223
#include "openPMD/IO/DummyIOHandler.hpp"
2324
#include "openPMD/IO/ADIOS/ADIOS1IOHandler.hpp"
@@ -41,17 +42,20 @@ namespace openPMD
4142
switch( format )
4243
{
4344
case Format::HDF5:
45+
LOG_DEBUG("Creating parallel HDF5 IOHandler");
4446
return std::make_shared< ParallelHDF5IOHandler >(path, accessTypeBackend, comm);
4547
case Format::ADIOS1:
48+
LOG_DEBUG("Creating parallel ADIOS1 IOHandler");
4649
# if openPMD_HAVE_ADIOS1
4750
return std::make_shared< ParallelADIOS1IOHandler >(path, accessTypeBackend, comm);
4851
# else
4952
throw std::runtime_error("openPMD-api built without ADIOS1 support");
50-
return std::make_shared< DummyIOHandler >(path, accessTypeBackend);
5153
# endif
5254
case Format::ADIOS2:
55+
LOG_DEBUG("Creating parallel ADIOS2 IOHandler");
5356
throw std::runtime_error("ADIOS2 backend not yet implemented");
5457
default:
58+
LOG_DEBUG("Creating parallel dummy IOHandler");
5559
return std::make_shared< DummyIOHandler >(path, accessTypeBackend);
5660
}
5761
}
@@ -66,19 +70,23 @@ namespace openPMD
6670
switch( format )
6771
{
6872
case Format::HDF5:
73+
LOG_DEBUG("Creating serial HDF5 IOHandler");
6974
return std::make_shared< HDF5IOHandler >(path, accessType);
7075
case Format::ADIOS1:
76+
LOG_DEBUG("Creating serial ADIOS1 IOHandler");
7177
# if openPMD_HAVE_ADIOS1
7278
return std::make_shared< ADIOS1IOHandler >(path, accessType);
7379
# else
7480
throw std::runtime_error("openPMD-api built without ADIOS1 support");
75-
return std::make_shared< DummyIOHandler >(path, accessType);
7681
# endif
7782
case Format::ADIOS2:
83+
LOG_DEBUG("Creating serial ADIOS1 IOHandler");
7884
throw std::runtime_error("ADIOS2 backend not yet implemented");
7985
case Format::JSON:
86+
LOG_DEBUG("Creating serial ADIOS1 IOHandler");
8087
return std::make_shared< JSONIOHandler >(path, accessType);
8188
default:
89+
LOG_DEBUG("Creating serial dummy IOHandler");
8290
return std::make_shared< DummyIOHandler >(path, accessType);
8391
}
8492
}

0 commit comments

Comments
 (0)