-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathFasterTraceHelper.cs
More file actions
219 lines (191 loc) · 13.4 KB
/
FasterTraceHelper.cs
File metadata and controls
219 lines (191 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace DurableTask.Netherite.Faster
{
using System;
using Microsoft.Extensions.Logging;
class FasterTraceHelper
{
readonly ILogger logger;
readonly LogLevel logLevelLimit;
readonly ILogger performanceLogger;
readonly string account;
readonly string taskHub;
readonly int partitionId;
public FasterTraceHelper(ILogger logger, LogLevel logLevelLimit, ILogger performanceLogger, uint partitionId, string storageAccountName, string taskHubName)
{
this.logger = logger;
this.logLevelLimit = logLevelLimit;
this.performanceLogger = performanceLogger;
this.account = storageAccountName;
this.taskHub = taskHubName;
this.partitionId = (int) partitionId;
}
public bool IsTracingAtMostDetailedLevel => this.logLevelLimit == LogLevel.Trace || this.BoostTracing;
public bool BoostTracing { get; set; }
// ----- faster storage layer events
public void FasterStoreCreated((long,int) inputQueuePosition, long latencyMs)
{
if (this.logLevelLimit <= LogLevel.Information)
{
this.logger.LogInformation("Part{partition:D2} Created Store, inputQueuePosition={inputQueuePosition}.{inputQueueBatchPosition} latencyMs={latencyMs}", this.partitionId, inputQueuePosition.Item1, inputQueuePosition.Item2, latencyMs);
EtwSource.Log.FasterStoreCreated(this.account, this.taskHub, this.partitionId, inputQueuePosition.Item1, inputQueuePosition.Item2, latencyMs, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public void FasterCheckpointStarted(Guid checkpointId, string details, string storeStats, long commitLogPosition, (long, int) inputQueuePosition)
{
if (this.logLevelLimit <= LogLevel.Information)
{
this.logger.LogInformation("Part{partition:D2} Started Checkpoint {checkpointId}, details={details}, storeStats={storeStats}, commitLogPosition={commitLogPosition} inputQueuePosition={inputQueuePosition}.{inputQueueBatchPosition}", this.partitionId, checkpointId, details, storeStats, commitLogPosition, inputQueuePosition.Item1, inputQueuePosition.Item2);
EtwSource.Log.FasterCheckpointStarted(this.account, this.taskHub, this.partitionId, checkpointId, details, storeStats, commitLogPosition, inputQueuePosition.Item1, inputQueuePosition.Item2, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public void FasterCheckpointPersisted(Guid checkpointId, string details, long commitLogPosition, (long,int) inputQueuePosition, long latencyMs)
{
if (this.logLevelLimit <= LogLevel.Information)
{
this.logger.LogInformation("Part{partition:D2} Persisted Checkpoint {checkpointId}, details={details}, commitLogPosition={commitLogPosition} inputQueuePosition={inputQueuePosition}.{inputQueueBatchPosition} latencyMs={latencyMs}", this.partitionId, checkpointId, details, commitLogPosition, inputQueuePosition.Item1, inputQueuePosition.Item2, latencyMs);
EtwSource.Log.FasterCheckpointPersisted(this.account, this.taskHub, this.partitionId, checkpointId, details, commitLogPosition, inputQueuePosition.Item1, inputQueuePosition.Item2, latencyMs, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
if (latencyMs > 10000)
{
this.FasterPerfWarning($"Persisting the checkpoint {checkpointId} took {(double)latencyMs / 1000}s, which is excessive; checkpointId={checkpointId} commitLogPosition={commitLogPosition} inputQueuePosition={inputQueuePosition}");
}
}
public void FasterLogPersisted(long commitLogPosition, long numberEvents, long sizeInBytes, long latencyMs)
{
if (this.logLevelLimit <= LogLevel.Debug)
{
this.logger.LogDebug("Part{partition:D2} Persisted Log, commitLogPosition={commitLogPosition} numberEvents={numberEvents} sizeInBytes={sizeInBytes} latencyMs={latencyMs}", this.partitionId, commitLogPosition, numberEvents, sizeInBytes, latencyMs);
EtwSource.Log.FasterLogPersisted(this.account, this.taskHub, this.partitionId, commitLogPosition, numberEvents, sizeInBytes, latencyMs, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
if (latencyMs > 10000)
{
this.FasterPerfWarning($"Persisting the log took {(double)latencyMs / 1000}s, which is excessive; commitLogPosition={commitLogPosition} numberEvents={numberEvents} sizeInBytes={sizeInBytes}");
}
}
public void FasterPerfWarning(string details)
{
if (this.logLevelLimit <= LogLevel.Warning)
{
this.performanceLogger.LogWarning("Part{partition:D2} Performance issue detected: {details}", this.partitionId, details);
EtwSource.Log.FasterPerfWarning(this.account, this.taskHub, this.partitionId, details, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public void FasterCheckpointLoaded(long commitLogPosition, (long,int) inputQueuePosition, string storeStats, long latencyMs)
{
if (this.logLevelLimit <= LogLevel.Information)
{
this.logger.LogInformation("Part{partition:D2} Loaded Checkpoint, commitLogPosition={commitLogPosition} inputQueuePosition={inputQueuePosition}.{inputQueueBatchPosition} storeStats={storeStats} latencyMs={latencyMs}", this.partitionId, commitLogPosition, inputQueuePosition.Item1, inputQueuePosition.Item2, storeStats, latencyMs);
EtwSource.Log.FasterCheckpointLoaded(this.account, this.taskHub, this.partitionId, commitLogPosition, inputQueuePosition.Item1, inputQueuePosition.Item2, storeStats, latencyMs, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public void FasterLogReplayed(long commitLogPosition, (long,int) inputQueuePosition, long numberEvents, long sizeInBytes, string storeStats, long latencyMs)
{
if (this.logLevelLimit <= LogLevel.Information)
{
this.logger.LogInformation("Part{partition:D2} Replayed CommitLog, commitLogPosition={commitLogPosition} inputQueuePosition={inputQueuePosition}.{inputQueueBatchPosition} numberEvents={numberEvents} sizeInBytes={sizeInBytes} storeStats={storeStats} latencyMs={latencyMs}", this.partitionId, commitLogPosition, inputQueuePosition.Item1, inputQueuePosition.Item2, numberEvents, sizeInBytes, storeStats, latencyMs);
EtwSource.Log.FasterLogReplayed(this.account, this.taskHub, this.partitionId, commitLogPosition, inputQueuePosition.Item1, inputQueuePosition.Item2, numberEvents, sizeInBytes, storeStats, latencyMs, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public void FasterStorageError(string context, Exception exception)
{
if (this.logLevelLimit <= LogLevel.Error)
{
this.logger.LogError("Part{partition:D2} !!! Faster Storage Error : {context} : {exception}", this.partitionId, context, exception);
EtwSource.Log.FasterStorageError(this.account, this.taskHub, this.partitionId, context, exception.ToString(), TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public void FasterCacheSizeMeasured(int numPages, long numRecords, long sizeInBytes, long gcMemory, long processMemory, long discrepancy, double elapsedMs)
{
if (this.logLevelLimit <= LogLevel.Information)
{
this.logger.LogInformation("Part{partition:D2} Measured CacheSize numPages={numPages} numRecords={numRecords} sizeInBytes={sizeInBytes} gcMemory={gcMemory} processMemory={processMemory} discrepancy={discrepancy} elapsedMs={elapsedMs:F2}", this.partitionId, numPages, numRecords, sizeInBytes, gcMemory, processMemory, discrepancy, elapsedMs);
EtwSource.Log.FasterCacheSizeMeasured(this.account, this.taskHub, this.partitionId, numPages, numRecords, sizeInBytes, gcMemory, processMemory, discrepancy, elapsedMs, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public void FasterProgress(string details)
{
if (this.logLevelLimit <= LogLevel.Debug)
{
this.logger.LogDebug("Part{partition:D2} {details}", this.partitionId, details);
EtwSource.Log.FasterProgress(this.account, this.taskHub, this.partitionId, details, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public void FasterProgress(Func<string> constructString)
{
if (this.logLevelLimit <= LogLevel.Debug)
{
var details = constructString();
this.FasterProgress(details);
}
}
public void FasterStorageProgress(string details)
{
if (this.logLevelLimit <= LogLevel.Trace || this.BoostTracing)
{
this.logger.LogTrace("Part{partition:D2} {details}", this.partitionId, details);
EtwSource.Log.FasterStorageProgress(this.account, this.taskHub, this.partitionId, details, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public void FasterAzureStorageAccessCompleted(string intent, long size, string operation, string details, string target, double latency, int attempt)
{
if (this.logLevelLimit <= LogLevel.Debug)
{
this.logger.LogDebug("Part{partition:D2} storage access completed intent={intent} size={size} operation={operation} {details} target={target} latency={latency} attempt={attempt}",
this.partitionId, intent, size, operation, details, target, latency, attempt);
EtwSource.Log.FasterAzureStorageAccessCompleted(this.account, this.taskHub, this.partitionId, intent, size, operation, details, target, latency, attempt, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public enum CompactionProgress { Skipped, Started, Completed };
public void FasterCompactionProgress(CompactionProgress progress, string operation, long begin, long safeReadOnly, long tail, long minimalSize, long compactionAreaSize, double elapsedMs)
{
if (this.logLevelLimit <= LogLevel.Information)
{
this.logger.LogInformation("Part{partition:D2} Compaction {progress} operation={operation} begin={begin} safeReadOnly={safeReadOnly} tail={tail} minimalSize={minimalSize} compactionAreaSize={compactionAreaSize} elapsedMs={elapsedMs}", this.partitionId, progress, operation, begin, safeReadOnly, tail, minimalSize, compactionAreaSize, elapsedMs);
EtwSource.Log.FasterCompactionProgress(this.account, this.taskHub, this.partitionId, progress.ToString(), operation, begin, safeReadOnly, tail, minimalSize, compactionAreaSize, elapsedMs, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
// ----- lease management events
public void LeaseAcquired()
{
if (this.logLevelLimit <= LogLevel.Information)
{
this.logger.LogInformation("Part{partition:D2} PartitionLease acquired", this.partitionId);
EtwSource.Log.FasterLeaseAcquired(this.account, this.taskHub, this.partitionId, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public void LeaseRenewed(double elapsedSeconds, double timing)
{
if (this.logLevelLimit <= LogLevel.Debug)
{
this.logger.LogDebug("Part{partition:D2} PartitionLease renewed after {elapsedSeconds:F2}s timing={timing:F2}s", this.partitionId, elapsedSeconds, timing);
EtwSource.Log.FasterLeaseRenewed(this.account, this.taskHub, this.partitionId, elapsedSeconds, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public void LeaseReleased(double elapsedSeconds)
{
if (this.logLevelLimit <= LogLevel.Information)
{
this.logger.LogInformation("Part{partition:D2} PartitionLease released after {elapsedSeconds:F2}s", this.partitionId, elapsedSeconds);
EtwSource.Log.FasterLeaseReleased(this.account, this.taskHub, this.partitionId, elapsedSeconds, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public void LeaseLost(double elapsedSeconds, string operation)
{
if (this.logLevelLimit <= LogLevel.Warning)
{
this.logger.LogWarning("Part{partition:D2} PartitionLease lost after {elapsedSeconds:F2}s in {operation}", this.partitionId, elapsedSeconds, operation);
EtwSource.Log.FasterLeaseLost(this.account, this.taskHub, this.partitionId, operation, elapsedSeconds, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
public void LeaseProgress(string operation)
{
if (this.logLevelLimit <= LogLevel.Debug)
{
this.logger.LogDebug("Part{partition:D2} PartitionLease progress: {operation}", this.partitionId, operation);
EtwSource.Log.FasterLeaseProgress(this.account, this.taskHub, this.partitionId, operation, TraceUtils.AppName, TraceUtils.ExtensionVersion);
}
}
}
}