Skip to content

Commit f1f4052

Browse files
committed
Automating Event Logging Infrastructure: With this change the infrastructure required for Event Logging
will be generated as part of build
1 parent 4be02be commit f1f4052

39 files changed

+1626
-43990
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,6 @@ Makefile
273273

274274
# Cross compilation
275275
cross/rootfs/*
276+
277+
#python import files
278+
*.pyc

Documentation/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Coding Guidelines
3838
- [CLR Coding Guide](coding-guidelines/clr-code-guide.md)
3939
- [CLR JIT Coding Conventions](coding-guidelines/clr-jit-coding-conventions.md)
4040
- [Cross Platform Performance and Eventing Design](coding-guidelines/cross-platform-performance-and-eventing.md)
41+
- [Adding New Events to the VM](coding-guidelines/EventLogging.md)
4142

4243
Build CoreCLR from Source
4344
=========================

Documentation/building/windows-instructions.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ The CoreCLR build relies on CMake for the build. We are currently using CMake 3.
3131
- Install [CMake](http://www.cmake.org/download) for Windows.
3232
- Add it to the PATH environment variable.
3333

34+
Python
35+
---------
36+
Python is used in the build system. We are currently using python 2.7.9.
37+
- Install [Python](https://www.python.org/downloads/) for Windows.
38+
- Add it to the PATH environment variable.
39+
3440
Git Setup
3541
---------
3642

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# CoreClr Event Logging Design
2+
3+
##Introduction
4+
5+
Event Logging is a mechanism by which CoreClr can provide a variety of information on it's state. This Logging works by inserting explicit logging calls by the developer within the VM . The Event Logging mechanism is largely based on [ETW- Event Tracing For Windows](https://msdn.microsoft.com/en-us/library/windows/desktop/bb968803(v=vs.85).aspx)
6+
7+
# Adding Events to the Runtime
8+
9+
- Edit the [Event manifest](../../src/vm/ClrEtwAll.man) to add a new event. For guidelines on adding new events, take a look at the existing events in the manifest and this guide for [ETW Manifests](https://msdn.microsoft.com/en-us/library/dd996930%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396).
10+
- The build system should automatically generate the required artifacts for the added events.
11+
- Add entries in the [exclusion list](../../src/vm/ClrEtwAllMeta) if necessary
12+
- The Event Logging Mechanism provides the following two functions, which can be used within the VM:
13+
- **FireEtw**EventName, this is used to trigger the event
14+
- **EventEnabled**EventName, this is used to see if any consumer has subscribed to this event
15+
16+
17+
# Adding New Logging System
18+
19+
Though the the Event logging system was designed for ETW, the build system provides a mechanism, basically an [adapter script- genXplatEventing.py](../../src/scripts/genXplatEventing.py) so that other Logging System can be added and used by CoreClr. An Example of such an extension for [LTTng logging system](https://lttng.org/) can be found in [genXplatLttng.py](../../src/scripts/genXplatLttng.py )

build.cmd

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@echo off
1+
echo off
22
setlocal EnableDelayedExpansion
33

44
:: Set the default arguments for build
@@ -65,6 +65,7 @@ set "__IntermediatesDir=%__RootBinDir%\obj\%__BuildOS%.%__BuildArch%.%__BuildTyp
6565
set "__PackagesBinDir=%__BinDir%\.nuget"
6666
set "__TestBinDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%"
6767
set "__TestIntermediatesDir=%__RootBinDir%\tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
68+
set "__GeneratedIntermediatesDir=%__IntermediatesDir%\Generated"
6869

6970
:: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
7071
set "__CMakeBinDir=%__BinDir%"
@@ -197,6 +198,27 @@ exit /b 1
197198

198199
REM Build CoreCLR
199200
:BuildCoreCLR
201+
:: Run Steps to Generate ETW specific infrastructure the
202+
if exist "%__GeneratedIntermediatesDir%" rd /s /q "%__GeneratedIntermediatesDir%" ::Ensure there are no stale files in the Generated Directory
203+
md "%__GeneratedIntermediatesDir%"
204+
md "%__GeneratedIntermediatesDir%\inc"
205+
set "genetw=%__SourceDir%\scripts\genWinEtw.py"
206+
207+
mc -h "%__GeneratedIntermediatesDir%\inc" -r "%__GeneratedIntermediatesDir%" -b -co -um -p FireEtw "%__SourceDir%\VM\ClrEtwAll.man"
208+
IF ERRORLEVEL 1 goto FailedToGenEtwMetadata
209+
210+
echo generating clretwallmain.h and etmdummy.h
211+
"%PythonPath%" "%genetw%" --man "%__SourceDir%\VM\ClrEtwAll.man" --exc "%__SourceDir%\VM\ClrEtwAllMeta.lst" --eventheader "%__GeneratedIntermediatesDir%\inc\ClrEtwAll.h" --macroheader "%__GeneratedIntermediatesDir%\inc\clretwallmain.h" --dummy "%__GeneratedIntermediatesDir%\inc\etmdummy.h"
212+
IF ERRORLEVEL 1 goto FailedToGenEtwMetadata
213+
214+
goto BuildVM
215+
216+
:FailedToGenEtwMetadata
217+
echo Failed to generate ETW specific files.
218+
exit /b %ERRORLEVEL%
219+
220+
:BuildVM
221+
200222
set "__CoreCLRBuildLog=%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
201223
if /i "%__BuildArch%" == "arm64" (
202224
REM TODO, remove once we have msbuild support for this platform.

build.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ setup_dirs()
2727
mkdir -p "$__BinDir"
2828
mkdir -p "$__LogsDir"
2929
mkdir -p "$__IntermediatesDir"
30+
31+
# Ensure there are no stale generated files
32+
rm -rf "$__IntermediatesDir"
33+
mkdir -p "$__GeneratedIntermediatesDir"
34+
mkdir -p "$__GeneratedIntermediatesDir/inc"
3035
}
3136

3237
# Performs "clean build" type actions (deleting and remaking directories)
@@ -67,6 +72,19 @@ build_coreclr()
6772
# All set to commence the build
6873

6974
echo "Commencing build of native components for $__BuildOS.$__BuildArch.$__BuildType"
75+
76+
echo "Laying out dynamically generated files consumed by the build system "
77+
python "$__ProjectRoot/src/scripts/genXplatEventing.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --exc "$__ProjectRoot/src/vm/ClrEtwAllMeta.lst" --inc "$__GeneratedIntermediatesDir/inc" --dummy "$__GeneratedIntermediatesDir/inc/etmdummy.h" --testdir "$__GeneratedIntermediatesDir/eventprovider_tests"
78+
79+
#determine the logging system
80+
case $__BuildOS in
81+
Linux)
82+
python "$__ProjectRoot/src/scripts/genXplatLttng.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__GeneratedIntermediatesDir/"
83+
;;
84+
*)
85+
;;
86+
esac
87+
7088
cd "$__IntermediatesDir"
7189

7290
generator=""
@@ -352,6 +370,7 @@ __ToolsDir="$__RootBinDir/tools"
352370
__TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
353371
__IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
354372
__TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
373+
export __GeneratedIntermediatesDir="$__IntermediatesDir/Generated"
355374

356375
# Specify path to be set for CMAKE_INSTALL_PREFIX.
357376
# This is where all built CoreClr libraries will copied to.

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
include_directories($ENV{__GeneratedIntermediatesDir}/inc)
12
include_directories("inc")
23
include_directories("strongname/inc")
34
include_directories("inc/winrt")

src/dlls/clretwrc/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include_directories(${CMAKE_CURRENT_BINARY_DIR})
2+
include_directories($ENV{__GeneratedIntermediatesDir})
23

34
if(WIN32)
45
# remove /ltcg from resource-only libraries
@@ -15,15 +16,6 @@ add_library(clretwrc SHARED
1516
clretwrc.rc
1617
)
1718

18-
#Compile clretwall.man file to create clretwall.rc resource file
19-
add_custom_command(
20-
TARGET clretwrc
21-
PRE_BUILD
22-
COMMAND mc -h ${CMAKE_CURRENT_BINARY_DIR} -r ${CMAKE_CURRENT_BINARY_DIR} -b -co -um -p FireEtw ${VM_DIR}/ClrEtwAll.man
23-
DEPENDS ${VM_DIR}/ClrEtwAll.man
24-
COMMENT "MessageCompile ${VM_DIR}/ClrEtwAll.man"
25-
)
26-
2719
# add the install targets
2820
install (TARGETS clretwrc DESTINATION .)
2921

src/inc/eventtracebase.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,10 @@ extern "C" {
294294
EtwCallout(RegHandle, Descriptor, NumberOfArguments, EventData)
295295
#endif //!DONOT_DEFINE_ETW_CALLBACK && !DACCESS_COMPILE
296296

297-
#include <clretwallmain.h>
298-
299-
#elif defined(__LINUX__)
300-
301-
#include "clrallevents.h"
302-
#else
303-
#error "A tracing System has not been enabled for this Platform"
304297
#endif //!FEATURE_PAL
305298

299+
#include "clretwallmain.h"
300+
306301
// The bulk type event is too complex for MC.exe to auto-generate proper code.
307302
// Use code:BulkTypeEventLogger instead.
308303
#ifdef FireEtwBulkType

0 commit comments

Comments
 (0)