Removes things that didn't work

This commit is contained in:
benbierens 2023-07-13 12:28:07 +02:00
parent e664591596
commit 7401d4af64
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 7 additions and 1107 deletions

File diff suppressed because it is too large Load Diff

View File

@ -19,12 +19,9 @@ import ./timer
when defined(chronosDurationThreshold): when defined(chronosDurationThreshold):
import std/monotimes import std/monotimes
import srcloc
import pkg/metrics import pkg/metrics
declareGauge(chronosCallbackDuration, "chronos callback duration") declareGauge(chronosCallbackDuration, "chronos callback duration")
declareGauge(chronosConstant, "chronos constant")
declareCounter(chronosCallbackCounter, "chronos callback counter")
export Port, SocketFlag export Port, SocketFlag
export timer export timer
@ -202,8 +199,6 @@ type
AsyncCallback* = object AsyncCallback* = object
function*: CallbackFunc function*: CallbackFunc
udata*: pointer udata*: pointer
when defined(chronosDurationThreshold):
location*: array[2, ptr SrcLoc]
AsyncError* = object of CatchableError AsyncError* = object of CatchableError
## Generic async exception ## Generic async exception
@ -232,22 +227,22 @@ template newAsyncCallback*(cbFunc: CallbackFunc, udataPtr: pointer = nil): Async
when defined(chronosDurationThreshold): when defined(chronosDurationThreshold):
type type
ChronosDurationThreadholdBreachedCallback* = proc(stackTrace: string, durationUs: int64) {.gcsafe, raises: [].} ChronosDurationThreadholdBreachedCallback* = proc(durationUs: int64) {.gcsafe, raises: [].}
proc defaultThresholdBreachedHandler(stackTrace: string, durationUs: int64) {.gcsafe, raises: [].} = proc defaultThresholdBreachedHandler(durationUs: int64) {.gcsafe, raises: [].} =
raise newException(Defect, "ChronosDurationThreshold breached. Time taken: " & $durationUs & " usecs - stackTrace: " & stackTrace) raise newException(Defect, "ChronosDurationThreshold breached. Time taken: " & $durationUs & " usecs")
var chronosDurationThresholdBreachedHandler {.threadvar.} : ChronosDurationThreadholdBreachedCallback var chronosDurationThresholdBreachedHandler {.threadvar.} : ChronosDurationThreadholdBreachedCallback
proc setChronosDurationThresholdBreachedHandler*(handler: ChronosDurationThreadholdBreachedCallback) = proc setChronosDurationThresholdBreachedHandler*(handler: ChronosDurationThreadholdBreachedCallback) =
chronosDurationThresholdBreachedHandler = handler chronosDurationThresholdBreachedHandler = handler
proc invokeChronosDurationThresholdBreachedHandler(stackTrace: string, durationUs: int64) = proc invokeChronosDurationThresholdBreachedHandler(durationUs: int64) =
if chronosDurationThresholdBreachedHandler == nil: if chronosDurationThresholdBreachedHandler == nil:
defaultThresholdBreachedHandler(stackTrace, durationUs) defaultThresholdBreachedHandler(durationUs)
return return
chronosDurationThresholdBreachedHandler(stackTrace, durationUs) chronosDurationThresholdBreachedHandler(durationUs)
proc sentinelCallbackImpl(arg: pointer) {.gcsafe, raises: [Defect].} = proc sentinelCallbackImpl(arg: pointer) {.gcsafe, raises: [Defect].} =
raiseAssert "Sentinel callback MUST not be scheduled" raiseAssert "Sentinel callback MUST not be scheduled"
@ -337,20 +332,9 @@ template processCallbacks(loop: untyped) =
durationUs = durationNs div 1000 durationUs = durationNs div 1000
chronosCallbackDuration.set(durationNs) chronosCallbackDuration.set(durationNs)
chronosConstant.set(123)
chronosCallbackCounter.inc()
if durationUs > chronosDurationThreshold: if durationUs > chronosDurationThreshold:
invokeChronosDurationThresholdBreachedHandler(durationUs)
# callable.location*: array[2, ptr SrcLoc]
# procedure*: cstring
# file*: cstring
# line*: int
var trace = "trace: "
if not(isNil(callable.location[0])): trace = trace & "[0]=" & $callable.location[0]
if not(isNil(callable.location[1])): trace = trace & "[1]=" & $callable.location[1]
invokeChronosDurationThresholdBreachedHandler(trace, durationUs)
proc raiseAsDefect*(exc: ref Exception, msg: string) {. proc raiseAsDefect*(exc: ref Exception, msg: string) {.
raises: [Defect], noreturn, noinline.} = raises: [Defect], noreturn, noinline.} =

View File

@ -21,9 +21,7 @@ WORKDIR ${BUILD_HOME}
COPY . . COPY . .
RUN make clean RUN make clean
RUN make -j ${MAKE_PARALLEL} update RUN make -j ${MAKE_PARALLEL} update
COPY docker/asyncfutures2.nim ./vendor/nim-chronos/chronos
COPY docker/asyncloop.nim ./vendor/nim-chronos/chronos COPY docker/asyncloop.nim ./vendor/nim-chronos/chronos
COPY docker/srcloc.nim ./vendor/nim-chronos/chronos
RUN make -j ${MAKE_PARALLEL} RUN make -j ${MAKE_PARALLEL}
# Create # Create

View File

@ -1,42 +0,0 @@
#
# Chronos source location utilities
# (c) Copyright 2018-Present
# Status Research & Development GmbH
#
# Licensed under either of
# Apache License, version 2.0, (LICENSE-APACHEv2)
# MIT license (LICENSE-MIT)
when (NimMajor, NimMinor) < (1, 4):
{.push raises: [Defect].}
else:
{.push raises: [].}
import stew/base10
type
SrcLoc* = object
procedure*: cstring
file*: cstring
line*: int
proc `$`*(loc: ptr SrcLoc): string =
var res = $loc.file
res.add("(")
res.add(Base10.toString(uint64(loc.line)))
res.add(")")
res.add(" ")
if len(loc.procedure) == 0:
res.add("[unspecified]")
else:
res.add($loc.procedure)
res
proc srcLocImpl(procedure: static string,
file: static string, line: static int): ptr SrcLoc =
var loc {.global.} = SrcLoc(
file: cstring(file), line: line, procedure: procedure
)
return addr(loc)
template getSrcLocation*(procedure: static string = ""): ptr SrcLoc =
srcLocImpl(procedure,
instantiationInfo(-2).filename, instantiationInfo(-2).line)