Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rejit - Switch to shared pointer and apply same behavior for initial call #3877

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include <mach-o/getsect.h>
#endif

using namespace std::chrono_literals;

#ifdef _WIN32
#include "netfx_assembly_redirection.h"
#endif
Expand All @@ -53,6 +51,8 @@ using namespace std::chrono_literals;
return E_FAIL; \
}

using namespace std::chrono_literals;

namespace trace
{

Expand Down Expand Up @@ -788,10 +788,10 @@ HRESULT STDMETHODCALLTYPE CorProfiler::ModuleLoadFinished(ModuleID module_id, HR
// We call the function to analyze the module and request the ReJIT of integrations defined in this module.
if (tracer_integration_preprocessor != nullptr && !integration_definitions_.empty())
{
std::promise<ULONG> promise;
std::future<ULONG> future = promise.get_future();
auto promise = std::make_shared<std::promise<ULONG>>();
std::future<ULONG> future = promise->get_future();
tracer_integration_preprocessor->EnqueueRequestRejitForLoadedModules(std::vector<ModuleID>{module_id},
integration_definitions_, &promise);
integration_definitions_, promise);

// wait and get the value from the future<ULONG>
const auto status = future.wait_for(100ms);
Expand Down Expand Up @@ -1109,14 +1109,24 @@ void CorProfiler::InternalAddInstrumentation(WCHAR* id, CallTargetDefinition* it
{
if (rejit_handler != nullptr)
{
std::promise<ULONG> promise;
std::future<ULONG> future = promise.get_future();
auto promise = std::make_shared<std::promise<ULONG>>();
std::future<ULONG> future = promise->get_future();
tracer_integration_preprocessor->EnqueueRequestRejitForLoadedModules(module_ids_,
integrationDefinitions, &promise);
integrationDefinitions, promise);

// wait and get the value from the future<int>
const auto& numReJITs = future.get();
Logger::Debug("Total number of ReJIT Requested: ", numReJITs);
// wait and get the value from the future<ULONG>
const auto status = future.wait_for(100ms);

if (status != std::future_status::timeout)
{
const auto& numReJITs = future.get();
Logger::Debug("Total number of ReJIT Requested: ", numReJITs);
}
else
{
Logger::Warn("Timeout while waiting for the rejit requests to be processed. Rejit will continue "
"asynchronously, but some initial calls may not be instrumented");
}
}

integration_definitions_.reserve(integration_definitions_.size() + integrationDefinitions.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ template <class RejitRequestDefinition>
void RejitPreprocessor<RejitRequestDefinition>::EnqueueRequestRejitForLoadedModules(
const std::vector<ModuleID>& modulesVector,
const std::vector<RejitRequestDefinition>& definitions,
std::promise<ULONG>* promise)
std::shared_ptr<std::promise<ULONG>> promise)
{
if (m_rejit_handler->IsShutdownRequested())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class RejitPreprocessor

void EnqueueRequestRejitForLoadedModules(const std::vector<ModuleID>& modulesVector,
const std::vector<RejitRequestDefinition>& requests,
std::promise<ULONG>* promise);
std::shared_ptr<std::promise<ULONG>> promise);
};

/// <summary>
Expand Down
Loading