rah/rah_runtime

诊断 Textpattern CMS 模板执行时间

安装: 0

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 3

分支: 0

公开问题: 0

类型:textpattern-plugin

dev-master 2013-09-25 08:18 UTC

This package is auto-updated.

Last update: 2024-09-15 12:58:02 UTC


README

主页 | Packagist | Twitter | GitHub | 支持论坛 | 捐赠

Rah_runtime 返回 A 到 B 点的运行时间,以微秒为单位。该插件可用于诊断 Textpattern 标记代码的特定块的运行时间。

基础

<txp:rah_runtime format="1">
    ...contained statements...
</txp:rah_runtime>

该插件引入了一个新的 Textpattern 标签,<txp:rah_runtime />。该标签计算 Textpattern 模板标记的执行时间,运行时间可以打印到页面模板,并添加到标签跟踪中。

rah_runtime 标签既可以作为容器使用,也可以作为自闭合单标签使用。当标签作为容器使用时,它计算包装代码的运行时间。当作为自闭合单标签使用时,它计算从第一个标签实例到第二个实例的运行时间。

属性

<txp:rah_runtime/> 标签的属性如下。

return
如果设置为 1,则标签将输出运行时间到页面模板。如果为 0,则运行时间仅在站点处于调试模式时添加并可见于页面的 标签跟踪中。默认情况下 return0,运行时间仅添加到标签跟踪中。
示例: return="1" 默认: "0"

format
返回时间格式的版本。当使用时,结果值(浮点数)将呈现为固定的小数。默认情况下使用该选项(1)。
示例: format="0" 默认: "1"

index
使用此属性可以嵌套多个标签对并计算多个独立的运行时间。当使用 <txp:rah_runtime /> 作为自闭合单标签时,index 属性仅适用。
示例: index="articles" 默认: "default"

persistent
如果设置为 1,则运行时间在返回后保持活跃。通常在使用后销毁运行时间对,但使用 persistent 后,初始运行时间将保持并仍然可用。该属性在您想从相同的单个起始点计算多个运行时间时很有用。当使用 <txp:rah_runtime /> 作为自闭合单标签时,persistent 属性仅适用。
示例: persistent="1" 默认: "0"

示例

作为容器使用

作为容器,rah_runtime 计算包装内容的运行时间。

<txp:rah_runtime>
    <txp:article_custom />
</txp:rah_runtime>

上述代码将返回包含语句的结果,就像没有使用 rah_runtime 一样,并且包含语句的运行时间将添加到页面的 标签跟踪中。标签跟踪应显示类似以下行

[rah_runtime (default): 0.000010013580322]

作为单标签使用

当 rah_runtime 标签作为单个自闭合标签使用时,运行时间从 <txp:rah_runtime/> 标签实例计算到下一个实例。本质上,运行时间是两个 <txp:rah_runtime/> 标签之间的标记和代码的运行时间。

<txp:rah_runtime />
    <!--
        Some code here, for example:
        <txp:article />
    -->
<txp:rah_runtime />

上述代码将返回所有标记,就像没有 rah_runtime 的痕迹一样,运行时将以类似以下方式添加到页面的标签跟踪中:

[rah_runtime (default): 0.000010013580322]

将运行时返回到页面

通常,生成的运行时会被添加到 标签跟踪 中,并且在正常页面内容中不可见。除非 return 属性设置为 1

<txp:rah_runtime />
Runtime: <txp:rah_runtime return="1" />

运行时将被添加到标签跟踪,上述代码将返回

Runtime: 0.00021401458032

使用多级嵌套标签对

rah_runtime 标签的 index 属性可以用来嵌套和混合多个 <txp:rah_runtime/> 标签和运行时对,这允许计算重叠的运行时。

<txp:rah_runtime index="2" />
<txp:rah_runtime index="1" />
Time1: <txp:rah_runtime index="1" return="1" />
Time2: <txp:rah_runtime index="2" return="1" />

上述代码将返回两个运行时

Time1: 0.000081
Time2: 0.000184

time2 包含 time1 的运行时以及更多。

使用持久化运行时

当需要从相同的起点计算多个运行时,持久化运行时非常有用。

<!--
    Starting the runtime timer
-->

<txp:rah_runtime persistent="1" return="1" />


<!--
    Some code here, for example <txp:article /> ...
    then output a (first) runtime
-->

<txp:rah_runtime persistent="1" return="1" />

<!--
    Some more code here, for example
    <txp:output_form form="myform" />

    Output runtime, calculated
    from the same original starting point
-->

<txp:rah_runtime persistent="1" return="1" />

<!--
    Even some more code.
    Finally, return the final runtime still calculated 
    from the same original starting point.
-->

<txp:rah_runtime return="1" />

请注意,每个 rah_runtime 标签(除了最后一个)都将 persistent 属性设置为 1。如果没有设置该属性,则运行时对在返回后将被销毁。要最终销毁运行时,请将 persistent 设置为 "0"(零)或将其留为未定义。

变更日志

版本 0.5.0 – 即将推出

  • 更新:帮助文件。

版本 0.4 – 2012/07/12

  • 新增:return 属性。
  • 新增:现在运行时被添加到标签跟踪中。
  • 新增:支持容器标签模式。
  • 更改:默认情况下,运行时仅在标签跟踪中可见。将 return 属性设置为 1return="1")以输出运行时到页面模板。
  • 更改:默认 index 更改为 default。这是为了避免潜在的类型转换副作用。

版本 0.3 – 2011/08/19

  • 新增:一个新的属性 persistent。禁用已使用运行时对的销毁。
  • 更改:现在将运行时存储在静态变量中而不是全局变量中。

版本 0.2 – 2010/06/18

版本 0.1 – 2010/06/15

  • 首次发布。