Zend_Db_Profiler 不记录数据库连接时间?

发布于 2024-08-23 03:05:43 字数 2743 浏览 9 评论 0原文

遵循 http://framework.zend.com/manual 上的示例代码/en/zend.db.profiler.html 我已经设置了我的 Zend Framework 应用程序的数据库分析。

application.ini:

db.profiler.enabled = true

视图助手:

$totalTime    = $profiler->getTotalElapsedSecs();
$queryCount   = $profiler->getTotalNumQueries();
$longestTime  = 0;
$longestQuery = null;

foreach ($profiler->getQueryProfiles() as $query) {
    if ($query->getElapsedSecs() > $longestTime) {
        $longestTime  = $query->getElapsedSecs();
        $longestQuery = $query->getQuery();
    }
}

echo 'Executed ' . $queryCount . ' queries in ' . $totalTime . ' seconds' . "\n";
echo 'Average query length: ' . $totalTime / $queryCount . ' seconds' . "\n";
echo 'Queries per second: ' . $queryCount / $totalTime . "\n";
echo 'Longest query length: ' . $longestTime . "\n";
echo "Longest query: \n" . $longestQuery . "\n";

它适用于选择/插入/更新/删除查询。

但我无论如何都找不到让探查器显示启动实际数据库连接所需的时间,尽管文档暗示它确实记录了这一点。

我怀疑 Zend_Db 根本不使用探查器记录与数据库的连接。

有谁知道这是怎么回事?

我正在使用 Oracle 数据库适配器和 ZF 1.10.1

更新:

我了解可以过滤探查器输出,以便它仅显示某些查询类型,例如选择/插入/更新。似乎还有一个仅过滤连接记录的选项:

$profiler->setFilterQueryType(Zend_Db_Profiler::CONNECT);

但是,我的问题是探查器不首先记录连接,因此此过滤器不执行任何操作。

我确实知道这一点,因为如果我打印探查器对象,它包含许多不同查询的数据 - 但没有连接查询的数据:

print_r($profiler);
//output
Zend_Db_Profiler Object
(
    [_queryProfiles:protected] => Array
        (
            [0] => Zend_Db_Profiler_Query Object
                (
                    [_query:protected] => select * from table1
                    [_queryType:protected] => 32
                    [_startedMicrotime:protected] => 1268104035.3465
                    [_endedMicrotime:protected] => 1268104035.3855
                    [_boundParams:protected] => Array
                        (
                        )

                )

            [1] => Zend_Db_Profiler_Query Object
                (
                    [_query:protected] => select * from table2
                    [_queryType:protected] => 32
                    [_startedMicrotime:protected] => 1268104035.3882
                    [_endedMicrotime:protected] => 1268104035.419
                    [_boundParams:protected] => Array
                        (
                        )

                )

        )

    [_enabled:protected] => 1
    [_filterElapsedSecs:protected] => 
    [_filterTypes:protected] => 
)

我做错了什么吗 - 或者连接日志还没有添加到 Zend Framework 中?

Following the sample code on http://framework.zend.com/manual/en/zend.db.profiler.html I have set up db profiling of my Zend Framework app.

application.ini:

db.profiler.enabled = true

View Helper:

$totalTime    = $profiler->getTotalElapsedSecs();
$queryCount   = $profiler->getTotalNumQueries();
$longestTime  = 0;
$longestQuery = null;

foreach ($profiler->getQueryProfiles() as $query) {
    if ($query->getElapsedSecs() > $longestTime) {
        $longestTime  = $query->getElapsedSecs();
        $longestQuery = $query->getQuery();
    }
}

echo 'Executed ' . $queryCount . ' queries in ' . $totalTime . ' seconds' . "\n";
echo 'Average query length: ' . $totalTime / $queryCount . ' seconds' . "\n";
echo 'Queries per second: ' . $queryCount / $totalTime . "\n";
echo 'Longest query length: ' . $longestTime . "\n";
echo "Longest query: \n" . $longestQuery . "\n";

It works fine for select/insert/update/delete queries.

But I cannot find anyway to get the profiler to show the time taken to initiate the actual db connection, despite the documenation implying that it does log this.

I suspect that Zend_Db simply does not log the connection to the db with the profiler.

Does anyone know what is going on here?

I am using the Oracle database adapter, and ZF 1.10.1

UPDATE:

I understand it is possible to filter the profiler output, such that it will only show certain query types, e.g. select/insert/update. There also appears to be an option to filter just the connection records:

$profiler->setFilterQueryType(Zend_Db_Profiler::CONNECT);

However, my problem is that the profiler is not logging the connections to begin with, so this filter does nothing.

I know this for a fact, because if I print the profiler object, it contains data for many different queries - but no data for the connection queries:

print_r($profiler);
//output
Zend_Db_Profiler Object
(
    [_queryProfiles:protected] => Array
        (
            [0] => Zend_Db_Profiler_Query Object
                (
                    [_query:protected] => select * from table1
                    [_queryType:protected] => 32
                    [_startedMicrotime:protected] => 1268104035.3465
                    [_endedMicrotime:protected] => 1268104035.3855
                    [_boundParams:protected] => Array
                        (
                        )

                )

            [1] => Zend_Db_Profiler_Query Object
                (
                    [_query:protected] => select * from table2
                    [_queryType:protected] => 32
                    [_startedMicrotime:protected] => 1268104035.3882
                    [_endedMicrotime:protected] => 1268104035.419
                    [_boundParams:protected] => Array
                        (
                        )

                )

        )

    [_enabled:protected] => 1
    [_filterElapsedSecs:protected] => 
    [_filterTypes:protected] => 
)

Am I doing something wrong - or has logging of connections just not been added to Zend Framework yet?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请你别敷衍 2024-08-30 03:05:43

探查器将连接和其他操作与一般查询“捆绑”在一起。

您可以通过三种方式专门检查连接:

  1. 在设置过程中在探查器上设置过滤器:

    <块引用>

    $profiler->setFilterQueryType(**Zend_Db_Profiler::CONNECT**);
    

    然后生成的配置文件将仅包含“连接”操作。

  2. 检索查询配置文件时指定查询类型:

    <块引用>

    $profiles = $profiler->getQueryProfiles(**Zend_Db_Profiler::CONNECT**);
    
  3. 在迭代期间直接检查查询对象:

    <块引用>

    foreach($profiler->getQueryProfiles() as $query) {
    if ($query->getQueryType() == Zend_Db_Profiler::CONNECT &&
       $query->getElapsedSecs()>; $longestConnectionTime) {
           $longestConnectionTime = $query->getElapsedSecs();
       } 
    }
    

您不会在那里找到详细信息,它只是作为“连接”操作以及所花费的时间进行记录。

The profiler 'bundles' connection and other operations in with the general queries.

There's three ways you might examine the connection specifically:

  1. Set a filter on the profiler during setup:

    $profiler->setFilterQueryType(**Zend_Db_Profiler::CONNECT**);
    

    Then the resultant profiles will only include 'connect' operations.

  2. Specify a query type when you retrieve the Query Profiles:

    $profiles = $profiler->getQueryProfiles(**Zend_Db_Profiler::CONNECT**);
    
  3. Examine the query objects directly during the iteration:

    foreach($profiler->getQueryProfiles() as $query) {
    if ($query->getQueryType() == Zend_Db_Profiler::CONNECT &&
       $query->getElapsedSecs() > $longestConnectionTime) {
           $longestConnectionTime  = $query->getElapsedSecs();
       } 
    }
    

You'll not find great detail in there, it's logged just as a 'connect' operation along with the time taken.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文