mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-02-26 08:23:08 +00:00
trying with future locations
This commit is contained in:
parent
0f4cca13a0
commit
ce6483e328
@ -315,6 +315,7 @@ proc addCallback*(future: FutureBase, cb: CallbackFunc, udata: pointer = nil) =
|
||||
callSoon(cb, udata)
|
||||
else:
|
||||
var acb = newAsyncCallback(cb, udata)
|
||||
acb.location = future.location
|
||||
|
||||
future.callbacks.add acb
|
||||
|
||||
|
||||
@ -20,6 +20,9 @@ import ./timer
|
||||
when defined(chronosDurationThreshold):
|
||||
import std/monotimes
|
||||
import srcloc
|
||||
import pkg/metrics
|
||||
|
||||
declareGauge(chronosCallbackDuration, "chronos callback duration")
|
||||
|
||||
export Port, SocketFlag
|
||||
export timer
|
||||
@ -198,7 +201,7 @@ type
|
||||
function*: CallbackFunc
|
||||
udata*: pointer
|
||||
when defined(chronosDurationThreshold):
|
||||
location*: string # ptr SrcLoc
|
||||
location*: array[2, ptr SrcLoc]
|
||||
|
||||
AsyncError* = object of CatchableError
|
||||
## Generic async exception
|
||||
@ -223,10 +226,10 @@ type
|
||||
const chronosDurationThreshold {.intdefine.} = 0
|
||||
|
||||
template newAsyncCallback*(cbFunc: CallbackFunc, udataPtr: pointer = nil): AsyncCallback =
|
||||
when defined(chronosDurationThreshold):
|
||||
AsyncCallback(function: cbFunc, udata: udataPtr, location: getStackTrace())
|
||||
else:
|
||||
AsyncCallback(function: cbFunc, udata: udataPtr)
|
||||
# when defined(chronosDurationThreshold):
|
||||
# AsyncCallback(function: cbFunc, udata: udataPtr, location: getStackTrace())
|
||||
# else:
|
||||
AsyncCallback(function: cbFunc, udata: udataPtr)
|
||||
|
||||
when defined(chronosDurationThreshold):
|
||||
type
|
||||
@ -334,6 +337,7 @@ template processCallbacks(loop: untyped) =
|
||||
durationNs = getMonoTime().ticks - startTime
|
||||
durationUs = durationNs div 1000
|
||||
|
||||
chronosCallbackDuration.set(durationUs.int64)
|
||||
if durationUs > chronosDurationThreshold:
|
||||
|
||||
# callable.location*: array[2, ptr SrcLoc]
|
||||
@ -341,8 +345,9 @@ template processCallbacks(loop: untyped) =
|
||||
# file*: cstring
|
||||
# line*: int
|
||||
|
||||
let loc = callable.location
|
||||
var trace = "trace: " & loc
|
||||
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) {.
|
||||
|
||||
@ -23,6 +23,7 @@ RUN make clean
|
||||
RUN make -j ${MAKE_PARALLEL} update
|
||||
COPY docker/asyncfutures2.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}
|
||||
|
||||
# Create
|
||||
|
||||
46
docker/srcloc.nim
Normal file
46
docker/srcloc.nim
Normal file
@ -0,0 +1,46 @@
|
||||
#
|
||||
# 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
|
||||
trace*: cstring
|
||||
|
||||
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.add("[")
|
||||
res.add($loc.trace)
|
||||
res.add("]")
|
||||
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, trace: "a"
|
||||
)
|
||||
return addr(loc)
|
||||
|
||||
template getSrcLocation*(procedure: static string = ""): ptr SrcLoc =
|
||||
srcLocImpl(procedure,
|
||||
instantiationInfo(-2).filename, instantiationInfo(-2).line)
|
||||
Loading…
x
Reference in New Issue
Block a user