From d851f24dde341e00bbc134d12469500252a32e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Baylac-Jacqu=C3=A9?= Date: Sat, 28 Sep 2019 17:33:42 +0200 Subject: [PATCH] Finished implementation design outline. --- src/libexpr/eval.hh | 47 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index ef58645f..289fc4ba 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -317,14 +317,48 @@ private: }; -struct ProfilerMeasurement { - string functionName; - string subFunction; +/* Profiler-related operations. + [callGrindSpec]: TODO: add URL */ + +typedef string FunctionName; +typedef string FileName; +typedef int CompressedFuncId; +typedef int CompressedFileId; +typedef int LineNumber; + +struct ProfFuncOcc { + CompressedFuncId funcId; + CompressedFileId fileId; } -struct ProfilerState { +struct ProfCostOcc { + ProfFuncOcc funcOcc; + int selfCost; + Array calledFunctions; +} + +struct ProfFuncCall { + CompressedFuncId calledFunc; + CompressedFileId calledFile; + LineNumber calledFuncLineNb; + int cost; +} + +class ProfilerState { + +public: + ProfCostOcc& getFuncOcc(FileName& fName, FunctionName& fnName); + void saveCost(ProfCostOcc& occCost); + +private: + Array stackedMeasurements; string funcName; - Array stackedMeasurements; + /* We index every func and file to leverage Callgrind's string compression. + See section "3.1.6.�Subposition Compression" section from [callgrindSpec]. */ + std::map funcMap; + std::map fileMap; + CompressedFuncId currentFuncId; + CompressedFileId currentFileId; } /* Return a string representing the type of the value `v'. */ @@ -366,6 +400,9 @@ struct EvalSettings : Config Setting traceFunctionCalls{this, false, "trace-function-calls", "Emit log messages for each function entry and exit at the 'vomit' log level (-vvvv)"}; + + Setting profileEvaluation(this, false, "profile-function-calls", + "Generates a callgraph profile summary which you can interpret using kcachegrind."); }; extern EvalSettings evalSettings;