Modern Tracing - Msmvps.com

pikeactuaryInternet και Εφαρμογές Web

20 Οκτ 2013 (πριν από 3 χρόνια και 10 μήνες)

130 εμφανίσεις

Kathleen Dollard
@
kathleendollard
http://msmvps.com/blogs/kathleen
kathleen@mvps.org
Modern Tracing
Agenda
ETW Architecture

Controllers, consumers, providers

Manifests

Channels (audience)

Role of Semantic Logging Application Block from Patterns & Practices
Tools
EventSource

.NET 4.5

NuGet
version
Fixing
EventSource
fragility

Side
-
trip into code generation
Tracing is Changing
Faster

Part of the operating system
Holistic view

Across applications, processes, threads, and machines
Modular

Many controllers

Many consumers

Many providers

Alternate cores
Rapidly evolving

Examples: new version of
EventSource
, TraceEvent, WPR/WPA, Semantic
Logging Application Block (SLAB)
Tracing records the path through your app
Outside forces affect your app

.NET

Operating system

Service/web calls

Many others







Old
-
Style Tracing
New
-
Style
Tracing















Very Confusing
ETW Design
Controller
Consumer
Controller
Consumer
A Few Tools
Controllers

PerfView

WPR

SLAB
Consumers

PerfView

WPA

SLAB

EventViewer
(maybe)
Demo
PerfView
EventSource
Structure
Too simple (bad)
EventSource
Please define a few things
namespace
EventDefinitions
{
public
class
SimpleEventSource
:
EventSource
{
static
public
SimpleEventSource
Log
=
new
SimpleEventSource
();
public
void
Message(
string
Message)
{
WriteEvent
(1, Message); }
public
void
AccessByPrimaryKey
(
int
PrimaryKey
,
string
TableName
)
{
WriteEvent
(2,
PrimaryKey
,
TableName
);
}
}
}
Default is “
SimpleEventSource

These must match the
order of the logging
methods in the file
“Normal” (good)
EventSource
Please define a few things
[
EventSource
(Name =
"
KadGen
-
EtwSamples
-
Normal"
)]
public
class
NormalEventSource
:
EventSource
{
static
public
NormalEventSource
Log
=
new
NormalEventSource
();
[
Event
(1)]
public
void
Message(
string
Message)
{
WriteEvent
(1, Message); }
[
Event
(2)]
public
void
AccessByPrimaryKey
(
int
PrimaryKey
)
{
if
(
IsEnabled
())
WriteEvent
(2,
PrimaryKey
); }
}
EventSource
Structure
Important Attribute Parameters
Property
Default
Recommended
Name
Non
-
namespace
qualified class name
Use a
hierarchical name meaningful to the
consumer

does not need to contain the
class name
DO NOT use the default value
Guid
Derived
from name and
also called the
ProviderId
Do not specify
but allow to be derived
from
the name
Property
Default
EventId
Ordinal from top
of class
Must match value passed to
WriteEvent
Unique identifier for the
event
EventSource
Event
Performance Summary
Cached
Logger
int
/string
Object
Overload
Event
Off
Yes
9ns
100M
20ns
50M
Event Watched
Yes
410ns
2M
720ns
1M
Event Off
No
9ns
100M
19ns
50M
Event
Watched
No
410ns
2M
730ns
50M
Integer and string constants same speed
Caching the logger does not alter performance
Object overload is approximately twice as slow
Non
-
watched events are nearly free
See guidelines in my course (What’s New… & ETW) or blog!
My course
or blog
Code Generation
EventSource
Fragility
Just say no to writing stupid code
[
EventSource
(Name =
"
KadGen
-
EtwSamples
-
Normal"
)]
public
class
NormalEventSource
:
EventSource
{
static
public
NormalEventSource
Log
=
new
NormalEventSource
();
[
Event
(1)]
public
void
Message(
string
Message)
{
WriteEvent
(1, Message); }
[
Event
(2)]
public
void
AccessByPrimaryKey
(
int
PrimaryKey
)
{
if
(
IsEnabled
())
WriteEvent
(2,
PrimaryKey
); }
}
r
edundant
b
ad default
EventID
in
WriteEvent
must match
parameters
must match
Demo
Generating
EventSource
Types of Code Generation
by increasing level of relevant size
Compilers
DSL (*)
File Generation
Application Generation

Architecture Expression
Code Generation Principles
1.
Humans are in control
2.
Metadata is distinct and isolated
3.
Generation is simplest approach
4.
Human altered code is sacred
5.
Generated code is highest quality
NuGet
Version 1.0
EventSource
Microsoft
.Diagnostics.Tracing
Improved diagnostics

Compiler errors and warnings

Constructor exception

Zero Events contain trace failure notification
Installed manifest support

Automatic creation of manifest files and resource assemblies
for installing with wevtutil.exe

Attribute parameter to specify a standard channel
Improved correlation support
SLAB Benefits over direct use
Plays nice with rest of Enterprise Library 6 , simpler than Logging Block
Really nice documentation
Builds on
EventSource
, so you get those benefits for free

Not even an intervening class
Build/test time tools to validate providers

Different than what’s available in
NuGet
4.5.1 version of
EventSource
In process as well of as out of process logging
Alternate and multiple listeners
IObservable
support
Drawbacks

As of (Sept 2013), no
EventSource
4.5.1 support, can’t write to
EventViewer

Be careful with alternate sinks in production

Your team won’t learn the tools they need for production maintenance
Out of
proc
In
-
Proc
SLAB In
-
Proc
SLAB In
-
Proc
SLAB Out Of
Proc
is ETW
Out of
proc
Out of
proc
In
-
Proc
Just configuration
Summary
ETW Architecture

Controllers, consumers, providers

Manifests

installed (
NuGet
) or in
-
line

Channels supported in
NuGet
version

A few tools

WPA in Win 8.1 SDK and PerfView
EventSource

.NET
4.5 (also has
EventListener
which you don’t care
much about

use SLAB
)

.NET 4.5.1 (
validation at build, trace diagnostics
-
Event
Zero/constructor)

NuGet
(4.0 support, channels, validation at build, trace diagnostics
-
Event
Zero/constructor, correlation)
Patterns and Practices

Semantic Logging Application Block for simple development time listeners

Use only ETW as production listener and controller
The most important thing you’re missing is
alternate event design.
Please watch my
next
course (ETW)
and my blog
References
kathleen@mvps.org
My blog:
http://msmvps.com/blogs/kathleen
@
kathleendollard
on Twitter
.NET Puzzles
, Kathleen Dollard,
Pluralsight
,
http://
bit.ly/19z2JaD
What’s
New in .NET 4.5,
Kathleen Dollard,
Pluralsight
,
http://
bit.ly/YTb962
Module
3 is ETW:
Upcoming Tracing/Server Debugging Course on
Pluralsight
Vance Morrison’s blog:
http://blogs.msdn.com/b/vancem/
EventSource
NuGet
announcement:
http://bit.ly/11XuggO
TraceEvent announcement:
http://bit.ly/16K1kLa
WPR/WPA announcement:
http://bit.ly/16K1kLa
My What’s New in .NET 4.5
Pluralsight
course,
http://bit.ly/18pyvCW
Older article on ETW:
http://bit.ly/18nIysh