我正在尝试分析用 Haskell 编写的中型编译器。在示例文件上运行它时,我得到以下分析数据:
vehicle +RTS -po.profiling/vehicle-1706073721 -p -RTS compile --target MarabouQueries --specification vehicle/tests/golden/compile/acasXu/spec.vcl --network acasXu:vehicle/tests/golden/compile/acasXu/fake.onnx
total time = 0.72 secs (716 ticks @ 1000 us, 1 processor)
total alloc = 1,558,506,104 bytes (excludes profiling overheads)
COST CENTRE MODULE SRC %time %alloc
fmap Vehicle.Prelude.Logging.Backend src/Vehicle/Prelude/Logging/Backend.hs:49:13-19 19.7 21.2
runVehicle.\ Vehicle src/Vehicle.hs:(56,46)-(67,52) 12.2 19.3
fmap Vehicle.Prelude.Supply src/Vehicle/Prelude/Supply.hs:28:13-19 9.1 8.2
compileDecls Vehicle.Backend.Queries src/Vehicle/Backend/Queries.hs:(87,1)-(101,47) 5.7 7.2
$mRelevantExplicitArg.\ Vehicle.Syntax.AST.Arg src/Vehicle/Syntax/AST/Arg.hs:51:36-60 5.6 5.4
>>= Vehicle.Prelude.Logging.Backend src/Vehicle/Prelude/Logging/Backend.hs:49:35-39 4.3 2.9
fmap Vehicle.Compile.Context.Free.Instance src/Vehicle/Compile/Context/Free/Instance.hs:24:13-19 4.3 4.2
>>= Vehicle.Prelude.Supply src/Vehicle/Prelude/Supply.hs:28:35-39 3.2 2.9
>>= Vehicle.Prelude.Logging.Instance src/Vehicle/Prelude/Logging/Instance.hs:49:35-39 2.8 4.4
pure Vehicle.Prelude.Supply src/Vehicle/Prelude/Supply.hs:28:22-32 2.2 0.7
return Vehicle.Prelude.Logging.Backend src/Vehicle/Prelude/Logging/Backend.hs:49:35-39 2.2 3.6
return Vehicle.Compile.Context.Free.Instance src/Vehicle/Compile/Context/Free/Instance.hs:24:35-39 2.2 1.5
Run Code Online (Sandbox Code Playgroud)
查看第二个条目,该函数runVehicle(直接从我的主函数调用)如下:
vehicle +RTS -po.profiling/vehicle-1706073721 -p -RTS compile --target MarabouQueries --specification vehicle/tests/golden/compile/acasXu/spec.vcl --network acasXu:vehicle/tests/golden/compile/acasXu/fake.onnx
total time = 0.72 secs (716 ticks @ 1000 us, 1 processor)
total alloc = 1,558,506,104 bytes (excludes profiling overheads)
COST CENTRE MODULE SRC %time %alloc
fmap Vehicle.Prelude.Logging.Backend src/Vehicle/Prelude/Logging/Backend.hs:49:13-19 19.7 21.2
runVehicle.\ Vehicle src/Vehicle.hs:(56,46)-(67,52) 12.2 19.3
fmap Vehicle.Prelude.Supply src/Vehicle/Prelude/Supply.hs:28:13-19 9.1 8.2
compileDecls Vehicle.Backend.Queries src/Vehicle/Backend/Queries.hs:(87,1)-(101,47) 5.7 7.2
$mRelevantExplicitArg.\ Vehicle.Syntax.AST.Arg src/Vehicle/Syntax/AST/Arg.hs:51:36-60 5.6 5.4
>>= Vehicle.Prelude.Logging.Backend src/Vehicle/Prelude/Logging/Backend.hs:49:35-39 4.3 2.9
fmap Vehicle.Compile.Context.Free.Instance src/Vehicle/Compile/Context/Free/Instance.hs:24:13-19 4.3 4.2
>>= Vehicle.Prelude.Supply src/Vehicle/Prelude/Supply.hs:28:35-39 3.2 2.9
>>= Vehicle.Prelude.Logging.Instance src/Vehicle/Prelude/Logging/Instance.hs:49:35-39 2.8 4.4
pure Vehicle.Prelude.Supply src/Vehicle/Prelude/Supply.hs:28:22-32 2.2 0.7
return Vehicle.Prelude.Logging.Backend src/Vehicle/Prelude/Logging/Backend.hs:49:35-39 2.2 3.6
return Vehicle.Compile.Context.Free.Instance src/Vehicle/Compile/Context/Free/Instance.hs:24:35-39 2.2 1.5
Run Code Online (Sandbox Code Playgroud)
我的理解是成本中心表示执行函数所花费的时间,不包括执行它调用的函数所花费的时间。成本中心摘要中的条目似乎表明 12.2% 的时间花在执行匿名 lambda 上。
我不明白怎么会这样,因为它所做的只是一个简单的案例分割。有人对发生的事情有一个很好的解释吗?
我的理解是成本中心表示执行函数所花费的时间,不包括执行它调用的函数所花费的时间。
我认为这是不正确的。我认为更正确的版本是分配给成本中心的时间表示执行该成本中心所花费的时间,不包括分配给它调用的成本中心的时间。如果它调用的函数本身没有成本中心,则父级将分配所有成本。也许这就是发生在你身上的事情,即也许typeCheck,,,compile朋友不是成本中心。