blob: 182fd8d2552c1dfd23ed9c43aa1da0487c947087 [file] [log] [blame]
#pragma once
#include "utils.hpp"
#include <cstdint>
#include <memory>
#include <string_view>
namespace boot_time_monitor
{
/**
* An interface class for the Boot Manager APIs
*/
class BootManagerIface
{
public:
virtual ~BootManagerIface() = default;
/**
* Set a new checkpoint to Boot Manager
*
* @param[in] cpName - Checkpoint name
* @param[in] externalWallTime - Current epoch time in milliseconds
* @param[in] duration - Self measured duration in milliseconds
*/
virtual void setCheckpoint(std::string_view cpName,
int64_t externalWallTime, int64_t duration) = 0;
/**
* Set a new duration to Boot Manager
*
* @param[in] durName - Duration name
* @param[in] duration - Self measured duration in milliseconds
*/
virtual void setDuration(std::string_view durName, int64_t duration) = 0;
/**
* Inform Boot Manager that current reboot process has completed.
*/
virtual void notifyComplete() = 0;
/**
* Check if we are in a reboot process
*
* @return true if it's rebooting
*/
virtual bool isRebooting() = 0;
/**
* Get current checkpoints
*
* @return vector of current checkpoints
*/
virtual const std::vector<Checkpoint>& getCheckpoints() const = 0;
/**
* Get current durations
*
* @return vector of current durations
*/
virtual const std::vector<Duration>& getDurations() const = 0;
/**
* Get previous checkpoints
*
* @return vector of previous checkpoints
*/
virtual const std::vector<Checkpoint>& getPreCheckpoints() const = 0;
/**
* Get previous durations
*
* @return vector of previous durations
*/
virtual const std::vector<Duration>& getPreDurations() const = 0;
};
class BootManager : public BootManagerIface
{
public:
constexpr static std::string_view kTransitionStagePrefix = "To_";
BootManager(std::shared_ptr<UtilIface> util,
const std::shared_ptr<FileUtilIface>& cpCSV,
const std::shared_ptr<FileUtilIface>& durCSV);
void setCheckpoint(std::string_view cpName, int64_t externalWallTime,
int64_t duration) override;
void setDuration(std::string_view durName, int64_t duration) override;
void notifyComplete() override;
bool isRebooting() override;
const std::vector<Checkpoint>& getCheckpoints() const override;
const std::vector<Duration>& getDurations() const override;
const std::vector<Checkpoint>& getPreCheckpoints() const override;
const std::vector<Duration>& getPreDurations() const override;
private:
std::vector<Checkpoint> checkpoints;
std::vector<Duration> durations;
std::vector<Checkpoint> preCheckpoints;
std::vector<Duration> preDurations;
std::shared_ptr<UtilIface> util;
std::shared_ptr<FileUtilIface> cpCSV;
std::shared_ptr<FileUtilIface> durCSV;
};
} // namespace boot_time_monitor