diff --git a/src/base/profile.nim b/src/base/profile.nim index e6ee8fd..b47bc39 100644 --- a/src/base/profile.nim +++ b/src/base/profile.nim @@ -36,7 +36,7 @@ tic() injects symbols: ]## type - II = typeof(instantiationInfo()) + II = ptr typeof(instantiationInfo()) RTInfo = distinct int RTInfoObj = object nsec: int64 @@ -53,13 +53,15 @@ type #overhead: int64 count: uint32 dropcount: uint32 - name: string + name: CStr loc: II SString = static[string] | string List[T] = object # No GCed type allowed len,cap:int32 data:ptr UncheckedArray[T] RTInfoObjList = distinct List[RTInfoObj] + CStr = object + p, s: int32 var rtiListLength:int32 = 0 @@ -132,6 +134,51 @@ iterator mitems(ls:RTInfoObjList):var RTInfoObj = func isNil(x:RTInfo):bool = x.int<0 func isNil(x:CodePoint):bool = x.int<0 +const defaultCStrPoolCap {.intDefine.} = 512 +type CStrAtom = array[16,char] +var cstrpool = newListOfCap[CStrAtom](defaultCStrPoolCap) + +proc len(s:CStr):int = int(s.s) +proc newCStr(t:string):CStr = + const a = int32(sizeof(CStrAtom)) + let p = cstrpool.len + let s = int32(t.len) + let n = (s+a-1) div a + cstrpool.setlen(p+n) + var k = 0 + var j = 0 + for i in 0..0) loc = pre & markMissing(noexpand, f0 & "(" & $l0 & "-" & (if f==f0:"" else:f) & $l & ")") - nm = pre & markMissing(noexpand, (if tn=="":"" else:tn&":") & (if pn=="":"" else:pn&"-") & ts[j].curr.name) + nm = pre & markMissing(noexpand, (if tn.len==0:"" else: $tn & ":") & (if pn.len==0:"" else: $pn & "-") & $ts[j].curr.name) if total!=0: let cent = 1e2 * ns.float / total.float @@ -715,7 +762,7 @@ template echoTimers*(expandAbove = 0.0, expandDropped = true, aggregate = true) if n0.0: ", not expanding contributions less than " & $(1e2*expandAbove) & " %" else:"" - echo "Timer total ",(tt.float*1e-6)|(0,-3)," ms, overhead ",(oh.float*1e-6)|(0,-3)," ms ~ ",(1e2*oh.float/tt.float)|(0,-1)," %, memory ",rtiListLength*sizeof(RTInfoObj)," B, max ",rtiListLengthMax*sizeof(RTInfoObj)," B",notshowing + echo "Timer total ",(tt.float*1e-6)|(0,-3)," ms, overhead ",(oh.float*1e-6)|(0,-3)," ms ~ ",(1e2*oh.float/tt.float)|(0,-1)," %, runtime info ",rtiListLength*sizeof(RTInfoObj)," B, max ",rtiListLengthMax*sizeof(RTInfoObj)," B, string ",cstrpool.len*sizeof(cstrpool[0])," B",notshowing echo '='.repeat(width) echo "file(lines)"|(-n), "%"|6, "OH%"|6, "microsecs"|12, "OH"|8, "count"|9, "ns/count"|14, "OH/c"|8, "mf"|8, " label" echo '='.repeat(width) @@ -731,7 +778,7 @@ proc echoTimersRaw* = proc getName(t: ptr RTInfoObj): string = let tn = t.tic.name let pn = t.prev.name - let name = (if tn=="":"" else:tn&":") & (if pn=="":"" else:pn&"-") & t.curr.name + let name = (if tn.len==0:"" else: $tn & ":") & (if pn.len==0:"" else: $pn & "-") & $t.curr.name if t.prev.toDropTimer: result = "{" & name & "}" else: result = name