Coder Social home page Coder Social logo

tonyredondo / clrprofiler.trace Goto Github PK

View Code? Open in Web Editor NEW

This project forked from caozhiyuan/clrprofiler.trace

0.0 3.0 0.0 2.15 MB

CoreCLR Profiler ILReWrite , Use To Trace

License: MIT License

Batchfile 0.42% Shell 0.03% PowerShell 0.22% C# 7.35% C++ 79.58% CMake 0.09% C 12.31%

clrprofiler.trace's Introduction

CoreCLR Profiler ILReWrite

This sample shows il rewrite (open dev.cmd to develop)

1.hook il in premain assembly.customloadfrom(you profiler C# dll)

2.add try catch finally in to need trace method

Prerequisites

Building

Build

windows

git clone https://github.com/dotnet/coreclr.git
git clone https://github.com/caozhiyuan/ClrProfiler.Trace.git

cd ClrProfiler.Trace
powershell ./scripts/install-vcpkgs.ps1

set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if exist %_VSWHERE% ( for /f "usebackq tokens=*" %i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSPATH=%i)
call "%_VSPATH%\VC\Auxiliary\Build\vcvars64.bat" 

cd src\ClrProfiler
SET BuildArch=x64
SET BuildType=Debug
build

linux

git clone https://github.com/dotnet/coreclr.git
git clone https://github.com/caozhiyuan/ClrProfiler.Trace.git

git clone https://github.com/Microsoft/vcpkg.git
cd ~/vcpkg
./bootstrap-vcpkg.sh
./vcpkg install spdlog

cd ~/ClrProfiler.Trace/src/ClrProfiler
mkdir build
cd build 
cmake ..
make

Setup

SET CORECLR_PROFILER={cf0d821e-299b-5307-a3d8-b283c03916dd}
SET CORECLR_ENABLE_PROFILING=1
SET CORECLR_PROFILER_PATH=%WorkDir%src\ClrProfiler\x64\Debug\ClrProfiler.dll
SET CORECLR_PROFILER_HOME=%WorkDir%src\ClrProfiler.Trace\bin\Debug\netstandard2.0

SET COR_PROFILER={af0d821e-299b-5307-a3d8-b283c03916dd}
SET COR_ENABLE_PROFILING=1
SET COR_PROFILER_PATH=%WorkDir%src\ClrProfiler\x64\Debug\ClrProfiler.dll
SET COR_PROFILER_HOME=%WorkDir%src\ClrProfiler.Trace\bin\Debug\net461

cd tools
Dll.Repack.cmd Debug 

: or Dll.Repack.cmd Release

download https://github.com/jaegertracing/jaeger/releases/download/v1.9.0/jaeger-1.9.0-windows-amd64.tar.gz
run jaeger-all-in-one.exe

run examples Samples.WebApi

open http://localhost:16686

Notice

About Async Method Trace

if use scope, you should startActive(false) and restore active scope at method end

it's important if you want get ActiveSpan, code like this :

 public EndMethodDelegate BeforeWrappedMethod(TraceMethodInfo traceMethodInfo)
 {
     var dbCommand = (DbCommand)traceMethodInfo.InvocationTarget;
     var scope = _tracer.BuildSpan("mssql.command")
         .WithTag(Tags.SpanKind, Tags.SpanKindClient)
         .WithTag(Tags.Component, "SqlServer")
         .WithTag(Tags.DbInstance, dbCommand.Connection.ConnectionString)
         .WithTag(Tags.DbStatement, dbCommand.CommandText)
         .WithTag(TagMethod, traceMethodInfo.MethodBase.Name)
         .WithTag(TagIsAsync, true)
         .StartActive(false);

     traceMethodInfo.TraceContext = scope;

     return delegate (object returnValue, Exception ex)
     {
         DelegateHelper.AsyncMethodEnd(Leave, traceMethodInfo, ex, returnValue);

         // for async method , at method end restore active scope, important
         var tempScope = (IScope)traceMethodInfo.TraceContext;
         tempScope.Dispose();
     };
 }

 private void Leave(TraceMethodInfo traceMethodInfo, object ret, Exception ex)
 {
     var scope = (IScope)traceMethodInfo.TraceContext;
     if (ex != null)
     {
         scope.Span.SetException(ex);
     }
     scope.Span.Finish();
 }

Help Links:


https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-335.pdf

https://github.com/Microsoft/clr-samples

https://github.com/brian-reichle/MethodCheck

https://www.codeproject.com/articles/42655/%2fArticles%2f42655%2fNET-file-format-Signatures-under-the-hood-Part-2#LocalVarSig1.1

https://github.com/DataDog/dd-trace-dotnet

clrprofiler.trace's People

Contributors

caozhiyuan avatar pingtest avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.