2
2
using CoinAPI . WebSocket . V1 ;
3
3
using CoinAPI . WebSocket . V1 . DataModels ;
4
4
using Microsoft . Extensions . Configuration ;
5
+ using Microsoft . Extensions . DependencyInjection ;
5
6
using Microsoft . Extensions . Hosting ;
6
7
using Serilog ;
7
8
using System . Diagnostics ;
@@ -185,6 +186,32 @@ void ProcessMsg(DateTime? time_exchange, DateTime? time_coinapi)
185
186
186
187
Task . Run ( async ( ) =>
187
188
{
189
+ string basePath = "output" ;
190
+ string extension = ".csv" ;
191
+
192
+ string csvFilePath = basePath + extension ;
193
+ int counter = 1 ;
194
+ while ( File . Exists ( csvFilePath ) )
195
+ {
196
+ csvFilePath = $ "{ basePath } _{ counter } { extension } ";
197
+ counter ++ ;
198
+ }
199
+
200
+ using ( StreamWriter sw = File . CreateText ( csvFilePath ) )
201
+ {
202
+ sw . WriteLine ( "Parameters:" ) ;
203
+ sw . WriteLine ( $ "Endpoint Name: { endpoint_name } ") ;
204
+ sw . WriteLine ( $ "Subscribe Data Type: { subscribe_data_type } ") ;
205
+ sw . WriteLine ( $ "Asset: { asset } ") ;
206
+ sw . WriteLine ( $ "Symbol: { symbol } ") ;
207
+ sw . WriteLine ( $ "Exchange: { exchange } ") ;
208
+ sw . WriteLine ( $ "Supress heartbeat: { supress_hb } ") ;
209
+ sw . WriteLine ( $ "Latency type: { latency_type } ") ;
210
+ sw . WriteLine ( ) ;
211
+ sw . WriteLine ( "Timestamp;Messages;BytesReceived;WaitingCPU%;ParsingCPU%;ProcessingCPU%;LatencyMin(ms);LatencyMax(ms)" ) ;
212
+ }
213
+
214
+
188
215
if ( ! wsClient . ConnectedEvent . WaitOne ( 10000 ) ) return ;
189
216
190
217
var iterations = 0 ;
@@ -242,9 +269,9 @@ void ProcessMsg(DateTime? time_exchange, DateTime? time_coinapi)
242
269
var deltaCpuTime = deltaCpuWaiting + deltaCpuParsing + deltaCpuHandling ;
243
270
244
271
245
- var cpuWaitingPercent = 100 * deltaCpuWaiting . TotalMilliseconds / deltaCpuTime . TotalMilliseconds ;
246
- var cpuParsingPercent = 100 * deltaCpuParsing . TotalMilliseconds / deltaCpuTime . TotalMilliseconds ;
247
- var cpuHandlingPercent = 100 * deltaCpuHandling . TotalMilliseconds / deltaCpuTime . TotalMilliseconds ;
272
+ var cpuWaitingPercent = deltaCpuWaiting . TotalMilliseconds / deltaCpuTime . TotalMilliseconds ;
273
+ var cpuParsingPercent = deltaCpuParsing . TotalMilliseconds / deltaCpuTime . TotalMilliseconds ;
274
+ var cpuHandlingPercent = deltaCpuHandling . TotalMilliseconds / deltaCpuTime . TotalMilliseconds ;
248
275
249
276
250
277
var msgCountOnInterval = msgCount - msgCountPrev ;
@@ -255,7 +282,7 @@ void ProcessMsg(DateTime? time_exchange, DateTime? time_coinapi)
255
282
256
283
strbld . AppendFormat ( $ "Messages: { msgCountOnInterval , - 8 } ") ;
257
284
strbld . AppendFormat ( $ "| Recv bytes: { bytesCountOnInterval , - 8 } ") ;
258
- strbld . Append ( $ "| CPU: wait: { cpuWaitingPercent : F2 } % | parse: { cpuParsingPercent : F2 } % | process: { cpuHandlingPercent : F2 } % ") ;
285
+ strbld . Append ( $ "| CPU: wait: { cpuWaitingPercent : P } | parse: { cpuParsingPercent : P } | process: { cpuHandlingPercent : P } ") ;
259
286
260
287
if ( latencies . Any ( ) )
261
288
{
@@ -264,6 +291,13 @@ void ProcessMsg(DateTime? time_exchange, DateTime? time_coinapi)
264
291
}
265
292
266
293
Serilog . Log . Information ( strbld . ToString ( ) ) ;
294
+
295
+ using ( StreamWriter sw = File . AppendText ( csvFilePath ) )
296
+ {
297
+ sw . WriteLine ( $ "\" { DateTime . UtcNow : yyyy-MM-dd HH:mm:ss} \" ;{ msgCountOnInterval } ;{ bytesCountOnInterval } ;{ cpuWaitingPercent : F2} ;{ cpuParsingPercent : F2} ;{ cpuHandlingPercent : F2} ;{ ( latencies . Any ( ) ? latencies . Min ( ) . TotalMilliseconds : 0 ) : F2} ;{ ( latencies . Any ( ) ? latencies . Max ( ) . TotalMilliseconds : 0 ) : F2} ") ;
298
+ }
299
+
300
+
267
301
}
268
302
}
269
303
) ;
0 commit comments