K iD ddlZddlmZddlZddlZ ddlZddlm Z ddl Z ddl mZmZddlmZdZdefd Zd Zd Zd Zed ddgZeddddddZedej2j5Dcic] \}}d|| c}}ZeddddddZedej2j5Dcic] \}}d|| c}}ZedddddZiej2j?Dcic]}|ec}Z ddddZ!e jEe!j?Dcic] }|ed e!c}ejFD]PZ$d e$Z%d!e$d"dd#e$d"dd$e$d"diZ&e jEe&j?Dcic] }|ee%e&c}Rd%Z'd&Z(d/d'Z)d(Z*d0d)Z+d*Z,d1d+Z-d,Z.d-Z/e0d.k(re/yy#e $r e dwxYwcc}}wcc}}wcc}wcc}wcc}w)2N) namedtuple) NegationQueryzPFailed to import hatchet. `pip install llnl-hatchet` to get the correct version.)COMPUTE_METADATA_SCOPE_NAME LaunchHook)specscXg}t|ts|g}|ru|D]p}|j}||zD]V}||vrdnd}|jddj j}|||fvsB|j ||zprt |dk(rtdd|S)N (inc)(rzMetric z< is not found. Use the --list flag to list available metrics) isinstancelistlowersplitstripappendlen RuntimeError)metricsinclusive_metricsexclusive_metricsretmetric raw_metricsuffixraw_metric_no_units \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/triton/profiler/viewer.pymatch_available_metricsrs C gt $) F\\^F/2CC  %/3D%D"%/%5%5c%:1%=%C%C%E%K%K%M"j*<==JJzF23    3x1}WVH,hijj Jdatabasec\fdg}|D]}|}||j| |S)Nc,d|vr|S|ddtk(ryt|ddk(rt|ddk(ry|jdg}g}|D]}|}||j| t|dkDst|dk(r||d<|Sy)Nframenamerrchildren)rrgetr)noder$ new_childrenchild new_childremove_frame_helpers rr*z*remove_frames..remove_frame_helper(s $ K = $? ? tI 1 $T*-=)>!)C88J+  /E+E2I$##I. / | q CMQ$6+D Kr)r)r new_databaser&new_noder*s @r remove_framesr-"sD $L*&t,      )* rc(tj|}t|}|jd}tj j |}|j}|jjDcgc] }||vs| }}||||fScc}w)N) jsonloadr-popht GraphFrame from_literalshow_metric_columns dataframecolumns)filer device_infogfrrrs rget_raw_metricsr<BsyyHX&H,,q/K  # #H -B..0.0ll.B.BfFfTeFeff  "3[ @@gs 9 BBc tjd|jdg}|D]}||D]}|||d}|||d}|||d}tjD]k}|d|k(} || } d|| j vr"t j|||||} |j| dfxx| d|jd | z z cc<m|S) Nmin_timeindexr8archnum_sms clock_rate device_idflopsr) pd DataFramerAr flops_widthr8r max_flopslocfillna) dfr:min_time_flops device_type device_indexrBrCrDwidthidx device_framesrJs rget_min_time_flopsrTLs\\#RXX |LN" l ' 4 lL{+L9&AD!+.|r?r@rEmemory_clock_rate bus_widthrBbytes)rGrHrArmax_bpsrK) rMr:min_time_bytesrOrPrRrSdevicerVrWpeak_bandwidths rget_min_time_bytesr]]s\\#RXX |LN"[ ' 4 [L[/\1CsGM -l;F &': ; {+I"]];v SdeN   sJ /=3IN3Z Z / [[ r FactorDictr#factortimer/gMbP?gư>g& .>)ztime/sztime/msztime/usztime/nsavg_timeavg_cpu_time)z cpu_time/sz cpu_time/msz cpu_time/usz cpu_time/ns avg_cpu_timerXgeAgmB)zbyte/szgbyte/sztbyte/s)zflop/szgflop/sztflop/srFflopz/sgfloptflopcg}fd}|D]}|dk(rt|j|}t|j|} ||jdt} |jdj } | dj |dt | z |jd<tj|jj| df<|jd|tvrt|} | j} | j}t| d}|j|||jdtz ||z |j|d<|j|d^|tjvs6|tjvs$|t jvs|t"jvr|tjvxs|t"jv}|t jvxs|t"jv}|r|rt"ntn |rt nt}|rdnd} |jd z|j%d d z}||j| |}|r||jd z }||j|z |j|d<|j|d|j%d }|d} t'|d kDr|d }|d k7rt)d |t| d}|j|}d}d|vrd}|j|j*d}n|j|j-}||z dz|j||z<|j||zet| d}|j||D]J}|j/dr|j0j|0|j2j|L|S)Nct|d}|jdz|jddjddz}|||j|zS)Nr/r r/))rr#rr_)rMr factor_dicttime_metric_name time_unitrrs rget_time_secondsz(derive_metrics..get_time_secondssn26;LN_`abc$$s*-=-C-CC-H-K-Q-QRU-VWX-YY "#k&8&8&CCCrutilr`rEr?rr rcrjr/z count (inc)%zUnsupported unit r z(inc)gY@)r]r7rTtime_factor_dictisnacombinemaxnpnanrKrderivable_metricsr#r_rcpu_time_factor_dictavg_time_factor_dictavg_cpu_time_factor_dictrr ValueErrorilocsumendswith inc_metrics exc_metrics)r;rrrr:derived_metricsrorrZrNtime_secinternal_frame_indicesderivable_metric metric_namemetric_factor_dictmatched_metric_nameis_cpuis_avgrlmetric_time_unit time_valuemetric_name_and_unit metric_unit single_framertotalderived_metrics `` rderive_metricsrsOD 5< V / kJN/ kJN' f>NOH%'\\+%>%C%C%E "#1*#=#E#EnU_F`be#fiq#qBLL ?AvvBLL  3V; <  " "6 * ( (08 *//K!1!8!8 "9+GXZk"lmn"o /1||gF3:::gfH`HgHg>gF]c4DX4:0@P (.*FK*//#5 S8I!8LL )",, [QJ'",,}*EE .8;;M;MN^;_._BLLF86* +  " "fXV#4 5#)<<#4 .q1K'(1,215 #%$'8 %FGG&=kK\^o&pqr&s#!||,?@ 11%FLL)<=BB1EELL)<=AACE1=1E0N Vf_-&&v7&=kK\^o&pqr&s#&&':;k5zformat_frames..AGGCLQSDTr function_linec*|jddS)N:rrrs rrzformat_frames..rr file_functionc|jddjddd|jddjddS)Nrjrrr@rrs rrzformat_frames..sOb)//4Q78!''#,r:J:P:PQT:UVW:X9YZr)r7apply)r;formats r format_framesrs %%!||F399:TU V I ? "!||F399:TU V I ? "!||F399 Z \ V Irc|rd|d}|j|d}|r$d|d}t|}|j|d}|rd|d|ig}|j|d}|S)Nz1 MATCH ("*")->(".", p)->("*") WHERE p."name" =~ "z" T)squashz* MATCH (".", p)->("*") WHERE p."name" =~ "*z>= )filterr)r;includeexclude thresholdrqueryinclusion_querys r filter_framesrs9YYuTY *9o. YYuTY *vYK012 YYuTY * Ircd|vr@|jdj}tj|}|dkr t dyyy)Nz bytes (inc)rzZWarning: Negative byte values detected, this is usually the result of a datatype overflow )r7valuesrvnanminprint)r;r byte_valuesmin_byte_values r emit_warningsrsGll=188 ;/ A  o p  rc t||}t|j|d|d|rtd|dz|jj |dgd}t dt |D]x}t |j|dd kDr|j|ddd d zn|j|d}td j||j||dzt||y) NTF) metric_column expand_namedepth render_headerzSorted kernels by metric r)by ascendingr/r#dz...z {:105} {:.4}) rrtreer7 sort_valuesrangerr}rr)r;rrr print_sorted sorted_dfrow kernel_names r print_treers r6 "B "''TV[' \] )GAJ67LL,, ,N C N+ WC$' s(;F(C$Ds$J%>>#.v6t< !PYP^P^_bPcdjPk  .'' Y^^C5HQR5TU V W"grct|d5}t|\}}}}t||zdkDsJd|j||||fcdddS#1swYyxYw)Nrrz"No metrics found in the input file)openr<rupdate_inclusive_columns)filenamefr;rrr:s rreadrsw h E@OPQ@R= 0+$'889A=c?cc= ##%$&7D EEEs >AAclt|\}}}}t|||||}t|||||d}||fS)Nr)rrr) rrrrrr;rrr:s rparser sK<@N9B,kR*;=NP[\G r7GY CB w;rct|d5}t|\}}}}td|rE|D]@}|jddj j }td|Btd|rE|D]@}|jddj j }td|Bdddy#1swYyxYw)NrzAvailable inclusive metrics:r rz- zAvailable exclusive metrics:)rr<rrrr) file_namer_rrrrs r show_metricsrs i  15DQ5G2 / ,- / 1 %/%5%5c%:1%=%C%C%E%K%K%M"-./0 1 ,- / 1 %/%5%5c%:1%=%C%C%E%K%K%M"-./0 1 1 1 1s B5C  CcHtjdtj}|jdddd|jdd tdd |jd d tdd |jddtdd |jddt dd |jddt dd |jddtgddd|jddd d!"|jd#d$tdd% |j\}}t|d&k(sJd'|d(}|jr|jjd)nd}|j}|j}|j}|j}|j} |j } |j"} |r |r t%d*|j&r t)|y|rGt+|||||\} } | r#t+|| |||\}}| j-|} t/| | || | yy)+Nz,Performance data viewer for proton profiles.) descriptionformatter_classz-lz--list store_truea-List available metrics. Metric names are case insensitive and ignore units. Derived metrics can be created when source metrics are available. - time/s, time/ms, time/us, time/ns: time - avg_time/s, avg_time/ms, avg_time/us, avg_time/ns: time / count - flop[<8/16/32/64>]/s, gflop[<8/16/32/64>]/s, tflop[<8/16/32/64>]/s: flops / time - byte/s, gbyte/s, tbyte/s: bytes / time - util: max(sum(flops) / peak_flops_time, sum(bytes) / peak_bandwidth_time) - /%%: frame(metric) / sum(metric). Only available for inclusive metrics (e.g. time) )actionhelpz-mz --metricszAt maximum two metrics can be specified, separated by comma. There are two modes: 1) Choose the output metric to display. It's case insensitive and ignore units. 2) Derive a new metric from existing metrics. )typedefaultrz-iz --includeaFind frames that match the given regular expression and return all nodes in the paths that pass through the matching frames. For example, the following command will display all paths that contain frames that contains "test": ``` proton-viewer -i ".*test.*" path/to/file.json ``` z-ez --excludezExclude frames that match the given regular expression and their children. For example, the following command will exclude all paths starting from frames that contains "test": ``` proton-viewer -e ".*test.*" path/to/file.json ``` z-tz --thresholdzrExclude frames(kernels) whose metrics are below the given threshold. This filter only applies on the first metric.z-dz--depthrz The depth of the tree to displayz-fz--format)fullrrrra!Formatting the frame name. - full: include the path, file name, function name and line number. - file_function_line: include the file name, function name and line number. - function_line: include the function name and line number. - file_function: include the file name and function name. )rchoicesrrz--print-sortedFz6Sort output by metric value instead of chronologically)rrrz--diff-profilez-diffzCompare two profiles. When used as 'proton-viewer -m time -diff file1.log file2.log', computes the difference: file2['time'] - file1['time']r/zMust specify a file to readr,z'Cannot specify both include and exclude)argparseArgumentParserRawTextHelpFormatter add_argumentstrfloatintparse_known_argsrrrrrrrr diff_profilerr|r rrsubr) argparserargs target_argsrrrrrrrdiffrr;rgf2rs rmainr"sw''B 55I                  |    /   P   E   A "224D+ { q ?"?? AI)-dll  %4GllGllGI JJE [[F   D$$L7BCC yyY #GY)TO 7D'7IFFCB2v|D r__main__)NNNN)rNF)NNN)1r collectionsrr0pandasrGhatchetr3 hatchet.queryr ImportErrornumpyrvtriton.profiler.hooks.launchrrtriton.profilerrrr-r<rTr]r^rrr_itemsrzryr{bytes_factor_dictkeysrxdefault_flop_factor_dictupdaterIrQ factor_namerlrrrrrrrrr__name__)keyvalues00rrs" j+P!$D@A"  vx&8 9 ftPTae&fg!*UeUlUlUrUrUt.uzsEcU|U/B.uv!*124X\mq"rt%n9M9T9T9Z9Z9\'^+53*.cU|U':'^_w1QU(VW#**//13  3 '(CDI(--/1  *W6 7712 # #hE%/K%#Q%wb(93%wb@QSWXKS^ScScSefCc:k;#GGfgh FR(q E 1wEt zFg j h iijH/v'^ 31 gs) G;G( G.  G44G9G> G%