Skip to content

Commit

Permalink
Implement config manager and built-in channel controllers (#174)
Browse files Browse the repository at this point in the history
* ConfigManager: initial implementation

* Reorganize built-in controllers

* Add test for spot controller

* Add Spot v1 controller

* Rename ConfigManager.hpp -> ConfigManager.h

* Add missing include
  • Loading branch information
daboehme committed May 31, 2019
1 parent d1cfc89 commit d5f056a
Show file tree
Hide file tree
Showing 30 changed files with 1,447 additions and 9 deletions.
20 changes: 20 additions & 0 deletions examples/apps/cali-basic-annotations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,26 @@
// A C++ Caliper instrumentation demo

#include <caliper/cali.h>
#include <caliper/cali-manager.h>

int main(int argc, char* argv[])
{
cali::ConfigManager mgr;

mgr.use_mpi(false);

if (argc > 1) {
mgr.add(argv[1]);

if (mgr.error())
std::cerr << "Caliper config error: " << mgr.error_msg() << std::endl;
}

auto channels = mgr.get_all_channels();

for (auto &c : channels)
c->start();

// Mark begin/end of the current function.
// Sets "function=main" in Caliper.
CALI_CXX_MARK_FUNCTION;
Expand Down Expand Up @@ -65,4 +82,7 @@ int main(int argc, char* argv[])
}

CALI_CXX_MARK_LOOP_END(mainloop);

for (auto &c : channels)
c->flush();
}
3 changes: 3 additions & 0 deletions include/caliper/ChannelController.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class ChannelController
/// \brief Returns true if channel exists and is active, false otherwise.
bool is_active() const;

/// \brief Returns the name of the underlying channel
std::string name() const;

/// \brief Flush the underlying %Caliper channel.
///
/// Allows derived classes to implement custom %Caliper data processing.
Expand Down
63 changes: 63 additions & 0 deletions include/caliper/ConfigManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2019, Lawrence Livermore National Security, LLC.
// See top-level LICENSE file for details.

/// \file ConfigManager.hpp
/// \brief %Caliper ConfigManager class definition

#pragma once

#include <map>
#include <memory>
#include <string>
#include <vector>

namespace cali
{

class ChannelController;

class ConfigManager
{
struct ConfigManagerImpl;
std::shared_ptr<ConfigManagerImpl> mP;

public:

typedef std::map<std::string, std::string> argmap_t;

typedef cali::ChannelController* (*CreateConfigFn)(const argmap_t&, bool);

struct ConfigInfo {
const char* name;
const char** args;
CreateConfigFn create;
};

static void
add_controllers(const ConfigInfo*);

ConfigManager();

explicit ConfigManager(const char* config_string);

~ConfigManager();

bool add(const char* config_string);

void use_mpi(bool);
void set_default_parameter(const char* key, const char* value);

bool error() const;
std::string error_msg() const;

typedef std::shared_ptr<cali::ChannelController> ChannelPtr;
typedef std::vector<ChannelPtr> ChannelList;

ChannelList
get_all_channels();

ChannelPtr
get_channel(const char* name);
};

} // namespace cali
15 changes: 15 additions & 0 deletions include/caliper/cali-manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2019, Lawrence Livermore National Security, LLC.
// See top-level LICENSE file for details.

#pragma once

#ifdef __cplusplus
#include "caliper/ConfigManager.h"
#include "caliper/ChannelController.h"

extern "C" {
#endif

#ifdef __cplusplus
} // extern "C"
#endif
49 changes: 49 additions & 0 deletions manager/include/caliper/ConfigManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2019, Lawrence Livermore National Security, LLC.
// See top-level LICENSE file for details.

/// \file ConfigManager.hpp
/// \brief %Caliper ConfigManager class definition

#pragma once

#include <memory>
#include <string>
#include <vector>

namespace cali
{

class ChannelController;

class ConfigManager
{
struct ConfigManagerImpl;
std::shared_ptr<ConfigManagerImpl> mP;

public:

ConfigManager();

explicit ConfigManager(const char* config_string);

~ConfigManager();

bool add(const char* config_string);

void use_mpi(bool);
void set_default_parameter(const char* key, const char* value);

bool error() const;
std::string error_msg() const;

typedef std::shared_ptr<cali::ChannelController> ChannelPtr;
typedef std::vector<ChannelPtr> ChannelList;

ChannelList
get_all_channels();

ChannelPtr
get_channel(const char* name);
};

} // namespace cali
15 changes: 15 additions & 0 deletions manager/include/caliper/cali-manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2019, Lawrence Livermore National Security, LLC.
// See top-level LICENSE file for details.

#pragma once

#ifdef __cplusplus
#include "caliper/ConfigManager.hpp"
#include "caliper/ChannelController.h"

extern "C" {
#endif

#ifdef __cplusplus
} // extern "C"
#endif
33 changes: 33 additions & 0 deletions manager/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
include_directories("../include")
include_directories("../../mpi/include")
include_directories(${MPI_CXX_INCLUDE_PATH})

if (${CMAKE_CXX_COMPILER_ID} MATCHES Intel)
# CMake does not have proper compiler feature support for Intel compilers :-/
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
else()
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 99)
endif()

set(CONFIG_MANAGER_SOURCES
ConfigManager.cpp
RuntimeProfileController.cpp
SpotController.cpp)

add_library(caliper-config-manager
${CONFIG_MANAGER_SOURCES})

target_link_libraries(caliper-config-manager PUBLIC caliper)

if (CALIPER_HAVE_MPI)
target_link_libraries(caliper-config-manager PUBLIC caliper-mpi)
endif()

if (BUILD_TESTING)
add_subdirectory(test)
endif()
Loading

0 comments on commit d5f056a

Please sign in to comment.