VM profiler (#14833)
* Crude VM profiler * Added --profileVM flag, refactoring * fixed FileLine hash * Use TLineInfo instead of own FileLine, updated formatting * Refactoring, moved PStackFrame to vmdefs for cleaner data structure * Moved vmprofiler to separate file * Simplified TLineInfo hash, use toFileLineCol for output * Hash * Moved profile data into Config, dump only once at end of run * Changed profile output header to show '#instr' instead of 'count' * Do not accumulate instrcount for non-top frames Co-authored-by: Ico Doornekamp <git@zevv.nl>
This commit is contained in:
parent
c38a459582
commit
d7ccd82eac
8 changed files with 86 additions and 15 deletions
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
import
|
||||
os, strutils, strtabs, sets, lineinfos, platform,
|
||||
prefixmatches, pathutils, nimpaths
|
||||
prefixmatches, pathutils, nimpaths, tables
|
||||
|
||||
from terminal import isatty
|
||||
from times import utc, fromUnix, local, getTime, format, DateTime
|
||||
|
|
@ -95,6 +95,7 @@ type # please make sure we have under 32 options
|
|||
optPanics # turn panics (sysFatal) into a process termination
|
||||
optNimV1Emulation # emulate Nim v1.0
|
||||
optSourcemap
|
||||
optProfileVM # enable VM profiler
|
||||
|
||||
TGlobalOptions* = set[TGlobalOption]
|
||||
|
||||
|
|
@ -217,6 +218,13 @@ type
|
|||
version*: int
|
||||
Suggestions* = seq[Suggest]
|
||||
|
||||
ProfileInfo* = object
|
||||
time*: float
|
||||
count*: int
|
||||
|
||||
ProfileData* = ref object
|
||||
data*: TableRef[TLineInfo, ProfileInfo]
|
||||
|
||||
ConfigRef* = ref object ## every global configuration
|
||||
## fields marked with '*' are subject to
|
||||
## the incremental compilation mechanisms
|
||||
|
|
@ -314,6 +322,7 @@ type
|
|||
structuredErrorHook*: proc (config: ConfigRef; info: TLineInfo; msg: string;
|
||||
severity: Severity) {.closure, gcsafe.}
|
||||
cppCustomNamespace*: string
|
||||
vmProfileData*: ProfileData
|
||||
|
||||
proc assignIfDefault*[T](result: var T, val: T, def = default(T)) =
|
||||
## if `result` was already assigned to a value (that wasn't `def`), this is a noop.
|
||||
|
|
@ -390,6 +399,9 @@ template newPackageCache*(): untyped =
|
|||
else:
|
||||
modeCaseSensitive)
|
||||
|
||||
proc newProfileData(): ProfileData =
|
||||
ProfileData(data: newTable[TLineInfo, ProfileInfo]())
|
||||
|
||||
proc newConfigRef*(): ConfigRef =
|
||||
result = ConfigRef(
|
||||
selectedGC: gcRefc,
|
||||
|
|
@ -442,6 +454,7 @@ proc newConfigRef*(): ConfigRef =
|
|||
arguments: "",
|
||||
suggestMaxResults: 10_000,
|
||||
maxLoopIterationsVM: 10_000_000,
|
||||
vmProfileData: newProfileData(),
|
||||
)
|
||||
setTargetFromSystem(result.target)
|
||||
# enable colors by default on terminals
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue