Add posibility to use files as source of configuration
authorAleksei Vereshchagin <avereschagin@dev.rtsoft.ru>
Fri, 30 Mar 2018 18:30:05 +0000 (21:30 +0300)
committerAleksei Vereshchagin <avereschagin@dev.rtsoft.ru>
Fri, 30 Mar 2018 18:30:05 +0000 (21:30 +0300)
src/CMakeLists.txt
src/config/configurationmanager.cpp [new file with mode: 0644]
src/config/configurationmanager.h [new file with mode: 0644]
src/config/environmentconfigprovider.cpp
src/config/environmentconfigprovider.h
src/config/fileconfigprovider.cpp [new file with mode: 0644]
src/config/fileconfigprovider.h [new file with mode: 0644]
src/profiler.cpp
src/profilermanager.cpp
src/profilermanager.h

index dc3760198176325536a6c0403955a412f3eab64f..c92db8f82af221999ed2a9d78ddfab47bc12020e 100644 (file)
@@ -13,7 +13,9 @@ add_library(coreprof
   SHARED
   classfactory.cpp
   config/commonconfigconversions.cpp
+  config/configurationmanager.cpp
   config/environmentconfigprovider.cpp
+  config/fileconfigprovider.cpp
   config/loggerconfig.cpp
   config/loggerconfigconversions.cpp
   config/profilerconfig.cpp
diff --git a/src/config/configurationmanager.cpp b/src/config/configurationmanager.cpp
new file mode 100644 (file)
index 0000000..860a290
--- /dev/null
@@ -0,0 +1,256 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdexcept>
+#include <sstream>
+
+#include <stdlib.h>
+
+#include "profiler.h"
+
+#include "commonconfig.h"
+#include "commonconfigconversions.h"
+#include "loggerconfigconversions.h"
+#include "tracelogconfigconversions.h"
+#include "profilerconfigconversions.h"
+
+#include "configurationmanager.h"
+
+ConfigurationManager::ConfigurationManager(Log &logger)
+    : m_logger(logger)
+    , m_fileConfigProvider()
+    , m_environmentConfigProvider()
+{
+    const char *config_filename = getenv("PROF_CONFIG_FILENAME");
+    if (config_filename)
+    {
+        m_fileConfigProvider.reset(new FileConfigProvider(config_filename));
+    }
+
+    m_environmentConfigProvider.reset(new EnvironmentConfigProvider());
+}
+
+template<typename T>
+bool ConfigurationManager::FetchValue(const std::string &name, T &value) const
+{
+    std::string str_value;
+
+    bool from_file = false;
+    if (m_fileConfigProvider)
+    {
+        from_file = m_fileConfigProvider->FetchValue(name, str_value);
+    }
+
+    bool from_env = m_environmentConfigProvider->FetchValue(name, str_value);
+    if (from_file && from_env)
+    {
+        m_logger.Info() << "Configuration variable " << name <<
+            " was overrided by environment";
+    }
+
+    if (from_file || from_env)
+    {
+        try
+        {
+            value = convert<T>(str_value.c_str());
+        }
+        catch (const std::runtime_error &e)
+        {
+            std::stringstream ss;
+            ss << "variable " << name << "=" << str_value <<
+                " can't be parsed: " << e.what();
+            throw config_error(ss.str());
+        }
+
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}
+
+void ConfigurationManager::FetchConfig(LoggerConfig &config) const
+{
+    // Save current configuration to temporary.
+    LoggerConfig new_config(config);
+
+    //
+    // Fetching from the environment can cause exceptions.
+    //
+
+    FetchValue("PROF_LOG_LEVEL", new_config.Level);
+
+    bool file_name_specified =
+        FetchValue("PROF_LOG_FILENAME", new_config.FileName);
+    if (file_name_specified)
+    {
+        new_config.OutputStream = LoggerOutputStream::File;
+    }
+
+    FetchValue("PROF_LOG_STREAM", new_config.OutputStream);
+
+    // Apply changes to the current configuration.
+    config = new_config;
+}
+
+void ConfigurationManager::FetchConfig(TraceLogConfig &config) const
+{
+    // Save current configuration to temporary.
+    TraceLogConfig new_config(config);
+
+    //
+    // Fetching from the environment can cause exceptions.
+    //
+
+    bool file_name_specified =
+        FetchValue("PROF_TRACE_FILENAME", new_config.FileName);
+    if (file_name_specified)
+    {
+        new_config.OutputStream = TraceLogOutputStream::File;
+    }
+
+    FetchValue("PROF_TRACE_STREAM", new_config.OutputStream);
+
+    // Apply changes to the current configuration.
+    config = new_config;
+}
+
+void ConfigurationManager::FetchConfig(ProfilerConfig &config) const
+{
+    // Save current configuration to temporary.
+    ProfilerConfig new_config(config);
+
+    //
+    // Fetching from the environment can cause exceptions.
+    //
+    // We don't check whether the environment variables override the
+    // configuration or not.
+    //
+
+    FetchValue("PROF_COLLECT_METHOD", new_config.CollectionMethod);
+    if (new_config.CollectionMethod != CollectionMethod::Sampling)
+    {
+        new_config.SamplingTimeoutMs = 0;
+        new_config.HighGranularityEnabled = false;
+    }
+    if (FetchValue("PROF_SAMPLING_TIMEOUT", new_config.SamplingTimeoutMs))
+    {
+        new_config.CpuTraceTimeoutMs = new_config.SamplingTimeoutMs;
+    }
+    FetchValue("PROF_HIGH_GRAN",     new_config.HighGranularityEnabled);
+    FetchValue("PROF_DELAYED_START", new_config.TracingSuspendedOnStart);
+    FetchValue("PROF_LINE_TRACE",    new_config.LineTraceEnabled);
+
+    bool CpuTraceEnabled;
+    if (FetchValue("PROF_CPU_TRACE", CpuTraceEnabled))
+    {
+        new_config.CpuTraceProcessEnabled = CpuTraceEnabled;
+        new_config.CpuTraceThreadEnabled  = CpuTraceEnabled;
+    }
+    FetchValue("PROF_CPU_TRACE_PROC",   new_config.CpuTraceProcessEnabled);
+    FetchValue("PROF_CPU_TRACE_THREAD", new_config.CpuTraceThreadEnabled);
+    if (!new_config.CpuTraceProcessEnabled && !new_config.CpuTraceThreadEnabled)
+    {
+        new_config.CpuTraceTimeoutMs = 0;
+    }
+    FetchValue("PROF_CPU_TRACE_TIMEOUT", new_config.CpuTraceTimeoutMs);
+
+    FetchValue("PROF_EXECUTION_TRACE",  new_config.ExecutionTraceEnabled);
+    FetchValue("PROF_MEMORY_TRACE",     new_config.MemoryTraceEnabled);
+    if (new_config.MemoryTraceEnabled &&
+        new_config.ExecutionTraceEnabled &&
+        new_config.CollectionMethod == CollectionMethod::Sampling)
+    {
+        new_config.StackTrackingEnabled = true;
+    }
+
+    FetchValue("PROF_STACK_TRACK",      new_config.StackTrackingEnabled);
+
+    bool GcTraceEnabled;
+    if (FetchValue("PROF_GC_TRACE", GcTraceEnabled))
+    {
+        new_config.GcAllocTableTraceEnabled = GcTraceEnabled;
+    }
+    FetchValue("PROF_GC_TRACE_ALT",     new_config.GcAllocTableTraceEnabled);
+
+    // Apply changes to the current configuration.
+    config = new_config;
+}
+
+template<typename T>
+T ConfigurationManager::FetchGenericConfig() const
+{
+    T config;
+
+    FetchConfig(config);
+
+    config.Validate();
+
+    auto warnings = config.Verify();
+    if (!warnings.empty())
+    {
+        auto logLine = m_logger.Warn();
+        logLine << "Some errors detected in " << config.Name() << ":";
+        for (const auto &warning : warnings)
+        {
+            logLine << "\n\t\t" << warning;
+        }
+    }
+
+    return config;
+}
+
+LoggerConfig ConfigurationManager::FetchLoggerConfig() const
+{
+    return FetchGenericConfig<LoggerConfig>();
+}
+
+TraceLogConfig ConfigurationManager::FetchTraceLogConfig() const
+{
+    return FetchGenericConfig<TraceLogConfig>();
+}
+
+ProfilerConfig ConfigurationManager::FetchProfilerConfig() const
+{
+    return FetchGenericConfig<ProfilerConfig>();
+}
+
+bool ConfigurationManager::CheckUnused() const
+{
+    if (!m_fileConfigProvider)
+    {
+        return true;
+    }
+
+    auto unused = m_fileConfigProvider->GetUnused();
+    if (!unused.empty())
+    {
+        auto logLine = m_logger.Warn();
+        logLine << "Some options from configuration file was unused:";
+        for (const auto &param : unused)
+        {
+            auto &param_name = param.first;
+            auto &param_value = param.second;
+
+            logLine << "\n\t\t" << param_name << "=" << param_value;
+        }
+
+        return false;
+    }
+
+    return true;
+}
diff --git a/src/config/configurationmanager.h b/src/config/configurationmanager.h
new file mode 100644 (file)
index 0000000..d0947c4
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONFIGURATION_MANAGER_H_
+#define _CONFIGURATION_MANAGER_H_
+
+#include <string>
+#include <memory>
+
+#include "log.h"
+
+#include "loggerconfig.h"
+#include "tracelogconfig.h"
+#include "profilerconfig.h"
+
+#include "fileconfigprovider.h"
+#include "environmentconfigprovider.h"
+
+class ConfigurationManager
+{
+public:
+    ConfigurationManager(Log &m_logger);
+
+private:
+    // Internal template method that takes name of the configuration variable
+    // and tries to fetch it from file than from environment and convert it to
+    // type T. If the value of the variable is incorrect, bad_conversion
+    // exception should be thrown.
+    //
+    // FetchValue() will log info message if some configuration variable from
+    // file overrided by environment.
+    //
+    // FetchValue() will return true on success convertion or false if specified
+    // variable is not presented.
+    template<typename T>
+    bool FetchValue(const std::string &name, T &value) const;
+
+    //
+    // FetchConfig() overrides the configuration with values fetched with
+    // FetchValue(). Other values are not changed. The configuration wouldn't
+    // chang if exception were thrown. Error messages of runtime exceptions are
+    // complemented by information about the variable that caused the problem.
+    // config_error class is used for this exceptions.
+    //
+
+    void FetchConfig(LoggerConfig &config) const;
+
+    void FetchConfig(TraceLogConfig &config) const;
+
+    void FetchConfig(ProfilerConfig &config) const;
+
+    // Get configuration for config type T from the Global Area.
+    template<typename T>
+    T FetchGenericConfig() const;
+
+public:
+    // Get logger configuration from the Global Area.
+    LoggerConfig FetchLoggerConfig() const;
+
+    // Get trace configuration from the Global Area.
+    TraceLogConfig FetchTraceLogConfig() const;
+
+    // Get configuration from the Global Area.
+    ProfilerConfig FetchProfilerConfig() const;
+
+    bool CheckUnused() const;
+
+private:
+    Log &m_logger;
+
+    std::unique_ptr<FileConfigProvider> m_fileConfigProvider;
+    std::unique_ptr<EnvironmentConfigProvider> m_environmentConfigProvider;
+};
+
+#endif // _CONFIGURATION_MANAGER_H_
index 759ca129a95312ecb3e44701debcde64d7d7d87c..292f5624fd4e06827944e6721ba73344990762d0 100644 (file)
  * limitations under the License.
  */
 
-#include <stdexcept>
-#include <sstream>
-
 #include <stdlib.h>
 
-#include "commonconfig.h"
-#include "commonconfigconversions.h"
-#include "loggerconfigconversions.h"
-#include "tracelogconfigconversions.h"
-#include "profilerconfigconversions.h"
 #include "environmentconfigprovider.h"
 
-template<typename T>
-bool EnvironmentConfigProvider::FetchValue(const char *name, T &value) const
-{
-    const char *env = getenv(name);
-    if (env)
-    {
-        try
-        {
-            value = convert<T>(env);
-        }
-        catch (const std::runtime_error &e)
-        {
-            std::stringstream ss;
-            ss << "variable " << name << "=" << env <<
-                " can't be parsed: " << e.what();
-            throw config_error(ss.str());
-        }
-
-        return true;
-    }
-    else
-    {
-        return false;
-    }
-}
-
-void EnvironmentConfigProvider::FetchConfig(LoggerConfig &config) const
-{
-    // Save current configuration to temporary.
-    LoggerConfig new_config(config);
-
-    //
-    // Fetching from the environment can cause exceptions.
-    //
-
-    FetchValue("PROF_LOG_LEVEL", new_config.Level);
-
-    bool file_name_specified =
-        FetchValue("PROF_LOG_FILENAME", new_config.FileName);
-    if (file_name_specified)
-    {
-        new_config.OutputStream = LoggerOutputStream::File;
-    }
-
-    FetchValue("PROF_LOG_STREAM", new_config.OutputStream);
-
-    // Apply changes to the current configuration.
-    config = new_config;
-}
-
-void EnvironmentConfigProvider::FetchConfig(TraceLogConfig &config) const
-{
-    // Save current configuration to temporary.
-    TraceLogConfig new_config(config);
-
-    //
-    // Fetching from the environment can cause exceptions.
-    //
-
-    bool file_name_specified =
-        FetchValue("PROF_TRACE_FILENAME", new_config.FileName);
-    if (file_name_specified)
-    {
-        new_config.OutputStream = TraceLogOutputStream::File;
-    }
-
-    FetchValue("PROF_TRACE_STREAM", new_config.OutputStream);
-
-    // Apply changes to the current configuration.
-    config = new_config;
-}
-
-void EnvironmentConfigProvider::FetchConfig(ProfilerConfig &config) const
+bool EnvironmentConfigProvider::FetchValue(
+    const std::string &name, std::string &value) const
 {
-    // Save current configuration to temporary.
-    ProfilerConfig new_config(config);
-
-    //
-    // Fetching from the environment can cause exceptions.
-    //
-    // We don't check whether the environment variables override the
-    // configuration or not.
-    //
-
-    FetchValue("PROF_COLLECT_METHOD", new_config.CollectionMethod);
-    if (new_config.CollectionMethod != CollectionMethod::Sampling)
-    {
-        new_config.SamplingTimeoutMs = 0;
-        new_config.HighGranularityEnabled = false;
-    }
-    if (FetchValue("PROF_SAMPLING_TIMEOUT", new_config.SamplingTimeoutMs))
-    {
-        new_config.CpuTraceTimeoutMs = new_config.SamplingTimeoutMs;
-    }
-    FetchValue("PROF_HIGH_GRAN",     new_config.HighGranularityEnabled);
-    FetchValue("PROF_DELAYED_START", new_config.TracingSuspendedOnStart);
-    FetchValue("PROF_LINE_TRACE",    new_config.LineTraceEnabled);
-
-    bool CpuTraceEnabled;
-    if (FetchValue("PROF_CPU_TRACE", CpuTraceEnabled))
-    {
-        new_config.CpuTraceProcessEnabled = CpuTraceEnabled;
-        new_config.CpuTraceThreadEnabled  = CpuTraceEnabled;
-    }
-    FetchValue("PROF_CPU_TRACE_PROC",   new_config.CpuTraceProcessEnabled);
-    FetchValue("PROF_CPU_TRACE_THREAD", new_config.CpuTraceThreadEnabled);
-    if (!new_config.CpuTraceProcessEnabled && !new_config.CpuTraceThreadEnabled)
-    {
-        new_config.CpuTraceTimeoutMs = 0;
-    }
-    FetchValue("PROF_CPU_TRACE_TIMEOUT", new_config.CpuTraceTimeoutMs);
-
-    FetchValue("PROF_EXECUTION_TRACE",  new_config.ExecutionTraceEnabled);
-    FetchValue("PROF_MEMORY_TRACE",     new_config.MemoryTraceEnabled);
-    if (new_config.MemoryTraceEnabled &&
-        new_config.ExecutionTraceEnabled &&
-        new_config.CollectionMethod == CollectionMethod::Sampling)
-    {
-        new_config.StackTrackingEnabled = true;
-    }
-
-    FetchValue("PROF_STACK_TRACK",      new_config.StackTrackingEnabled);
-
-    bool GcTraceEnabled;
-    if (FetchValue("PROF_GC_TRACE", GcTraceEnabled))
+    const char *env_str = getenv(name.c_str());
+    if (env_str)
     {
-        new_config.GcAllocTableTraceEnabled = GcTraceEnabled;
+        value = env_str;
     }
-    FetchValue("PROF_GC_TRACE_ALT",     new_config.GcAllocTableTraceEnabled);
 
-    // Apply changes to the current configuration.
-    config = new_config;
+    return env_str != nullptr;
 }
index 36d8d71a77ee9561d711b5282da840bd5a368cc5..b6bde01876598440791e0c94a07d142e29454bbf 100644 (file)
 #ifndef _ENVIRONMENT_CONFIG_PROVIDER_H_
 #define _ENVIRONMENT_CONFIG_PROVIDER_H_
 
-#include "loggerconfig.h"
-#include "tracelogconfig.h"
-#include "profilerconfig.h"
+#include <string>
 
 class EnvironmentConfigProvider
 {
-private:
-    // Internal template method that takes name of the environment variable and
-    // tries to fetch it and convert to type T. If the value of the variable
-    // is incorrect, bad_conversion exception should be thrown.
-    //
-    // FetchValue() will return true on success convertion or false if specified
-    // variable is not presented.
-    template<typename T>
-    bool FetchValue(const char *name, T &value) const;
-
 public:
-    //
-    // FetchConfig() overrides the configuration with values fetched from the
-    // environment. Other values are not changed. The configuration wouldn't
-    // chang if exception were thrown. Error messages of runtime exceptions are
-    // complemented by information about the variable that caused the problem.
-    // config_error class is used for this exceptions.
-    //
-
-    void FetchConfig(LoggerConfig &config) const;
-
-    void FetchConfig(TraceLogConfig &config) const;
-
-    void FetchConfig(ProfilerConfig &config) const;
+    // FetchValue() will return false if specified variable is not presented.
+    // Otherwise returns true.
+    bool FetchValue(const std::string &name, std::string &value) const;
 };
 
 #endif // _ENVIRONMENT_CONFIG_PROVIDER_H_
diff --git a/src/config/fileconfigprovider.cpp b/src/config/fileconfigprovider.cpp
new file mode 100644 (file)
index 0000000..8ba4ef0
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <iostream>
+#include <fstream>
+#include <system_error>
+#include <stdexcept>
+
+#include <assert.h>
+#include <errno.h>
+#include <ctype.h>
+
+#include "fileconfigprovider.h"
+
+FileConfigProvider::FileConfigProvider(const std::string &filename)
+    : m_data()
+{
+    std::ifstream stream;
+    stream.exceptions(std::ios::badbit);
+    stream.open(filename, std::ios::in);
+
+    std::string line;
+    while (std::getline(stream, line))
+    {
+        std::string name;
+        std::string value;
+        bool is_name = true;
+        auto parse_error = std::runtime_error(
+            "FileConfigProvider::FileConfigProvider(): "
+            "can't parse config file (syntax error)"
+        );
+
+        if (line[0] == '=')
+        {
+            throw parse_error;
+        }
+
+        if (line.empty())
+        {
+            continue;
+        }
+
+        for (char c : line)
+        {
+            if (is_name)
+            {
+                if (c == '_' || isalnum(c))
+                {
+                    name.push_back(c);
+                }
+                else if (c == '=')
+                {
+                    is_name = false;
+                }
+                else
+                {
+                    throw parse_error;
+                }
+            }
+            else
+            {
+                value.push_back(c);
+            }
+        }
+
+        if (is_name)
+        {
+            throw parse_error;
+        }
+
+        m_data[name] = std::make_pair(value, false);
+    }
+
+    if (!stream.eof())
+    {
+        assert(stream.fail());
+
+        if (errno)
+        {
+            throw std::system_error(
+                errno, std::system_category(),
+                "FileConfigProvider::FileConfigProvider(): "
+                "can't parse config file"
+            );
+        }
+        else
+        {
+            throw std::runtime_error(
+                "FileConfigProvider::FileConfigProvider(): "
+                "can't parse config file (unknown error)"
+            );
+        }
+    }
+}
+
+bool FileConfigProvider::FetchValue(
+    const std::string &name, std::string &value)
+{
+    auto it = m_data.find(name);
+    if (it != m_data.end())
+    {
+        auto &param_name = it->first;
+        auto &param_value = it->second.first;
+        auto &param_is_used = it->second.second;
+
+        value = param_value;
+        param_is_used = true;
+
+        return true;
+    }
+
+    return false;
+}
+
+std::unordered_map<std::string, std::string>
+FileConfigProvider::GetUnused() const
+{
+    std::unordered_map<std::string, std::string> unused;
+    for (const auto &param : m_data)
+    {
+        auto &param_name = param.first;
+        auto &param_value = param.second.first;
+        auto &param_is_used = param.second.second;
+
+        if (!param_is_used)
+        {
+            unused[param_name] = param_value;
+        }
+    }
+
+    return unused;
+}
diff --git a/src/config/fileconfigprovider.h b/src/config/fileconfigprovider.h
new file mode 100644 (file)
index 0000000..e5aeb9b
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _FILE_CONFIG_PROVIDER_H_
+#define _FILE_CONFIG_PROVIDER_H_
+
+#include <string>
+#include <unordered_map>
+#include <utility>
+
+class FileConfigProvider
+{
+public:
+    FileConfigProvider(const std::string &filename);
+
+    // FetchValue() will return false if specified variable is not presented.
+    // Otherwise returns true.
+    bool FetchValue(const std::string &name, std::string &value);
+
+    // Returns map of name-value pairs of unused parameters.
+    std::unordered_map<std::string, std::string> GetUnused() const;
+
+private:
+    std::unordered_map<
+        std::string, // Name of parameter.
+        std::pair<std::string, bool> // Value of parameter and usage flag.
+    > m_data;
+};
+
+#endif // _FILE_CONFIG_PROVIDER_H_
index 262e1c2091ad54d894f8bb312776e02a2af791d5..06be2b8ecf424cb8312ced27e9bd250ac6d697b7 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "localtime.h"
 #include "profilermanager.h"
+#include "configurationmanager.h"
 
 #include "profiler.h"
 #include "commontrace.h"
@@ -374,12 +375,17 @@ HRESULT STDMETHODCALLTYPE Profiler::Initialize(
         // Fetching the Configuration and setup logging.
         //
 
-        m_loggerConfig = ProfilerManager::Instance().FetchLoggerConfig(this);
-        this->SetupLogging(m_loggerConfig);
+        {
+            ConfigurationManager cm(LOG());
+
+            m_loggerConfig = cm.FetchLoggerConfig();
+            this->SetupLogging(m_loggerConfig);
 
-        m_traceLogConfig =
-            ProfilerManager::Instance().FetchTraceLogConfig(this);
-        m_profConfig = ProfilerManager::Instance().FetchProfilerConfig(this);
+            m_traceLogConfig = cm.FetchTraceLogConfig();
+            m_profConfig = cm.FetchProfilerConfig();
+
+            cm.CheckUnused();
+        }
 
         //
         // Applying the Configuration to the TraceLog.
index 6aa0ee33a8ae5a3255daaa58557db566d5fdc94e..53660e3a18a5e845f531aa7b7534dbcf88ff63a0 100644 (file)
@@ -48,33 +48,6 @@ ProfilerManager::~ProfilerManager()
     assert(g_pProfilerObject == nullptr);
 }
 
-template <typename T>
-T ProfilerManager::FetchConfig(const Profiler *pProfiler)
-{
-    // Ensure method is called for the global profiler instance;
-    assert(g_pProfilerObject == pProfiler);
-
-    T config;
-
-    // Currently only environment is used as source of the configuration.
-    EnvironmentConfigProvider().FetchConfig(config);
-
-    config.Validate();
-
-    auto warnings = config.Verify();
-    if (!warnings.empty())
-    {
-        auto logLine = pProfiler->LOG().Warn();
-        logLine << "Some errors detected in " << config.Name() << ":";
-        for (const auto &warning : warnings)
-        {
-            logLine << "\n\t\t" << warning;
-        }
-    }
-
-    return config;
-}
-
 bool ProfilerManager::IsProfilerRegistered(
     const Profiler *pProfiler) const noexcept
 {
@@ -103,21 +76,6 @@ void ProfilerManager::UnregisterProfiler(const Profiler *pProfiler)
     }
 }
 
-LoggerConfig ProfilerManager::FetchLoggerConfig(const Profiler *pProfiler)
-{
-    return FetchConfig<LoggerConfig>(pProfiler);
-}
-
-TraceLogConfig ProfilerManager::FetchTraceLogConfig(const Profiler *pProfiler)
-{
-    return FetchConfig<TraceLogConfig>(pProfiler);
-}
-
-ProfilerConfig ProfilerManager::FetchProfilerConfig(const Profiler *pProfiler)
-{
-    return FetchConfig<ProfilerConfig>(pProfiler);
-}
-
 void ProfilerManager::DllDetachShutdown() noexcept
 {
     //
index ba8d9a88ee077de6687de5eadcc616172882bffe..8d4173e6b36942d549c2f74ae24df85d48d0792d 100644 (file)
@@ -37,9 +37,6 @@ private:
     // Singleton can be destroyed only during process termination.
     ~ProfilerManager();
 
-    template<typename T>
-    T FetchConfig(const Profiler *pProfiler);
-
 public:
     // Check if the Profiler is registered in the Profiler Manager.
     bool IsProfilerRegistered(const Profiler *pProfiler) const noexcept;
@@ -50,15 +47,6 @@ public:
     // Remove the Profiler from the Profiler Manager.
     void UnregisterProfiler(const Profiler *pProfiler);
 
-    // Get logger configuration from the Global Area for the specified Profiler.
-    LoggerConfig FetchLoggerConfig(const Profiler *pProfiler);
-
-    // Get trace configuration from the Global Area for the specified Profiler.
-    TraceLogConfig FetchTraceLogConfig(const Profiler *pProfiler);
-
-    // Get configuration from the Global Area for the specified Profiler.
-    ProfilerConfig FetchProfilerConfig(const Profiler *pProfiler);
-
     // This function is called when DLL is detached and we should perform
     // cleanup of the Global Area.
     void DllDetachShutdown() noexcept;