Skip to content

Commit

Permalink
Add CalculateAndReportLoadTime to reduce size of OnLoadFinal
Browse files Browse the repository at this point in the history
  • Loading branch information
indrajit96 committed Oct 15, 2024
1 parent 9802664 commit 319bc04
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/model_repository_manager/model_lifecycle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -804,16 +804,7 @@ ModelLifeCycle::OnLoadFinal(
loaded.second->state_ = ModelReadyState::READY;
loaded.second->state_reason_.clear();
#ifdef TRITON_ENABLE_METRICS
auto reporter = loaded.second->model_->MetricReporter();
const uint64_t now_ns =
std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::steady_clock::now().time_since_epoch())
.count();
uint64_t time_to_load_ns = now_ns - loaded.second->load_start_ns_;
std::chrono::duration<double> time_to_load =
std::chrono::duration_cast<std::chrono::duration<double>>(
std::chrono::nanoseconds(time_to_load_ns));
ReportModelLoadTime(reporter, time_to_load);
CalculateAndReportLoadTime(loaded.second);
#endif // TRITON_ENABLE_METRICS
auto bit = background_models_.find((uintptr_t)loaded.second);
// Check if the version model is loaded in background, if so,
Expand Down Expand Up @@ -859,6 +850,21 @@ ModelLifeCycle::OnLoadFinal(
}
}

void
ModelLifeCycle::CalculateAndReportLoadTime(ModelInfo* loaded_model_info)
{
auto reporter = loaded_model_info->model_->MetricReporter();
const uint64_t now_ns =
std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::steady_clock::now().time_since_epoch())
.count();
uint64_t time_to_load_ns = now_ns - loaded_model_info->load_start_ns_;
std::chrono::duration<double> time_to_load =
std::chrono::duration_cast<std::chrono::duration<double>>(
std::chrono::nanoseconds(time_to_load_ns));
ReportModelLoadTime(reporter, time_to_load);
}

void
ModelLifeCycle::ReportModelLoadTime(
std::shared_ptr<MetricModelReporter> reporter,
Expand Down
2 changes: 2 additions & 0 deletions src/model_repository_manager/model_lifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ class ModelLifeCycle {
ModelInfo* model_info, const bool is_update,
const std::function<void(Status)>& OnComplete,
std::shared_ptr<LoadTracker> load_tracker);
// Calculate time to load model
void ModelLifeCycle::CalculateAndReportLoadTime(ModelInfo* loaded_model_info);
// Report Load time per model metrics
void ReportModelLoadTime(
std::shared_ptr<MetricModelReporter> reporter,
Expand Down

0 comments on commit 319bc04

Please sign in to comment.