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

chore: Address profiler warnings #2545

Merged
merged 5 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/Agent/NewRelic/Home/Home.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</Target>

<ItemGroup>
<PackageReference Include="NewRelic.Agent.Internal.Profiler" Version="10.24.0.10"/>
<PackageReference Include="NewRelic.Agent.Internal.Profiler" Version="10.25.1.7"/>
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion src/Agent/NewRelic/Profiler/Common/CorStandIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#pragma warning(push)
#pragma warning(disable : 4458)
#pragma warning(disable: 4458)
chynesNR marked this conversation as resolved.
Show resolved Hide resolved
#pragma warning(disable: 26495)
#include <corhlpr.h>
#pragma warning(pop)
32 changes: 16 additions & 16 deletions src/Agent/NewRelic/Profiler/Configuration/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,24 @@ namespace NewRelic { namespace Profiler { namespace Configuration {
, _ignoreList(new IgnoreInstrumentationList())
{
try {
rapidxml::xml_document<xchar_t> globalNewRelicConfigurationDocument;
globalNewRelicConfigurationDocument.parse<rapidxml::parse_trim_whitespace | rapidxml::parse_normalize_whitespace>(const_cast<xchar_t*>(globalNewRelicConfiguration.c_str()));
auto globalNewRelicConfigurationDocument = std::make_shared<rapidxml::xml_document<xchar_t>>();
globalNewRelicConfigurationDocument->parse<rapidxml::parse_trim_whitespace | rapidxml::parse_normalize_whitespace>(const_cast<xchar_t*>(globalNewRelicConfiguration.c_str()));

auto globalNewRelicConfigurationNode = GetConfigurationNode(globalNewRelicConfigurationDocument);
auto globalNewRelicConfigurationNode = GetConfigurationNode(globalNewRelicConfigurationDocument);
if (globalNewRelicConfigurationNode == nullptr)
{
LogError(L"Unable to locate configuration node in the global newrelic.config file.");
throw ConfigurationException();
}

auto appliedNewRelicConfigurationNode = globalNewRelicConfigurationNode;
auto localNewRelicConfigurationDocument = std::make_shared<rapidxml::xml_document<xchar_t>>();

if (localNewRelicConfiguration.second)
{
try
{
rapidxml::xml_document<xchar_t> localNewRelicConfigurationDocument;
chynesNR marked this conversation as resolved.
Show resolved Hide resolved
localNewRelicConfigurationDocument.parse<rapidxml::parse_trim_whitespace | rapidxml::parse_normalize_whitespace>(const_cast<xchar_t*>(localNewRelicConfiguration.first.c_str()));
localNewRelicConfigurationDocument->parse<rapidxml::parse_trim_whitespace | rapidxml::parse_normalize_whitespace>(const_cast<xchar_t*>(localNewRelicConfiguration.first.c_str()));

auto localNewRelicConfigurationNode = GetConfigurationNode(localNewRelicConfigurationDocument);
if (localNewRelicConfigurationNode == nullptr)
Expand Down Expand Up @@ -92,7 +92,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration {
SetLogLevel(appliedNewRelicConfigurationNode);
SetInstrumentationData(appliedNewRelicConfigurationNode);
SetApplicationPools(appliedNewRelicConfigurationNode);

} catch (const rapidxml::parse_error& exception) {
// We log two separate error messages here because sometimes the logging macros hang when
// logging the "where" contents
Expand Down Expand Up @@ -196,15 +196,15 @@ namespace NewRelic { namespace Profiler { namespace Configuration {
return _logLevel;
}

bool GetConsoleLogging()
bool GetConsoleLogging() const
{
return _consoleLogging;
}
bool GetLoggingEnabled()
bool GetLoggingEnabled() const
{
return _loggingEnabled;
}
IgnoreInstrumentationListPtr GetIgnoreInstrumentationList()
IgnoreInstrumentationListPtr GetIgnoreInstrumentationList() const
{
return _ignoreList;
}
Expand All @@ -224,9 +224,9 @@ namespace NewRelic { namespace Profiler { namespace Configuration {
std::shared_ptr<NewRelic::Profiler::Logger::IFileDestinationSystemCalls> _systemCalls;
IgnoreInstrumentationListPtr _ignoreList;

rapidxml::xml_node<xchar_t>* GetConfigurationNode(const rapidxml::xml_document<xchar_t>& document)
rapidxml::xml_node<xchar_t>* GetConfigurationNode(const std::shared_ptr<rapidxml::xml_document<xchar_t>> document)
{
auto configurationNode = document.first_node(_X("configuration"), 0, false);
auto configurationNode = document->first_node(_X("configuration"), 0, false);
if (configurationNode == nullptr) {
return nullptr;
}
Expand Down Expand Up @@ -294,7 +294,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration {
_logLevel = TryParseLogLevel(level);
}

Logger::Level TryParseLogLevel(const xstring_t& logText)
Logger::Level TryParseLogLevel(const xstring_t& logText) const
{
if (Strings::AreEqualCaseInsensitive(logText, _X("off"))) {
return Logger::Level::LEVEL_ERROR;
Expand Down Expand Up @@ -423,8 +423,8 @@ namespace NewRelic { namespace Profiler { namespace Configuration {
if (applicationConfiguration.empty())
return;

rapidxml::xml_document<xchar_t> document;
document.parse<rapidxml::parse_trim_whitespace | rapidxml::parse_normalize_whitespace>(const_cast<xchar_t*>(applicationConfiguration.c_str()));
auto document = std::make_shared<rapidxml::xml_document<xchar_t>>();
document->parse<rapidxml::parse_trim_whitespace | rapidxml::parse_normalize_whitespace>(const_cast<xchar_t*>(applicationConfiguration.c_str()));
auto configurationNode = GetConfigurationNode(document);

auto appSettingsNode = configurationNode->first_node(_X("appSettings"), 0, false);
Expand Down Expand Up @@ -468,7 +468,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration {
static bool IsProcessInProcessList(const ProcessesPtr& processes, const xstring_t& processName)
{
// check the processes loaded from configuration
for (auto validProcessName : *processes) {
for (auto& validProcessName : *processes) {
if (Strings::EndsWith(processName, validProcessName)) {
return true;
}
Expand Down Expand Up @@ -498,7 +498,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration {
return isIis;
}

bool ShouldInstrumentApplicationPool(const xstring_t& appPoolId)
bool ShouldInstrumentApplicationPool(const xstring_t& appPoolId) const
{
if (ApplicationPoolIsOnBlackList(appPoolId, _applicationPoolsBlackList)) {
LogInfo(_X("This application pool (") + appPoolId + _X(") is explicitly configured to NOT be instrumented."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration
}

private:
bool Matches(xstring_t assembly, xstring_t className)
bool Matches(xstring_t assembly, xstring_t className) const
{
if (!Strings::AreEqualCaseInsensitive(AssemblyName, assembly))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration
, _foundServerlessInstrumentationPoint(false)
{
// pull instrumentation points from every xml string
for (auto instrumentationXml : *instrumentationXmls)
for (auto& instrumentationXml : *instrumentationXmls)
{
try
{
Expand Down Expand Up @@ -64,13 +64,13 @@ namespace NewRelic { namespace Profiler { namespace Configuration
, _systemCalls(nullptr)
, _foundServerlessInstrumentationPoint(false)
{
for (auto instrumentationPoint : *instrumentationPoints)
for (auto& instrumentationPoint : *instrumentationPoints)
{
AddInstrumentationPointToCollectionsIfNotIgnored(instrumentationPoint);
}
}

uint16_t GetInvalidFileCount()
uint16_t GetInvalidFileCount() const
{
return _invalidFileCount;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration
// We may have multiple matching instrumentation points that target different assembly versions. See if we can find one that meets
// the version requirements
AssemblyVersion foundVersion(function->GetAssemblyProps());
for (auto instPoint : instPoints)
for (auto& instPoint : instPoints)
{
if ((instPoint->MinVersion != nullptr) && (foundVersion < *instPoint->MinVersion))
{
Expand Down Expand Up @@ -228,9 +228,9 @@ namespace NewRelic { namespace Profiler { namespace Configuration

void GetInstrumentationPoints(xstring_t instrumentationXml)
{
rapidxml::xml_document<xchar_t> document;
document.parse<rapidxml::parse_trim_whitespace | rapidxml::parse_normalize_whitespace>(const_cast<xchar_t*>(instrumentationXml.c_str()));
auto extensionNode = document.first_node(_X("extension"), 0, false);
auto document = std::make_shared<rapidxml::xml_document<xchar_t>>();
document->parse<rapidxml::parse_trim_whitespace | rapidxml::parse_normalize_whitespace>(const_cast<xchar_t*>(instrumentationXml.c_str()));
auto extensionNode = document->first_node(_X("extension"), 0, false);
if (extensionNode == nullptr)
{
LogWarn(L"extension node not found in instrumentation file. Please validate your instrumentation files against extensions/extension.xsd or contact New Relic support.");
Expand Down Expand Up @@ -397,7 +397,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration
// if the ClassName includes multiple classes, we have to split this into multiple instrumentation points
auto instrumentationPoints = SplitInstrumentationPointsOnClassNames(instrumentationPoint);

for (auto iPoint : instrumentationPoints) {
for (auto& iPoint : instrumentationPoints) {

// finally add the new instrumentation point(s) to our set of instrumentation points
// Note that there may be "duplicated" instrumentation points that target different assembly versions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration
ParametersMatch(other);
}

xstring_t ToString()
xstring_t ToString() const
{
if (Parameters == nullptr)
{
Expand All @@ -63,7 +63,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration
}
}

xstring_t GetMatchKey()
xstring_t GetMatchKey() const
{
return Parameters == nullptr
? GetMatchKey(AssemblyName, ClassName, MethodName)
Expand All @@ -82,7 +82,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration


private:
bool ParametersMatch(const InstrumentationPoint& other)
bool ParametersMatch(const InstrumentationPoint& other) const
{
// nullptr means no parameters attribute was supplied in configuration, suggesting that we should instrument all overloads
if (this->Parameters == nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,12 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter
// shift the original clauses up to the correct
for (uint32_t i = 0; i < _originalExceptionClauseCount; ++i)
{
auto clause = _exceptionClauses[i];
auto& clause = _exceptionClauses[i];
clause->ShiftOffsets(userCodeOffset);
}

// append the clauses
for (auto clause : _exceptionClauses)
for (auto& clause : _exceptionClauses)
{
auto clauseBytes = clause->GetBytes();
bytes->insert(bytes->end(), clauseBytes->begin(), clauseBytes->end());
Expand All @@ -276,7 +276,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter
return bytes;
}

uint32_t GetOriginalExceptionClauseCount()
uint32_t GetOriginalExceptionClauseCount() const
{
return _originalExceptionClauseCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter
_instructions->Append(CEE_NEWARR, _X("[mscorlib]System.Object"));
uint32_t index = 0;

for (auto func : elementLoadLambdas)
for (auto& func : elementLoadLambdas)
{
auto nextIndex = index++;
// get an extra copy of the array (it will be popped off the stack each time we add an element to it)
Expand Down
6 changes: 3 additions & 3 deletions src/Agent/NewRelic/Profiler/MethodRewriter/InstructionSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter

void AppendTryEnd()
{
auto exception = _exceptionStack.top();
auto& exception = _exceptionStack.top();
if (exception->_tryLength != 0)
{
LogError(L"Attempted to set try close on the same exception twice.");
Expand All @@ -414,7 +414,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter

void AppendCatchStart(uint32_t typeToken)
{
auto exception = _exceptionStack.top();
auto& exception = _exceptionStack.top();
if (exception->_handlerOffset != 0)
{
LogError(L"Attempted to set catch start on the same exception twice.");
Expand All @@ -439,7 +439,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter

void AppendCatchEnd()
{
auto exception = _exceptionStack.top();
auto& exception = _exceptionStack.top();
if (exception->_handlerLength != 0)
{
LogError(L"Attempted to set catch end on the same exception twice.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter
public:
InstrumentFunctionManipulator(IFunctionPtr function, InstrumentationSettingsPtr instrumentationSettings) :
FunctionManipulator(function),
_instrumentationSettings(instrumentationSettings)
_instrumentationSettings(instrumentationSettings),
_userExceptionLocalIndex(0),
_resultLocalIndex(0),
_tracerLocalIndex(0)
{
if (_function->Preprocess()) {
Initialize();
Expand Down Expand Up @@ -228,4 +231,4 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter
_resultLocalIndex = AppendReturnTypeLocal(_newLocalVariablesSignature, _methodSignature);
}
};
}}}
}}}
4 changes: 2 additions & 2 deletions src/Agent/NewRelic/Profiler/MethodRewriter/MethodRewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter {

auto instrumentationPoints = _instrumentationConfiguration->GetInstrumentationPoints();

for (auto instrumentationPoint : *instrumentationPoints) {
for (auto& instrumentationPoint : *instrumentationPoints) {

_instrumentedAssemblies->emplace(instrumentationPoint->AssemblyName);
_instrumentedFunctionNames->emplace(instrumentationPoint->MethodName);
Expand All @@ -74,7 +74,7 @@ namespace NewRelic { namespace Profiler { namespace MethodRewriter {
std::set<Configuration::InstrumentationPointPtr> GetAssemblyInstrumentation(xstring_t assemblyName)
{
std::set<Configuration::InstrumentationPointPtr> set;
for (auto instrumentationPoint : *_instrumentationConfiguration->GetInstrumentationPoints().get()) {
for (auto& instrumentationPoint : *_instrumentationConfiguration->GetInstrumentationPoints().get()) {
if (assemblyName == instrumentationPoint->AssemblyName) {
set.emplace(instrumentationPoint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../Logging/Logger.h"
#include "../Sicily/Sicily.h"
#include "IModule.h"
#include "../Profiler/Exceptions.h"

namespace NewRelic { namespace Profiler { namespace ModuleInjector
{
Expand Down
Loading
Loading