LCOV - code coverage report
Current view: top level - common/interface - IProfiler.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 4 4
Test Date: 2026-05-08 12:58:51 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :  * If not stated otherwise in this file or this component's LICENSE file the
       3              :  * following copyright and licenses apply:
       4              :  *
       5              :  * Copyright 2026 Sky UK
       6              :  *
       7              :  * Licensed under the Apache License, Version 2.0 (the "License");
       8              :  * you may not use this file except in compliance with the License.
       9              :  * You may obtain a copy of the License at
      10              :  *
      11              :  * http://www.apache.org/licenses/LICENSE-2.0
      12              :  *
      13              :  * Unless required by applicable law or agreed to in writing, software
      14              :  * distributed under the License is distributed on an "AS IS" BASIS,
      15              :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      16              :  * See the License for the specific language governing permissions and
      17              :  * limitations under the License.
      18              :  */
      19              : 
      20              : #ifndef FIREBOLT_RIALTO_COMMON_I_PROFILER_H_
      21              : #define FIREBOLT_RIALTO_COMMON_I_PROFILER_H_
      22              : 
      23              : #include <chrono>
      24              : #include <cstdint>
      25              : #include <functional>
      26              : #include <memory>
      27              : #include <optional>
      28              : #include <string>
      29              : #include <vector>
      30              : 
      31              : namespace firebolt::rialto::common
      32              : {
      33              : class IProfiler;
      34              : 
      35              : /**
      36              :  * @brief IProfiler factory class, returns a concrete implementation of IProfiler
      37              :  */
      38              : class IProfilerFactory
      39              : {
      40              : public:
      41           32 :     IProfilerFactory() = default;
      42           32 :     virtual ~IProfilerFactory() = default;
      43              : 
      44              :     /**
      45              :      * @brief Creates a IProfilerFactory instance.
      46              :      *
      47              :      * @retval the factory instance or null on error.
      48              :      */
      49              :     static std::shared_ptr<IProfilerFactory> createFactory();
      50              : 
      51              :     /**
      52              :      * @brief Creates an IProfiler object.
      53              :      *
      54              :      * @param[in] moduleName    : The name of the module
      55              :      *
      56              :      * @retval the new profiler instance or null on error.
      57              :      */
      58              :     virtual std::unique_ptr<IProfiler> createProfiler(std::string moduleName) const = 0;
      59              : };
      60              : 
      61              : class IProfiler
      62              : {
      63              : public:
      64              :     using RecordId = std::uint64_t;
      65              :     using Clock = std::chrono::system_clock;
      66              : 
      67              :     struct Record
      68              :     {
      69              :         std::string moduleName;
      70              :         uint64_t id{0};
      71              :         std::string stage;
      72              :         std::string info;
      73              :         Clock::time_point time;
      74              :     };
      75              : 
      76           39 :     virtual ~IProfiler() = default;
      77              : 
      78              :     IProfiler(const IProfiler &) = delete;
      79              :     IProfiler &operator=(const IProfiler &) = delete;
      80              :     IProfiler(IProfiler &&) = delete;
      81              :     IProfiler &operator=(IProfiler &&) = delete;
      82              : 
      83              :     /**
      84              :      * @brief Checks if profiler is enabled.
      85              :      *
      86              :      * @retval true if profiler is enabled, false otherwise.
      87              :      */
      88              :     virtual bool isEnabled() const noexcept = 0;
      89              : 
      90              :     /**
      91              :      * @brief Creates a record for given stage.
      92              :      *
      93              :      * @param[in] stage : Stage name used for record creation
      94              :      *
      95              :      * @retval Record identifier for created record or std::nullopt.
      96              :      */
      97              :     virtual std::optional<RecordId> record(const std::string &stage) = 0;
      98              : 
      99              :     /**
     100              :      * @brief Creates a record for given stage and info.
     101              :      *
     102              :      * @param[in] stage : Stage name used for record creation
     103              :      * @param[in] info  : Additional information used for record creation
     104              :      *
     105              :      * @retval Record identifier for created record or std::nullopt.
     106              :      */
     107              :     virtual std::optional<RecordId> record(const std::string &stage, const std::string &info) = 0;
     108              : 
     109              :     /**
     110              :      * @brief Logs a record for given identifier.
     111              :      *
     112              :      * @param[in] id : Record identifier
     113              :      */
     114              :     virtual void log(RecordId id) = 0;
     115              : 
     116              :     /**
     117              :      * @brief Dumps all records into pre-configured file.
     118              :      *
     119              :      * @retval true if file is created and records are dumped, false otherwise.
     120              :      */
     121              :     virtual bool dumpToFile() const = 0;
     122              : 
     123              :     /**
     124              :      * @brief Retrieves existing records.
     125              :      *
     126              :      * @retval Snapshot copy of existing records.
     127              :      */
     128              :     virtual std::vector<Record> getRecords() const = 0;
     129              : 
     130              : protected:
     131           39 :     IProfiler() = default;
     132              : };
     133              : 
     134              : } // namespace firebolt::rialto::common
     135              : 
     136              : #endif // FIREBOLT_RIALTO_COMMON_I_PROFILER_H_
        

Generated by: LCOV version 2.0-1