Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 3개 있습니다.)

마이크로소프트의 CoreCLR 프로파일러 예제 빌드 방법

CoreCLR 용 프로파일 예제가 github에 공개되어 있습니다.

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

clr-samples/ProfilingAPI/ReJITEnterLeaveHooks/
; https://github.com/Microsoft/clr-samples/tree/master/ProfilingAPI/ReJITEnterLeaveHooks

물론, 빌드하는 방법이 "clr-samples/ProfilingAPI/ReJITEnterLeaveHooks/" 문서에도 나오지만 그래도 정리를 해보겠습니다. ^^

우선, 당연히 Visual Studio 2017은 있어야 합니다. 그런 다음 CoreCLR을 clone합니다.

dotnet/coreclr 
; https://github.com/dotnet/coreclr

부담 갖지 않아도 됩니다. ^^ 단지 include 파일만 필요하기 때문에 빌드까지 할 필요는 없습니다. 그런 다음 cmd.exe 창을 띄우고 다음과 같이 환경 변수를 설정합니다.

SET CORECLR_PATH=...[coreclr 폴더]...
SET BuildOS=Windows_NT
SET BuildArch=...[원하는 플랫폼]...
SET BuildType=...[Debug or Release]...
SET Output=...[빌드 후 생성되는 DLL 파일명]...

가령, clone한 coreclr 폴더가 E:\git_clone\coreclr이고, x64/Debug 모드로 빌드하고 싶다면 다음과 같은 식으로 설정하면 됩니다.

SET CORECLR_PATH=E:\git_clone\coreclr
SET BuildOS=Windows_NT
SET BuildArch=x64
SET BuildType=Debug
SET Output=ClrProfiler.dll

이걸로 준비 작업은 모두 끝입니다. 이후에는 그냥 ./build.cmd 파일을 실행하면 깨끗하게 빌드가 완료됩니다.

참고로, 다음과 같이 .csproj 프로젝트 파일 내에 IncludePath를 통해 위에서 설정한 환경 변수의 값에 따라 include 경로가 결정됩니다.

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
    <IncludePath>$(VC_IncludePath);$(CORECLR_PATH)\src\pal\prebuilt\inc;$(CORECLR_PATH)\src\inc;$(CORECLR_PATH)\bin\Product\$(BuildOS).$(BuildArch).$(BuildType)\inc;$(NETFXSDKDir)Include\um;$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>




그래도 역시 디버깅이 가능한 Visual Studio 2017 내에서 빌드하는 것이 좋습니다. ^^ 이를 위해 명령행 창에서 SET... 환경 변수를 지정한 후 devenv.exe를 실행해야 합니다. 그렇게 실행된 Visual Studio 2017의 경우 환경 변수를 cmd.exe로부터 물려받기 때문에 정상적으로 빌드가 가능합니다.

만약 매번 명령행 창에 SET ... 환경 변수를 적용해서 devenv.exe를 실행하는 것이 귀찮다면 별도로 런처용 .bat를 만들던가, 아니면 전역 환경 변수로 적용하시면 됩니다. 참고로 런처용 .bat를 만든다면 다음의 글에 따라,

Visual Studio(devenv.exe)를 배치 파일(.bat)을 통해 실행하는 방법
; https://www.sysnet.pe.kr/2/0/11293

이렇게 구성해야 합니다.

REM dev_coreclr.bat

SET CORECLR_PATH=E:\git_clone\coreclr
SET BuildOS=Windows_NT
SET BuildArch=x64
SET BuildType=Debug
SET Output=ClrProfiler.dll

start "" "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe" 




만약, SET ... 환경 변수를 설정하지 않고 Visual Studio에서 ClrProfiler.sln을 올려 곧바로 빌드하면 다음과 같은 컴파일 에러가 발생합니다.

1>------ Rebuild All started: Project: ClrProfiler, Configuration: Debug Win32 ------
1>  ILRewriter.cpp
1>c:\program files (x86)\windows kits\8.1\include\um\corhdr.h(1849): error C2220: warning treated as error - no 'object' file generated
1>c:\program files (x86)\windows kits\8.1\include\um\corhdr.h(1849): warning C4091: 'typedef ': ignored on left of 'NGenHintEnum' when no variable is declared
1>c:\program files (x86)\windows kits\8.1\include\um\corhdr.h(1858): warning C4091: 'typedef ': ignored on left of 'LoadHintEnum' when no variable is declared
1>c:\program files (x86)\windows kits\8.1\include\um\corhdr.h(1907): warning C4091: 'typedef ': ignored on left of 'NativeTypeArrayFlags' when no variable is declared
1>  CorProfiler.cpp
1>c:\program files (x86)\windows kits\8.1\include\um\corhdr.h(1849): error C2220: warning treated as error - no 'object' file generated
1>c:\program files (x86)\windows kits\8.1\include\um\corhdr.h(1849): warning C4091: 'typedef ': ignored on left of 'NGenHintEnum' when no variable is declared
1>c:\program files (x86)\windows kits\8.1\include\um\corhdr.h(1858): warning C4091: 'typedef ': ignored on left of 'LoadHintEnum' when no variable is declared
1>c:\program files (x86)\windows kits\8.1\include\um\corhdr.h(1907): warning C4091: 'typedef ': ignored on left of 'NativeTypeArrayFlags' when no variable is declared
1>e:\git_clone\clr-samples\profilingapi\rejitenterleavehooks\corprofiler.h(11): error C2504: 'ICorProfilerCallback8': base class undefined
1>e:\git_clone\clr-samples\profilingapi\rejitenterleavehooks\corprofiler.h(14): error C2143: syntax error: missing ';' before '*'
1>e:\git_clone\clr-samples\profilingapi\rejitenterleavehooks\corprofiler.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\git_clone\clr-samples\profilingapi\rejitenterleavehooks\corprofiler.h(14): error C2238: unexpected token(s) preceding ';'

왜냐하면, CLR 관련 헤더 파일들이 기본적으로 Windows SDK에 포함된 것을 가져오게 되는데 아쉽게도 현재(2017-09-04) ICorProfilerCallback8 인터페이스 같은 것들은 포함하고 있지 않기 때문에 컴파일이 안됩니다. 이러한 최신 인터페이스들은 CoreClr 관련 헤더 파일에만 정의되어 있습니다. (아마도, 언젠가 Windows SDK에도 ICorProfilerCallback8이 포함되지 않을까요?!)




빌드 후 테스트하는 것도 간단합니다. 다음과 같이 프로파일러의 존재를 알리는 환경 변수를 설정하고,

SET CORECLR_PROFILER={cf0d821e-299b-5307-a3d8-b283c03916dd}
SET CORECLR_ENABLE_PROFILING=1
SET CORECLR_PROFILER_PATH=C:\filePath\to\ClrProfiler.dll

그대로 dotnet.exe 등의 .NET Core 실행 파일을 직접 구동하면 됩니다.

마찬가지로, Visual Studio 2017 내에서 직접 F5 디버깅 환경을 구성하고 싶다면 아래의 글에서처럼 C++ 프로젝트 설정에 환경 변수 설정과 실행될 EXE 환경을 구성해 주시면 됩니다.

디버깅 방법 - CLR 프로파일러
; https://www.sysnet.pe.kr/2/0/258




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 9/4/2017]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2019-02-27 12시08분
리눅스에서의 빌드/테스트는 다음의 글에 정리했습니다.

마이크로소프트의 CoreCLR 프로파일러 예제 빌드 방법 - 리눅스 환경
; http://www.sysnet.pe.kr/2/0/11829
정성태

... [31]  32  33  34  35  36  37  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
12845정성태10/6/20218099.NET Framework: 1120. C# - BufferBlock<T> 사용 예제 [5]파일 다운로드1
12844정성태10/3/20216132오류 유형: 764. MSI 설치 시 "... is accessible and not read-only." 오류 메시지
12843정성태10/3/20216592스크립트: 29. 파이썬 - fork 시 기존 클라이언트 소켓 및 스레드의 동작파일 다운로드1
12842정성태10/1/202124809오류 유형: 763. 파이썬 오류 - AttributeError: type object '...' has no attribute '...'
12841정성태10/1/20218378스크립트: 28. 모든 파이썬 프로세스에 올라오는 특별한 파일 - sitecustomize.py
12840정성태9/30/20218431.NET Framework: 1119. Entity Framework의 Join 사용 시 다중 칼럼에 대한 OR 조건 쿼리파일 다운로드1
12839정성태9/15/20219495.NET Framework: 1118. C# 11 - 제네릭 타입의 특성 적용파일 다운로드1
12838정성태9/13/20219146.NET Framework: 1117. C# - Task에 전달한 Action, Func 유형에 따라 달라지는 async/await 비동기 처리 [2]파일 다운로드1
12837정성태9/11/20218089VC++: 151. Golang - fmt.Errorf, errors.Is, errors.As 설명
12836정성태9/10/20217680Linux: 45. 리눅스 - 실행 중인 다른 프로그램의 출력을 확인하는 방법
12835정성태9/7/20218947.NET Framework: 1116. C# 10 - (15) CallerArgumentExpression 특성 추가 [2]파일 다운로드1
12834정성태9/7/20217320오류 유형: 762. Visual Studio 2019 Build Tools - 'C:\Program' is not recognized as an internal or external command, operable program or batch file.
12833정성태9/6/20216771VC++: 150. Golang - TCP client/server echo 예제 코드파일 다운로드1
12832정성태9/6/20217609VC++: 149. Golang - 인터페이스 포인터가 의미 있을까요?
12831정성태9/6/20216151VC++: 148. Golang - 채널에 따른 다중 작업 처리파일 다운로드1
12830정성태9/6/20218372오류 유형: 761. Internet Explorer에서 파일 다운로드 시 "Your current security settings do not allow this file to be downloaded." 오류
12829정성태9/5/202110021.NET Framework: 1115. C# 10 - (14) 구조체 타입에 기본 생성자 정의 가능파일 다운로드1
12828정성태9/4/20218147.NET Framework: 1114. C# 10 - (13) 단일 파일 내에 적용되는 namespace 선언파일 다운로드1
12827정성태9/4/20218129스크립트: 27. 파이썬 - 웹 페이지 데이터 수집을 위한 scrapy Crawler 사용법 요약
12826정성태9/3/202110372.NET Framework: 1113. C# 10 - (12) 문자열 보간 성능 개선 [1]파일 다운로드1
12825정성태9/3/20217931개발 환경 구성: 603. GoLand - WSL 환경과 연동
12824정성태9/2/202117008오류 유형: 760. 파이썬 tensorflow - Dst tensor is not initialized. 오류 메시지
12823정성태9/2/20216740스크립트: 26. 파이썬 - PyCharm을 이용한 fork 디버그 방법
12822정성태9/1/202111948오류 유형: 759. 파이썬 tensorflow - ValueError: Shapes (...) and (...) are incompatible [2]
12821정성태9/1/20217502.NET Framework: 1112. C# - .NET 6부터 공개된 ISpanFormattable 사용법
12820정성태9/1/20217807VC++: 147. Golang - try/catch에 대응하는 panic/recover [1]파일 다운로드1
... [31]  32  33  34  35  36  37  38  39  40  41  42  43  44  45  ...