Top Banner
Logging - Considered Harmful? David Dancy Programmation Pty Limited @4dexpert
91

Logging considered-harmful

Apr 09, 2017

Download

Software

dd105
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Logging considered-harmful

Logging - Considered Harmful?

David Dancy Programmation Pty Limited

@4dexpert

Page 2: Logging considered-harmful
Page 3: Logging considered-harmful

Race Conditions

Page 4: Logging considered-harmful

Racing C#

Page 5: Logging considered-harmful

Racing C#initial = 100

Page 6: Logging considered-harmful

Racing C#initial = 100

-0

100

Page 7: Logging considered-harmful

Racing C#initial = 100

+1

101

-0

100

Page 8: Logging considered-harmful

Racing C#initial = 100

+1

101

-2

99

-0

100

Page 9: Logging considered-harmful

Racing C#initial = 100

+1

101

-2

99

+3

102

-0

100

Page 10: Logging considered-harmful

Racing C#initial = 100

+1

101

-2

99

+3

102

-4

98

-0

100

Page 11: Logging considered-harmful

Racing C#initial = 100

+1

101

-2

99

+3

102

-4

98

+5

103

-0

100

Page 12: Logging considered-harmful

Racing C#initial = 100

+1

101

-2

99

+3

102

-4

98

+5

103

-6

97

-0

100

Page 13: Logging considered-harmful

Racing C#initial = 100

+1

101

-2

99

+3

102

-4

98

+5

103

-6

97

+7

104

-0

100

Page 14: Logging considered-harmful

Racing C#initial = 100

+1

101

-2

99

+3

102

-4

98

+5

103

-6

97

+7

104

-8

96

-0

100

Page 15: Logging considered-harmful

Racing C#initial = 100

+1

101

-2

99

+3

102

-4

98

+5

103

-6

97

+7

104

-8

96

+9

105

-0

100

Page 16: Logging considered-harmful

Racing C#initial = 100

+1

101

-2

99

+3

102

-4

98

+5

103

-6

97

+7

104

-8

96

+9

105

-10

95

-0

100

Page 17: Logging considered-harmful

Racing C#initial = 100

+1

101

-2

99

+3

102

-4

98

+5

103

-6

97

+7

104

-8

96

+9

105

-10

95

+11

106

-0

100

Page 18: Logging considered-harmful

Racing C#initial = 100

+1

101

-2

99

+3

102

-4

98

+5

103

-6

97

+7

104

-8

96

+9

105

-10

95

+11

106

-12

94

-0

100

Page 19: Logging considered-harmful

Racing C#initial = 100

+1

101

-2

99

+3

102

-4

98

+5

103

-6

97

+7

104

-8

96

+9

105

-10

95

+11

106

-12

94

+13

107

-0

100

Page 20: Logging considered-harmful

Racing C#initial = 100

+1

101

-2

99

+3

102

-4

98

+5

103

-6

97

+7

104

-8

96

+9

105

-10

95

+11

106

-12

94

+13

107

-14

93

-0

100

Page 21: Logging considered-harmful

Racing C#[44006:6972073][2015-08-10T22:14:23.5812750Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 0 [44006:6972073][2015-08-10T22:14:23.5812830Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 1 [44006:6972073][2015-08-10T22:14:23.5812890Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 2 [44006:6972073][2015-08-10T22:14:23.5812940Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 3 [44006:6972073][2015-08-10T22:14:23.5812990Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 4 [44006:6972073][2015-08-10T22:14:23.5813050Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 5 [44006:6972073][2015-08-10T22:14:23.5813110Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 6 [44006:6972073][2015-08-10T22:14:23.5813160Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 7 [44006:6972073][2015-08-10T22:14:23.5813200Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 8 [44006:6972073][2015-08-10T22:14:23.5813260Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 9 [44006:6972073][2015-08-10T22:14:23.5813310Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 10 [44006:6972073][2015-08-10T22:14:23.5813360Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 11 [44006:6972073][2015-08-10T22:14:23.5813400Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 12 [44006:6972073][2015-08-10T22:14:23.5813450Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 13 [44006:6972073][2015-08-10T22:14:23.5813500Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 14 [44006:6972073][2015-08-10T22:14:23.5813610Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L146]: -> 93

Page 22: Logging considered-harmful

Racing C#initial = 100

Page 23: Logging considered-harmful

Racing C#initial = 100

-0

100

Page 24: Logging considered-harmful

Racing C#initial = 100

-0

100

+1

101

Page 25: Logging considered-harmful

Racing C#initial = 100

-0

100

+1

101

+3

104

Page 26: Logging considered-harmful

Racing C#initial = 100

-2

102

-0

100

+1

101

+3

104

Page 27: Logging considered-harmful

Racing C#initial = 100

-2

102

-0

100

+1

101

+3

104

-4

98

Page 28: Logging considered-harmful

Racing C#initial = 100

-2

102

+5

103

-0

100

+1

101

+3

104

-4

98

Page 29: Logging considered-harmful

Racing C#initial = 100

-2

102

+5

103

-6

97

-0

100

+1

101

+3

104

-4

98

Page 30: Logging considered-harmful

Racing C#initial = 100

-2

102

+7

104

+5

103

-6

97

-0

100

+1

101

+3

104

-4

98

Page 31: Logging considered-harmful

Racing C#initial = 100

-2

102

+7

104

+5

103

-6

97

-0

100

+1

101

+3

104

+9

113

-4

98

Page 32: Logging considered-harmful

Racing C#initial = 100

-2

102

+7

104

+5

103

-6

97

-0

100

+1

101

-10

93

+3

104

+9

113

-4

98

Page 33: Logging considered-harmful

Racing C#initial = 100

-2

102

+7

104

+5

103

-6

97

-0

100

+11

104

+1

101

-10

93

+3

104

+9

113

-4

98

Page 34: Logging considered-harmful

Racing C#initial = 100

-2

102

+7

104

+5

103

-6

97

-0

100

+11

104

-8

96

+1

101

-10

93

+3

104

+9

113

-4

98

Page 35: Logging considered-harmful

Racing C#initial = 100

-2

102

+7

104

+5

103

-6

97

-0

100

+11

104

-8

96

+1

101

-10

93

+3

104

-12

84

+9

113

-4

98

Page 36: Logging considered-harmful

Racing C#initial = 100

-2

102

+7

104

+5

103

-6

97

-0

100

+11

104

-8

96

+1

101

-10

93

+3

104

+13

97

-12

84

+9

113

-4

98

Page 37: Logging considered-harmful

Racing C#initial = 100

-2

102

+7

104

+5

103

-6

97

-0

100

+11

104

-8

96

+1

101

-10

93

+3

104

+13

97

-12

84

+9

113

-14

83

-4

98

Page 38: Logging considered-harmful

Racing C#[44006:6972073][2015-08-10T22:14:23.5816070Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 0 [44006:6972073][2015-08-10T22:14:23.5816250Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 1 [44006:6972073][2015-08-10T22:14:23.5816310Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 3 [44006:6972073][2015-08-10T22:14:23.5816310Z][DBUG00009][ViewModels.RaceLoggingViewModel.Run L138]: 2 [44006:6972073][2015-08-10T22:14:23.5816360Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 4 [44006:6972073][2015-08-10T22:14:23.5816410Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 5 [44006:6972073][2015-08-10T22:14:23.5816460Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 6 [44006:6972073][2015-08-10T22:14:23.5816500Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 7 [44006:6972073][2015-08-10T22:14:23.5816550Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 9 [44006:6972073][2015-08-10T22:14:23.5816600Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 10 [44006:6972073][2015-08-10T22:14:23.5816640Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 11 [44006:6972073][2015-08-10T22:14:23.5816680Z][DBUG00009][ViewModels.RaceLoggingViewModel.Run L138]: 8 [44006:6972073][2015-08-10T22:14:23.5816690Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 12 [44006:6972073][2015-08-10T22:14:23.5816740Z][DBUG00010][ViewModels.RaceLoggingViewModel.Run L138]: 13 [44006:6972073][2015-08-10T22:14:23.5816910Z][DBUG00009][ViewModels.RaceLoggingViewModel.Run L138]: 14 [44006:6972073][2015-08-10T22:14:23.5817100Z][DBUG00009][ViewModels.RaceLoggingViewModel.Run L146]: -> 92

Page 39: Logging considered-harmful

Racing C#

Page 40: Logging considered-harmful

Racing C#

Page 41: Logging considered-harmful

Racing C#

Fixed!

Page 42: Logging considered-harmful

????

Page 43: Logging considered-harmful

Accidental Locks

Page 44: Logging considered-harmful

Accidental LocksI/O operations using [System.Console] are synchronized, which means multiple threads

can read from, or write to, the streams.

Page 45: Logging considered-harmful

Accidental LocksI/O operations using [System.Console] are synchronized, which means multiple threads

can read from, or write to, the streams.

https://github.com/dotnet/corefx/blob/master/src/System.Console/src/System/IO/SyncTextWriter.cs

Page 46: Logging considered-harmful

Introducing…

Page 47: Logging considered-harmful

TPL Dataflow

Page 48: Logging considered-harmful

TPL Dataflow

ActionBlock<T>

TransformBlock<T, U>

TransformManyBlock<T, U>

Page 49: Logging considered-harmful

TPL Dataflow

ActionBlock<T>

TransformBlock<T, U>

TransformManyBlock<T, U>

BatchBlock<T>

JoinBlock<T, U, …>

BatchedJoinBlock<T, U, …>

Page 50: Logging considered-harmful

TPL Dataflow

ActionBlock<T>

TransformBlock<T, U>

TransformManyBlock<T, U>

BufferBlock<T>

WriteOnceBlock<T>

BroadcastBlock<T>

BatchBlock<T>

JoinBlock<T, U, …>

BatchedJoinBlock<T, U, …>

Page 51: Logging considered-harmful

Exec

utio

n

TPL Dataflow

ActionBlock<T>

TransformBlock<T, U>

TransformManyBlock<T, U>

BufferBlock<T>

WriteOnceBlock<T>

BroadcastBlock<T>

BatchBlock<T>

JoinBlock<T, U, …>

BatchedJoinBlock<T, U, …>

Page 52: Logging considered-harmful

Gro

upin

g

Exec

utio

n

TPL Dataflow

ActionBlock<T>

TransformBlock<T, U>

TransformManyBlock<T, U>

BufferBlock<T>

WriteOnceBlock<T>

BroadcastBlock<T>

BatchBlock<T>

JoinBlock<T, U, …>

BatchedJoinBlock<T, U, …>

Page 53: Logging considered-harmful

Buffe

r

Gro

upin

g

Exec

utio

n

TPL Dataflow

ActionBlock<T>

TransformBlock<T, U>

TransformManyBlock<T, U>

BufferBlock<T>

WriteOnceBlock<T>

BroadcastBlock<T>

BatchBlock<T>

JoinBlock<T, U, …>

BatchedJoinBlock<T, U, …>

Page 54: Logging considered-harmful

TPL Dataflow

Page 55: Logging considered-harmful

TPL Dataflow

Page 56: Logging considered-harmful

TPL DataflowBufferBlock<T>

Page 57: Logging considered-harmful

TPL DataflowBufferBlock<T>

Page 58: Logging considered-harmful

TPL Dataflow

BatchBlock<T>

BufferBlock<T>

Page 59: Logging considered-harmful

TPL Dataflow

BatchBlock<T>

BufferBlock<T>

Page 60: Logging considered-harmful

TPL Dataflow

BatchBlock<T>

BufferBlock<T>

TransformManyBlock<T, U>

Page 61: Logging considered-harmful

TPL Dataflow

BatchBlock<T>

BufferBlock<T>

TransformManyBlock<T, U>

Page 62: Logging considered-harmful

TPL Dataflow

BatchBlock<T>

BufferBlock<T>

TransformManyBlock<T, U>

JoinBlock<T, U, …>

Page 63: Logging considered-harmful

TPL Dataflow

BatchBlock<T>

BufferBlock<T>

TransformManyBlock<T, U>

JoinBlock<T, U, …>

Page 64: Logging considered-harmful

TPL Dataflow

BatchBlock<T>

BufferBlock<T>

TransformManyBlock<T, U>

JoinBlock<T, U, …>

ActionBlock<T>

Page 65: Logging considered-harmful

Safe Logger

Page 66: Logging considered-harmful

Safe Logger

• Create interface ILogger

Page 67: Logging considered-harmful

Safe Logger

• Create interface ILogger

• Debug

Page 68: Logging considered-harmful

Safe Logger

• Create interface ILogger

• Debug

• Info

Page 69: Logging considered-harmful

Safe Logger

• Create interface ILogger

• Debug

• Info

• Include / Exclude

Page 70: Logging considered-harmful

Safe Logger

Page 71: Logging considered-harmful

Safe Logger

2015-07-29 18:00:12.565 SimpleLog.iOS [57400:1766661] [2015-07-29T08:00:12.5657180Z] [DBUG00001] [SimpleLog.StartPage.OnSizeAllocated L24]: Size: [568, 288]

Page 72: Logging considered-harmful

Safe Logger

Page 73: Logging considered-harmful

Safe Logger

Page 74: Logging considered-harmful

Safe Logger

• Create LogData class implementing ILogData

Page 75: Logging considered-harmful

Safe Logger

• Create LogData class implementing ILogData

• Use ActionBlock<ILogData>

Page 76: Logging considered-harmful

Safe Logger

• Create LogData class implementing ILogData

• Use ActionBlock<ILogData>

• Profit!

Page 77: Logging considered-harmful

Safe Logger

Page 78: Logging considered-harmful

Safe Logger

Page 79: Logging considered-harmful

Safe Logger

• Test harness for different logging strategies

• Use Scale to increase time spent working vs logging

Page 80: Logging considered-harmful

Safe LoggeriOS Native Console

Blocking √ Scale

Queue √ √Dataflow √ √

Page 81: Logging considered-harmful

Safe Logger

• Android (emulator) very reluctant to race

Page 82: Logging considered-harmful

Safe LoggerAndroid Native Console

Blocking ? ?Queue ? ?

Dataflow ? ?

Page 83: Logging considered-harmful

Safe Logger

• Hardware behaves differently

• Test on real hardware

• Beware memory limitations

Page 84: Logging considered-harmful

DEMO

Page 85: Logging considered-harmful

Safe Logging

Page 86: Logging considered-harmful

Safe Logging• There is no completely safe logging

Page 87: Logging considered-harmful

Safe Logging• There is no completely safe logging

• There's only less dangerous logging

Page 88: Logging considered-harmful

Safe Logging• There is no completely safe logging

• There's only less dangerous logging

• Measuring something changes the way it behaves

Page 89: Logging considered-harmful

Safe Logging• There is no completely safe logging

• There's only less dangerous logging

• Measuring something changes the way it behaves

• Change as little as possible

Page 90: Logging considered-harmful

Safe Logging• There is no completely safe logging

• There's only less dangerous logging

• Measuring something changes the way it behaves

• Change as little as possible

• Especially threads

Page 91: Logging considered-harmful

CAVEAT LOGITOR