Skip to content

Commit c547f45

Browse files
authored
Merge pull request microsoft#295 from microsoft/develop
Merge develop to main for v1.0.33 release
2 parents d5a073b + 8f0e1fd commit c547f45

39 files changed

+469
-166
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ Please format the changes as follows:
77
+ BugFixes:
88
+ Updates:
99

10+
## 1.0.33
11+
+ New:
12+
+ BugFixes:
13+
+ Fix GetILFunctionBody call for RawProfilerHook during OnModuleLoadFinished
14+
+ Fix building with MSVC v14.28 by moving .h headers from ClCompile to ClInclude
15+
+ Fix RawProfilerHook QI to match CLR behavior (cast interfaces downward)
16+
+ Updates:
17+
1018
# 1.0.32
1119
+ New:
1220
+ Support loading and initializing Instrumentation Methods on profiler attach.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any addi
2424

2525
Active development is happening in `develop` branch.
2626

27-
Last released version is in `master` branch.
27+
Last released version is in `main` branch.
2828

2929
## Submitting your Pull Request:
3030

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Develop Branch: [![Build Status](https://dev.azure.com/ms/CLRInstrumentationEngine/_apis/build/status/CI-Yaml?branchName=develop)](https://dev.azure.com/ms/CLRInstrumentationEngine/_build/latest?definitionId=275&branchName=develop)
44

5-
Master Branch: [![Build Status](https://devdiv.visualstudio.com/DevDiv/_apis/build/status/ClrInstrumentationEngine/GitHub/ClrInstrumentationEngine-Signed-Yaml?branchName=master)](https://devdiv.visualstudio.com/DevDiv/_build/latest?definitionId=11311&branchName=master)
5+
Main Branch: [![Build Status](https://devdiv.visualstudio.com/DevDiv/_apis/build/status/ClrInstrumentationEngine/GitHub/ClrInstrumentationEngine-Signed-Yaml?branchName=main)](https://devdiv.visualstudio.com/DevDiv/_build/latest?definitionId=11311&branchName=main)
66

77
## Overview
88

@@ -19,6 +19,7 @@ The CLR Instrumentation Engine is a profiler implementation and is enabled and c
1919
* [Getting Started](docs/getting_started.md) for details on how use the CLR Instrumentation Engine.
2020
* [Environment Variables](docs/environment_variables.md)
2121
* [Configure Instrumentation Methods](docs/configuration.md)
22+
* [CLRIE Releases](docs/releases.md)
2223

2324
## Contributing
2425

build/SiteExtensions.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License. -->
24
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
35
<PropertyGroup>
46
<PrepareForRunDependsOn>$(PrepareForRunDependsOn);GeneratePrivateXdts;ZipFiles</PrepareForRunDependsOn>

build/Version.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
-->
1313
<SemanticVersionMajor>1</SemanticVersionMajor>
1414
<SemanticVersionMinor>0</SemanticVersionMinor>
15-
<SemanticVersionPatch>32</SemanticVersionPatch>
15+
<SemanticVersionPatch>33</SemanticVersionPatch>
1616

1717
<FileVersionMajor>15</FileVersionMajor>
1818
<FileVersionMinor>1</FileVersionMinor>
@@ -38,7 +38,7 @@
3838
Update for every public release.
3939
Format is YYYY-MM-DD
4040
-->
41-
<SemanticVersionDate>2020-01-31</SemanticVersionDate>
41+
<SemanticVersionDate>2020-04-03</SemanticVersionDate>
4242

4343
<!--
4444
Build version is used to distinguish internally built NuGet packages.

build/yaml/pipelines/codeanalysis.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ schedules:
1515
displayName: Weekly Static Analysis
1616
branches:
1717
include:
18-
- master
18+
- main
1919

2020
variables:
2121
TeamName: ClrInstrumentationEngine

build/yaml/steps/microbuild/codesignverify.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
14
# Step Template: MicroBuild Signing and Verification
25

36
parameters:

docs/environment_variables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ MicrosoftInstrumentationEngine_DebugWait|1|Suspends the process until the debugg
4343
MicrosoftInstrumentationEngine_FileLogPath|"[FULL PATH TO LOGGING FILE]"|File to host the event logs. This requires LogLevel to be set.
4444
MicrosoftInstrumentationEngine_DisableCodeSignatureValidation|1|Disables signature validation
4545
MicrosoftInstrumentationEngine_IsPreinstalled|1|The preinstalled site extension for CLRIE sets this to help users know that the applicationHost.xdt file for the preinstalled extension was applied. The Application Insights private site extension won't set this.
46+
MicrosoftInstrumentationEngine_LatestPath|D:\Program Files (x86)\SiteExtensions\InstrumentationEngine\\[LATEST VERSION]|This environment variable is available in Azure App Service v91+ and allows private site extensions to reference the path to the latest preinstalled InstrumentationEngine.
4647

4748
## Raw Profiler Hook
4849

docs/getting_started.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ The Instrumentation Engine supports both x86 and x64 configurations.
6565

6666
See [CLRIE in Azure](scenarios/azure.md) for details about leveraging CLRIE on supported Azure platforms and products.
6767

68-
#### Required Dlls
69-
The Instrumentation Engine supports both x86 and x64 configurations.
70-
71-
* MicrosoftInstrumentationEngine_x86.dll
72-
* MicrosoftInstrumentationEngine_x64.dll
73-
7468
### How do I write an Instrumentation Method?
7569

7670
A simple example of an InstrumentationMethod can be found in

docs/release_process.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Releasing the CLR Instrumentation Engine
22

3-
Release occurs from the Master branch. Please notify clrieowners@microsoft.com to initiate the release process.
3+
Release occurs from the `main` branch. Please notify clrieowners@microsoft.com to initiate the release process.
44

55
## Microsoft Internal Process
66

@@ -16,8 +16,8 @@ automatically publishes artifacts to the internal NuGet feed with a preview vers
1616
Based on the changes and targeted platform releases, impacted scenarios and partner teams should be involved in testing for regressions.
1717

1818
### Release Phase
19-
1. Once testing completes, PR to merge develop branch to master branch
20-
2. Manually run the [Master-Signed](https://devdiv.visualstudio.com/DevDiv/_build/index?context=allDefinitions&path=%5CClrInstrumentationEngine%5CGitHub&definitionId=10055&_a=completed) build to create release artifacts
19+
1. Once testing completes, PR to merge develop branch to main branch
20+
2. Manually run the [Signed](https://devdiv.visualstudio.com/DevDiv/_build?definitionId=11311) build to create release artifacts
2121
3. Manually run the
2222
[CLR Instrumentation Engine Release](https://devdiv.visualstudio.com/DevDiv/_releases2?view=all&definitionId=901)
2323
pipeline which publishes artifacts with release version (eg. 1.0.15)

docs/releases.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# CLR Instrumentation Engine Releases
2+
3+
The below links provide the latest released packages for CLRIE. Some Azure platforms already support CLRIE as a first party extension. (see [here](scenarios/azure.md) for details).
4+
5+
## Current Release - 1.0.31
6+
7+
|Platform|Installer|Merge Module|
8+
|-|-|-|
9+
|Windows (x64)|[Download](https://aka.ms/clrie/release/1.0.31/instrumentationengine.installer_x64.1.0.31.msi)|[Download](https://aka.ms/clrie/release/1.0.31/instrumentationengine.module_x64.1.0.31.msm)
10+
|Windows (x86)|[Download](https://aka.ms/clrie/release/1.0.31/instrumentationengine.installer_x86.1.0.31.msi)|[Download](https://aka.ms/clrie/release/1.0.31/instrumentationengine.module_x86.1.0.31.msm)

docs/scenarios/azure.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Details for CLR Instrumentation Engine environment variables can be found at [En
4747

4848
#### As a Preinstalled Site Extension
4949

50+
##### Via App Setting
5051
In order to enable the CLR Instrumentation Engine preinstalled site extension, go to your Azure App Service resource in the Azure Portal and
5152
add the below setting to the Application Settings (Currently there's a bug where different components set the key with different casings and
5253
producing 409 conflict errors):
@@ -60,10 +61,49 @@ Please see [Kudu Site Extensions](https://github.com/projectkudu/kudu/wiki/Azure
6061

6162
Please note that applicationHost.xdt files for enabled preinstalled site extension are processed before any private site extension.
6263

64+
##### Via ApplicationHost.XDT
65+
66+
If you ship a private site extension and want to use Instrumentation Engine cooperatively, the following environment variable in Azure App Service will be enabled in ANT91 (2020, late-Oct/early-Nov):
67+
68+
`MicrosoftInstrumentationEngine_LatestPath` = `D:\Program Files (x86)\SiteExtensions\InstrumentationEngine\[LATEST VERSION]`
69+
70+
Where [LATEST VERSION] represents the latest available version of the InstrumentationEngine preinstalled site extension.
71+
72+
In the private site extension's applicationHost.xdt, you can leverage this environment variable in the following way, note that each of these are set as `InsertIfMissing` to avoid conflicts if the InstrumentationEngine preinstalled site extension is enabled.
73+
74+
```
75+
<!-- .NET Framework -->
76+
<add name="COR_ENABLE_PROFILING" value="1"
77+
xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
78+
<add name="COR_PROFILER" value="{324F817A-7420-4E6D-B3C1-143FBED6D855}"
79+
xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
80+
<add name="COR_PROFILER_PATH_64" value="%MicrosoftInstrumentationEngine_LatestPath%\Instrumentation64\MicrosoftInstrumentationEngine_x64.dll"
81+
xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
82+
<add name="COR_PROFILER_PATH_32" value="%MicrosoftInstrumentationEngine_LatestPath%\Instrumentation32\MicrosoftInstrumentationEngine_x86.dll"
83+
xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
84+
85+
<!-- .NET Core -->
86+
<add name="CORECLR_ENABLE_PROFILING" value="1"
87+
xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
88+
<add name="CORECLR_PROFILER" value="{324F817A-7420-4E6D-B3C1-143FBED6D855}"
89+
xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
90+
<add name="CORECLR_PROFILER_PATH_64" value="%MicrosoftInstrumentationEngine_LatestPath%\Instrumentation64\MicrosoftInstrumentationEngine_x64.dll"
91+
xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
92+
<add name="CORECLR_PROFILER_PATH_32" value="%MicrosoftInstrumentationEngine_LatestPath%\Instrumentation32\MicrosoftInstrumentationEngine_x86.dll"
93+
xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
94+
```
95+
96+
We also recommend enabling Error logging. These will report to D:\Home\LogFiles\EventLog.xml.
97+
98+
```
99+
<add name="MicrosoftInstrumentationEngine_LogLevel" value="Errors"
100+
xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
101+
```
102+
63103
#### As a Private Site Extension
64104

65-
The CLR Instrumentation Engine is not shipped as a standalone private site extension. Instead it is available as part of the Application
66-
Insights private site extension and will be enabled as part of the Application Insights applicationHost.xdt file.
105+
The CLR Instrumentation Engine is not shipped as a standalone private site extension. Instead it is currently available as part of the Application
106+
Insights **private** site extension and will be enabled as part of the Application Insights applicationHost.xdt file.
67107

68108
#### Configuring your Instrumentation Method
69109

docs/troubleshooting.md

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
11
# Troubleshooting
22

3-
## Azure
3+
## Azure Scenarios
44

55
See [CLRIE in Azure](scenarios/azure.md).
66

7-
## Diagnosing Issues
7+
## Mitigation
8+
9+
When an issue occurs in production, the first step is to mitigate it so the application continues to run. A common cause of problems are from updates to either CLRIE or to one of the Instrumentation Method client that introduces potential conflicts with another client or incompatiblities with the app.
10+
11+
### Remove CLRIE
12+
13+
The most direct way to stop CLRIE and all Instrumentation Methods is to remove the ICorProfiler environment variables that are being applied to the process (along with a process restart). This may either require updating applicationHost.xdt files, changing the `InstrumentationEngine_EXTENSION_VERSION` Application Setting, or modifying registry keys. Without the ICorProfiler environment variables, the process effectively removes CLRIE & all IMs that are currently running. If the application without CLRIE is still encountering errors, then the issue is something the app owner will need to address.
14+
15+
Alternatively, if the user cannot modify the ICorProfiler environment variable, they may be able to at least remove the dlls which are pointed to by the COR_PROFILER_PATH/CORECLR_PROFILER_PATH environment variables. A process restart will still be required.
16+
17+
For Azure VM/VMSS, the Visual Studio Production Diagnostics team ships a CLRIE-hosted MSI in the Microsoft.Insights.VMDiagnosticsSettings extension (Type: Microsoft.Azure.Diagnostics.IaaSDiagnostics). This extension will apply the ICorProfiler variables to the registry for IIS at `HKLM\SYSTEM\CurrentControlSet\Services\W3SVC` and `HKLM\SYSTEM\CurrentControlSet\Services\WAS`. In order to disable CLRIE, you will need to remove the VM extension entirely. You can do so either from the Azure Portal or via Azure PowerShell cmdlet `Remove-AzVMExtension`.
18+
19+
### Remove Instrumentation Methods
20+
21+
Currently this feature is not supported. We could potentially create a tool that supports an allow/block list of InstrumentationMethods that CLRIE uses to ignore environment variables on startup. Concerns of this implementation involve security implications of file-on-disk or require privileged user access.
22+
23+
## Investigations and Diagnosing Issues
24+
25+
After mitigation and having the application back up and running, the next step is to figure out who the culprit is that produced the error. We recommend using a test environment rather than testing in production to prvent giving customers a very negative experience.
26+
27+
### Enable CLRIE only
28+
29+
It is recommended to just enable CLRIE without any Instrumentation Methods to ensure there's no regression in CLRIE's steady-state behavior. This is especially important if CLRIE was recently updated because regressions or incomptibilities might be introduced for the current application. We expect these issues to be rare as CLRIE is tested on a variety of platforms and apps and features are added incrementally with emphasis on supporting backwards compatibility.
30+
31+
### Enable Instrumentation Methods (one at a time)
32+
33+
Profilers are the main feature providers and so should be the focal point of investigation. Instrumentation Methods are loaded by CLRIE via environment variables that have the prefix `MicrosoftInstrumentationEngine_ConfigPath64_` or `MicrosoftInstrumentationEngine_ConfigPath32_` so app owners can easily determine what Instrumentation Methods are running in their process.
34+
35+
The user should enable each Instrumentation Method by itself and see if the application runs into the issue. This can confirm directly whether an Instrumentation Method by itself is causing the issue. This does not confirm if the Instrumentation Method is causing the issue or if it relies on behavior from CLRIE that is broken or has bugs.
36+
37+
The more complex scenarios occur when multiple Instrumentation Methods are running as their behaviors may conflict without either parties being aware. For these scenarios it is difficult to find a sole owner. We **recommend** starting a discussion by posting a GitHub issue with tags for each of the involved Instrumentation Methods products. Private discussions or discussions with sensitive information can be done via email or other channels once the involved parties are established.
838

939
### Enable Instrumentation Engine Logging
1040

1141
A quick way to see if any errors are occurring in the CLR Instrumentation Engine or Instrumentation Methods is to enable logging. Please see
12-
[Environment Variables](environment_variables.md) for detailed information on the allowed values to set.
42+
[Environment Variables](environment_variables.md) for detailed information on the allowed values to set. For Instrumentation Method authors, we recommend enabling the "Dumps" log level which shows the IL transformations.
1343

1444
#### Event Log
1545

@@ -25,11 +55,31 @@ If `MicrosoftInstrumentationEngine_FileLogPath` is set along with `MicrosoftInst
2555
occur. If the FilePath is set to a directory, then an automatically generated `%TEMP%\ProfilerLog_[PID].txt` file is used, where [PID]
2656
represents the process id and the %TEMP% variable is evaluated against the user account running the process.
2757

58+
#### Instrumentation Method Logging
59+
60+
CLRIE's logging infrastructure is outlined [here](./logging.md). During ICorProfilerCallback::Initialize(), InstrumentationMethods can obtain an InstrumentationMethod-specific logger via `IProfilerManager::GetLoggingInstance()` which will prepend log messages with the `[IM:GUID]`. In addition, IMs can log at a different log level from CLRIE by setting an additional environment variable, allowing IMs to filter out CLRIE or other IM logs. See [ProfilerManagerForInstrumentationMethod](./logging.md#profilermanagerforinstrumentationmethod-hcpp) section for more details.
61+
62+
Log parsing or an event collector can utilize these patterns to track InstrumentationMethod behaviors and potentially help diagnose issues.
63+
2864
### Debugging the Instrumentation Engine
2965

30-
When using a local build of the Instrumentation Engine, you will need to disable signing validations and checks by setting the
66+
When using a local build of the Instrumentation Engine or testing your InstrumentationMethod, you will need to disable signing validations and checks by setting the
3167
`MicrosoftInstrumentationEngine_DisableCodeSignatureValidation` to 1.
3268

33-
Since the CLR Instrumentation Engine initializes on process start, in order for breakpoints in the initialization logic to hit, you will need
34-
to set the `MicrosoftInstrumentationEngine_DebugWait` environment variable with the value 1. This will cause the Instrumentation Engine to wait
35-
on startup for a debugger attach event.
69+
Since the CLR Instrumentation Engine initializes on process start, in order for breakpoints in the initialization logic to hit, you will need to set the `MicrosoftInstrumentationEngine_DebugWait` environment variable with the value of 1. This will cause the Instrumentation Engine to wait on startup for a debugger attach event.
70+
71+
#### Breakpoint Locations
72+
73+
The best place to start debugging is in [ProfilerManager.cpp](../src/InstrumentationEngine/ProfilerManager.cpp). ProfilerManager is CLRIE's ICorProfiler implementation which gets the first-chance callback during profiling. It controls setting up InstrumentationMethods and forwarding ICorProfiler callback events to them.
74+
75+
Setting a breakpoint inside `CProfilerManager::Initialize()` provides the earliest point where CLRIE is beginning to initialize in the process.
76+
77+
`CProfilerManager::AddInstrumentationMethod()` provides the logic for loading each InstrumentationMethod and calling Initialize() on them.
78+
79+
CLRIE's main purpose is to coordinate instrumentation, so callbacks such as `CProfilerManager::JITCompilationStarted()` and `CProfilerManager::GetReJITParameters()` are also good places to inspect.
80+
81+
#### Loading Symbols for CLR/.NET modules
82+
83+
In order to debug issues, it is pertinent to have symbols (ie. pdb files) for the modules/assemblies that the process is using. This will aid in investigating IL issues at the point of failure (eg. ProgramInvalidException).
84+
85+
If you are debugging with Visual Studio, make sure you have "Microsoft Symbol Server" enabled for symbol loading in *Tools > Options > Debugging > Symbols > Symbol file locations*. Symbols for both managed modules such as clr.dll and native modules like kernel32.dll are available to be loaded.

src/ExtensionsCommon/ExtensionsCommon.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<ClInclude Include="FormatMessage.h" />
3838
<ClInclude Include="ICodeInjector.h" />
3939
<ClInclude Include="ICodeInjectorFwd.h" />
40+
<ClInclude Include="INativeMethodsStubs.h" />
4041
<ClInclude Include="InstructionDefineExtensions.h" />
4142
<ClInclude Include="InstrumentationEngineDefs.h" />
4243
<ClInclude Include="InstrumentationEngineInfraPointerDefs.h" />
@@ -75,7 +76,6 @@
7576
<ClCompile Include="DecorationCallbacksInfoReader.cpp" />
7677
<ClCompile Include="DecorationCallbacksInfoStaticReader.cpp" />
7778
<ClCompile Include="Exception.cpp" />
78-
<ClCompile Include="INativeMethodsStubs.h" />
7979
<ClCompile Include="InstrumentationMethodBase.cpp" />
8080
<ClCompile Include="InteropInstrumentationHandler.cpp" />
8181
<ClCompile Include="LoadArgumentsHelper.cpp" />

src/InstrumentationEngine.Attach/InstrumentationEngine.Attach.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<Project>
2-
<!-- Copyright (c) Microsoft Corporation. All rights reserved.
1+
<!-- Copyright (c) Microsoft Corporation. All rights reserved.
32
Licensed under the MIT License. -->
3+
<Project>
44
<PropertyGroup>
55
<SubComponent>Tools\Attach</SubComponent>
66
</PropertyGroup>

src/InstrumentationEngine.Lib/ConfigurationLoader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ HRESULT CConfigurationLoaderHelper::ProcessInstrumentationMethodNode(_In_ BSTR b
219219
#else
220220

221221
#include <string.h>
222+
#include <iconv.h>
222223

223224
HRESULT CConfigurationLoaderHelper::LoadConfiguration(_In_ BSTR bstrConfigPath, _In_ std::vector<CInstrumentationMethod*>& methods)
224225
{

0 commit comments

Comments
 (0)