Changes

Jump to navigation Jump to search
3,606 bytes added ,  13:23, 24 May 2018
no edit summary
This [[Module Library|XQuery Module]] contains various functions for XQuery to test and profile code, and to dump information to standard output.
=Conventions=
All functions and errors in this module are assigned to the {{Code|<code><nowiki>http://basex.org/modules/prof}} </nowiki></code> namespace, which is statically bound to the {{Code|prof}} prefix.<br/>All errors are assigned to the {{Code|http://basex.org/errors}} namespace, which is statically bound to the {{Code|bxerr}} prefix.
=Performance Functions=
==prof:timetrack==
{| width='100%'
|-
| width='90120' | '''Signatures'''|{{Func|prof:timetrack|$expr expression as item()|item()*}}<br />{{Func|prof:timetrack|$expr expression as item(), $cache options as xs:boolean|itemmap()*}}<br />{{Func|prof:time|$expr as item(), $cache as xs:boolean, $label as xs:string?|item()*}}
|-
| '''Summary'''
|Measures the execution time needed to evaluate and memory consumption required for evaluating the specified {{Code|$exprexpression}} and sends it to standard error or, if returns a map with the GUI is used, to the Info Viewresults.<br />If The following {{Code|$cacheoptions}} is set to are available:* {{Code|memory}}: Include memory consumption in result (unit: bytes; default: true).* {{Code|time}}: Include execution time in result (unit: milliseconds; default: true).* {{Code|value}}: Include value in result (default: true).Helpful notes:* If you are not interested in some of the returned results, you should disable them to save time and memory.* Profiling might change the result execution behavior of your code: An expression that might be executed iteratively will be temporarily cachedby the profiling function. This way* If a value has a compact internal representation, a potential iterative execution of memory consumption will be very low, even if the expression (which often yields different serialized result may consume much more memory.* Please note that memory usage) profiling is blockedonly approximative, so it can be quite misleading.<br/>A thirdIf the memory option is enabled, optional argument {{Codemain-memory will be garbage-collected before and after evaluation to improve the quality of the measurement.|-| '''Properties'''|$label}} may The function is ''non-deterministic'': evaluation order will be specified to tag preserved by the profiling resultcompiler.
|-
| '''Examples'''
|
* {{Code|Return a human-readable representation of the memory consumption caused by fetching an XML document (<code>fetch:xml</code> is used, as <code>fn:doc</code> may already be evaluated at compilation time):<pre class="brush:xquery">prof:track(fetch:xml('factbook.xml'))?memory=> prof:human()</pre>* The function call <code>prof:track((1 to 1000000)[. mod 2 = 0], map { 'time': false() })</code> will return something similar to:<pre class="1 to 100000brush:xquery">map { "memory": 21548400, "value": (2, 4, 6, 8, 10, ...)}</pre>|} may output  ==prof:time== {| width='100%'|-| width='120' | '''Signatures'''|{{CodeFunc|prof:time|$expr as item()|25.69 msitem()*}}.* <br />{{CodeFunc|prof:time|$expr as item("1 to 100000"), true$label as xs:string|item())*}}|-| '''Summary'''|Measures the time needed to evaluate {{Code|$expr}} may output and outputs a string to standard error or, if the GUI is used, to the Info View. An optional {{Code|208$label}} may be specified to tag the profiling result.12 msSee {{Function|Profiling|prof:track}}for further notes.
|-
| '''Properties'''
|The function is ''non-deterministic'': evaluation order will be preserved by the compiler.
|-
| '''Examples'''
|
* {{Code|prof:time(prof:sleep(1000))}} outputs something similar to {{Code|1000.99 ms}}.
|}
==prof:memmemory==
{| width='100%'
|-
| width='90120' | '''Signatures'''|{{Func|prof:memmemory|$expr as item()|item()*}}<br />{{Func|prof:memmemory|$expr as item(), $cache as xs:boolean|item()*}}<br />{{Func|prof:mem|$expr as item(), $cache as xs:boolean, $label as xs:string|item()*}}
|-
| '''Summary'''
|Measures the memory allocated by evaluating {{Code|$expr}} and sends it outputs a string to standard error or, if the GUI is used, to the Info View.<br />If An optional {{Code|$cachelabel}} is set may be specified to {{Code|true()}}, tag the profiling result will be temporarily cached. This way, a potential iterative execution of the expression (which often yields different memory usage) is blocked.<br/>A third, optional argument See {{CodeFunction|Profiling|$labelprof:track}} may for further notes.|-| '''Properties'''|The function is ''non-deterministic'': evaluation order will be specified to tag preserved by the profiling resultcompiler.
|-
| '''Examples'''
|
* {{Code|prof:mbmemory("1 to 100000")}} may output {{Code|0 Bytes}}.* {{Code|prof:mb("1 to 100000", true()! <a/>)}} may will output something similar to {{Code|26.678 mb5620 kB}}.|-| '''Properties'''|The function is ''non-deterministic'': evaluation order will be preserved by the compiler.
|}
==prof:sleepcurrent-ms==
{| width='100%'
|-
| width='90120' | '''Signatures'''|{{Func|prof:sleepcurrent-ms||$ms as xs:integer|empty-sequence()*}}<br />
|-
| '''Summary'''
|Sleeps for Returns the specified number of milliseconds passed since 1970/01/01 UTC. The granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.
|-
| '''Properties'''
|The In contrast to {{Code|fn:current-time()}}, the function is ''non-deterministic'': and returns different values every time it is called. Its evaluation order will be preserved by the compiler.|-| '''Examples'''|* {{Code|convert:integer-to-dateTime(prof:current-ms())}} returns the current miliseconds in the {{Code|xs:dateTime}} format.
|}
==prof:humancurrent-ns== {{Mark|Introduced with Version 7.5.1:}}
{| width='100%'
|-
| width='90120' | '''Signatures'''|{{Func|prof:humancurrent-ns||$number as xs:integer|xs:string}}<br />
|-
| '''Summary'''
|Returns a human-readable representation the current value of the specified most precise available system timer in nanoseconds.|-| '''Properties'''|In contrast to {{Code|$numberfn:current-time()}}, the function is ''non-deterministic'' and returns different values every time it is called. Its evaluation order will be preserved by the compiler.
|-
| '''ExampleExamples'''|{{Code|Measures the time of an expression:<pre class="brush:xquery">let $ns1 := prof:current-ns()return ( (: process to measure :) (1 to 1000000)[. = 0], let $ns2 := prof:humancurrent-ns() let $ms := (16384(($ns2 - $ns1)}} returns {{Codeidiv 10000) div 100) return $ms |16K}}.| ' ms')</pre>
|}
 
=Debugging Functions=
==prof:dump==
 
{{Mark|Introduced with Version 7.5:}}
{| width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|prof:dump|$expr as item()|empty-sequence()}}<br />{{Func|prof:dump|$expr as item(), $label as xs:string|empty-sequence()}}<br />
|-
|}
==prof:variables== {| width='100%'|-| width='120' | '''Signatures'''|{{Func|prof:variables||empty-sequence()}}|-| '''Summary'''|Prints a list of all currentlocal and global variable assignments to standard error or, if the GUI is used, to the Info View.<br />As every query is optimized before being evaluated, not all of the original variables may be visible in the output. Moreover, many variables of function calls will disappear because functions are inlined. Function inlining can be turned off by setting the [[Options#INLINELIMIT|INLINELIMIT]] option to <code>0</code>.|-| '''Properties'''|The function is ''non-deterministic'': evaluation order will be preserved by the compiler.|-| '''Examples'''|* {{Code|for $x in 1 to 2 return prof:variables()}} will dump the values of <code>$x</code> to standard error.|} ==prof:type== {| width='100%'|-| width='120' | '''Signatures'''|{{Func|prof:type|$expr as item()*|item()*}}|-| '''Summary'''|Similar to {{Code|fn:trace($expr, $msg)}}, but instead of a user-defined message, it emits the compile-mstime type and estimated result size of its argument.|} =Helper Functions=
{{Mark|Introduced with Version 7.5==prof:}}void==
{| width='100%'
|-
| width='90120' | '''Signatures'''|{{Func|prof:current-msvoid|$value as item()*|xs:integerempty-sequence()}}<br />
|-
| '''Summary'''
|Returns the number of milliseconds passed since 1970/01/01 UTC. The granularity Swallows all items of the specified {{Code|$value depends on the underlying operating system }} and may returns an empty sequence. This function is helpful if some code needs to be larger. For example, many operating systems measure time in units of tens of millisecondsevaluated and if the actual result is irrelevant.
|-
| '''Properties'''
|In contrast to {{Code|fn:current-time()}}, the The function is ''non-deterministic'', as it returns different values every time it is called. Its : evaluation order will be preserved by the compiler.|-| '''Examples'''|* {{Code|prof:void(fetch:binary('http://my.rest.service'))}} performs an HTTP request and ignores the result.
|}
==prof:currentsleep== {| width='100%'|-ns=| width='120' | '''Signatures'''|{{Func|prof:sleep|$ms as xs:integer|empty-sequence()}}<br />|-| '''Summary'''|Sleeps for the specified number of milliseconds.|-| '''Properties'''|The function is ''non-deterministic'': evaluation order will be preserved by the compiler.|}
{{Mark|Introduced with Version 7.5==prof:}}human==
{| width='100%'
|-
| width='90120' | '''Signatures'''|{{Func|prof:current-nshuman|$number as xs:integer|xs:integerstring}}<br />
|-
| '''Summary'''
|Returns the current value a human-readable representation of the most precise available system timer in nanosecondsspecified {{Code|$number}}.
|-
| '''PropertiesExample'''|In contrast to * {{Code|fnprof:current-timehuman(16384)}}, the function is ''non-deterministic'', as it returns different values every time it is called. Its evaluation order will be preserved by the compiler{{Code|16K}}.
|}
=Changelog=
;Version 79.0 * Added: [[#prof:track|prof:track]]* Updated: renamed prof:mem to [[#prof:memory|prof:memory]] ;Version 8.5 * Added: [[#prof:type|prof:type]] (moved from [[XQuery Module]]) ;Version 8.1 * Added: [[#prof:variables|prof:variables]] ;Version 7.7 * Added: [[#prof:void|prof:void]]
;Version 7.6 * Added: <code>[[#prof:human|prof:human]]</code>
;Version 7.5
* Added: <code>[[#prof:dump|prof:dump]]</code>, <code>[[#prof:current-ms|prof:current-ms]]</code>, <code>[[#prof:current-ns|prof:current-ns]]</code>
This module was introduced with Version 7.3.
 
[[Category:XQuery]]
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu