boot_manager: Adding upper bound of checkpoints and durations
Adding upper bound to avoid this daemon consumes too many memory.
Tested:
```
\# Set checkpoint and duration 102 times
boot-time-monitor[257]: [setCheckpoint] Drop incoming checkpoint due to no space left. name=S0, externalWallTime=0, duration=0
boot-time-monitor[257]: [setCheckpoint] Drop incoming checkpoint due to no space left. name=S0, externalWallTime=0, duration=0
boot-time-monitor[257]: [setDuration] Drop incoming duration due to no space left. name=S0, duration=0
boot-time-monitor[257]: [setDuration] Drop incoming duration due to no space left. name=S0, duration=0
```
Google-Bug-Id: 296787899
Google-Bug-Id: 296791279
Change-Id: Ic89bef86f8354f9fdb22458e72e85eec67195182
Signed-off-by: Michael Shen <gpgpgp@google.com>
diff --git a/src/boot_manager.cpp b/src/boot_manager.cpp
index 52903fc..79d41ea 100644
--- a/src/boot_manager.cpp
+++ b/src/boot_manager.cpp
@@ -10,6 +10,12 @@
namespace boot_time_monitor
{
+namespace
+{
+constexpr uint32_t kMaxCheckpointCnt = 100;
+constexpr uint32_t kMaxDurationCnt = 100;
+} // namespace
+
/**
* BootManager implementation class
*/
@@ -45,6 +51,13 @@
return;
}
+ if (checkpoints.size() >= kMaxCheckpointCnt)
+ {
+ fmt::print("[{}] Drop incoming checkpoint due to hit the limit. "
+ "name={}, externalWallTime={}, duration={}\n",
+ __FUNCTION__, cpName, externalWallTime, duration);
+ return;
+ }
// `boot_manager` helps to calculate the transition time from one stage to
// next stage if the user can provide a self measured duration for the
// current stage.
@@ -61,6 +74,16 @@
cpCSV->addCheckpoint(checkpoints.back().name,
checkpoints.back().wallTime,
checkpoints.back().monoTime);
+
+ if (checkpoints.size() >= kMaxCheckpointCnt)
+ {
+ fmt::print(
+ "[{}] Incoming checkpoint has `duration` so `To_{}` has been "
+ "created and added. Since the size is full so the incoming "
+ "checkpoint has been dropped\n",
+ __FUNCTION__, cpName);
+ return;
+ }
}
checkpoints.emplace_back(std::string{cpName}, wallTime, upTime.value());
@@ -78,6 +101,14 @@
return;
}
+ if (durations.size() >= kMaxDurationCnt)
+ {
+ fmt::print("[{}] Drop incoming duration due to hit the limit. "
+ "name={}, duration={}\n",
+ __FUNCTION__, durName, duration);
+ return;
+ }
+
durations.emplace_back(std::string(durName), duration);
durCSV->addDuration(durations.back().name, durations.back().duration);
}