Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark, in light modeAuto light/dark, in dark modeSkip to content
onnx-array-api 0.3.1 documentation
Logo
onnx-array-api 0.3.1 documentation

Contents

More

Back to top

profiling

ProfileNode

classonnx_array_api.profiling.ProfileNode(filename:str,line:int,func_name:str,nc1:int,nc2:int,tin:float,tall:float)[source]

Graph structure to represent a profiling.

Parameters:
  • filename – filename

  • line – line number

  • func_name – function name

  • nc1 – number of calls 1

  • nc2 – number of calls 2

  • tin – time spent in the function

  • tout – time spent in the function and in the sub functions

profile

onnx_array_api.profiling.profile(fct:Callable,sort:str='cumulative',rootrem:str|None=None,as_df:bool=False,return_results:bool=False,**kwargs)str[source]

Profiles the execution of a function.

Parameters:
  • fct – function to profile

  • sort – seesort_stats

  • rootrem – root to remove in filenames

  • as_df – return the results as a dataframe and not text

  • return_results – if True, return results as well(in the first position)

  • kwargs – additional parameters used to create the profiler,seecProfile.Profile

Returns:

raw results, statistics text dump (or dataframe isas_df is True)

(Sourcecode,png,hires.png,pdf)

../_images/profiling-1.png

profile2graph

onnx_array_api.profiling.profile2graph(ps:Stats,clean_text:Callable|None=None,verbose:bool=False,fLOG:Callable|None=None)ProfileNode[source]

Converts profiling statistics into a graphs.

Parameters:
  • ps – an instance ofpstats

  • clean_text – function to clean function names

  • verbose – verbosity

  • fLOG – logging function

Returns:

an instance of class @see cl ProfileNode

pyinstrument has a nice display to showtime spent and call stack at the same time. This functiontries to replicate that display based on the results producedby modulecProfile. Here is an example.

<<<

importtimefromonnx_array_api.profilingimportprofile,profile2graphdeffct0(t):time.sleep(t)deffct1(t):time.sleep(t)deffct2():fct1(0.1)fct1(0.01)deffct3():fct0(0.2)fct1(0.5)deffct4():fct2()fct3()ps=profile(fct4)[0]root,nodes=profile2graph(ps,clean_text=lambdax:x.split("/")[-1])text=root.to_text()print(text)

>>>

fct1--33--0.000030.61083--:11:fct1(fct1)<built-inmethodtime.sleep>--33--0.610800.61080--~:0:<built-inmethodtime.sleep>(<built-inmethodtime.sleep>)+++fct4--11--0.000020.81135--:25:fct4(fct4)fct2--11--0.000010.11071--:15:fct2(fct2)fct1--22--0.000020.11070--:11:fct1(fct1)+++fct3--11--0.000010.70062--:20:fct3(fct3)fct0--11--0.000010.20048--:7:fct0(fct0)<built-inmethodtime.sleep>--11--0.200470.20047--~:0:<built-inmethodtime.sleep>(<built-inmethodtime.sleep>)+++fct1--11--0.000010.50013--:11:fct1(fct1)+++<built-inmethodtime.sleep>--44--0.811270.81127--~:0:<built-inmethodtime.sleep>(<built-inmethodtime.sleep>)
On this page

[8]ページ先頭

©2009-2025 Movatter.jp