microsoft / CLRInstrumentationEngine

The CLR Instrumentation Engine is a cooperation profiler that allows running multiple profiling extensions in the same process.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

is CLRIE working for x86 netfx apps?

sanikolov opened this issue · comments

Consider this simple app

class Prog {
    private static void PrintStuff(int a, int b)
    {
            System.Console.WriteLine($"{a} and {b}");
            //System.Threading.Thread.Sleep(30*1000);
    }
    public static void Main(string[] args)
    {
            PrintStuff(1,2);
    }
}

I can profile it just fine if platform is x64 but nothing happens if the platform is set to x86.
By "nothing" I mean that at a minimum I should see some output in the file pointed to by FileLogPath, see below.
Here is how I drive app profiling from a script

function make_config_mods([string]$config, [string]$bitness)
{
    [Xml]$xml = Get-Content -Raw $config
    $mod = $xml.SelectSingleNode("/InstrumentationEngineConfiguration/InstrumentationMethod/Module")
    $mod.InnerText = [IO.Path]::Combine("..", "huh_framework_${bitness}.dll")
    $xml.Save($config)
}

function multi([string]$bitness)
{
    $env:COR_PROFILER='{A1538204-C8BF-484E-BCD3-E4587B9D3322}'
    $conf = ""
    if ($bitness -eq "x64")
    {
        $env:COR_PROFILER_PATH_64='C:\Program Files\Microsoft CLR Instrumentation Engine\Proxy\v1\InstrumentationEngine.ProfilerProxy_x64.dll'
        $env:MicrosoftInstrumentationEngine_ConfigPath64_blah='C:\Program Files\Huh\BLAH\Configurations\huh.config'
        $conf = $env:MicrosoftInstrumentationEngine_ConfigPath64_blah
    }
    else
    {
        $env:COR_PROFILER_PATH_32='C:\Program Files\Microsoft CLR Instrumentation Engine\Proxy\v1\InstrumentationEngine.ProfilerProxy_x86.dll'
        $env:MicrosoftInstrumentationEngine_ConfigPath32_blah='C:\Program Files\Huh\BLAH\Configurations\huh.config'
        $conf = $env:MicrosoftInstrumentationEngine_ConfigPath32_blah
    }
    $env:MicrosoftInstrumentationEngine_DisableCodeSignatureValidation='1'
    $env:MicrosoftInstrumentationEngine_LogLevel='Errors'
    $env:MicrosoftInstrumentationEngine_FileLogPath='C:\tmp\netfx_app_prof\mie.log'
    make_config_mods $conf $bitness
}

$arch="x86"
iex "csc /platform:${arch} /debug testprog.cs"

$env:BLEH_LIB_BLAH='C:\Program Files\Huh\BLAH\$arch\blah.dll'
multi $arch
$env:COR_ENABLE_PROFILING='1'

iex ".\testprog.exe"

Hi @sanikolov, the x86 version of the ProfilerProxy lives under C:\Program Files (x86)

Not on my box. Maybe we're not packaging it per the recommendations but nevertheless the paths are sensible on my box.

[lssw:/mnt/c/tmp/netfx_app_prof] find /mnt/c/Program\ Files/Microsoft\ CLR\ Instrumentation\ Engine/ -type f
/mnt/c/Program Files/Microsoft CLR Instrumentation Engine/1.0.36/Instrumentation32/MicrosoftInstrumentationEngine_x86.dll
/mnt/c/Program Files/Microsoft CLR Instrumentation Engine/1.0.36/Instrumentation64/MicrosoftInstrumentationEngine_x64.dll
/mnt/c/Program Files/Microsoft CLR Instrumentation Engine/Proxy/v1/InstrumentationEngine.ProfilerProxy_x64.dll
/mnt/c/Program Files/Microsoft CLR Instrumentation Engine/Proxy/v1/InstrumentationEngine.ProfilerProxy_x86.dll

This path structure works ok for arch x64, btw, even if it deviates from the recommendations.

To rule out profiler proxy is messing things up due to dir/file structure I referenced the instrumentation engine directly. Still doesn't work.
$env:COR_PROFILER_PATH_32='C:\Program Files\Microsoft CLR Instrumentation Engine\1.0.36\Instrumentation32\MicrosoftInstrumentationEngine_x86.dll'

The profiler proxy looks in specific locations to find the current version of the CLRIE profiler. For x86 processes, it looks in the Program Files (x86) directory:

#ifndef _WIN64
        // WoW64 = Windows (32bit) on Windows 64bit
        BOOL bIsWow64 = FALSE;
        IfFailRet_Proxy(IsWow64(eventLogger, &bIsWow64));
        if (bIsWow64)
        {
            programFilesVar = _T("ProgramFiles(x86)");
        }
#endif

So, not setting up you layout in that manner is likely the cause of the issue. This is by design. It is to ensure that people can use the most up-to-date version of CLRIE by looking in a particular path on the system. It is part of the contract.

@WilliamXieMSFT, do we publish the MSI to the public? If yes, @sanikolov could you install the proxy using the MSI?

To rule out profiler proxy is messing things up due to dir/file structure I referenced the instrumentation engine directly. Still doesn't work.
$env:COR_PROFILER_PATH_32='C:\Program Files\Microsoft CLR Instrumentation Engine\1.0.36\Instrumentation32\MicrosoftInstrumentationEngine_x86.dll'

Have you checked the Windows Event Log to see if there are any problems loading the dll? The CLR should either tell you it was successful, or it should report an error.

There was a typo in the most recent edit.
In fact, referencing the instrumentation engine directly did work.
So your explanation about the contract makes sense.... I should update how CLRIE is redistributed by us.
Thanks

There was a typo in the most recent edit.
In fact, referencing the instrumentation engine directly did work.
So your explanation about the contract makes sense.... I should update how CLRIE is redistributed by us.
Thanks

Glad to hear it. Let us know if there is anything else we can do to help.