From zeta-dev-return-287-apmail-incubator-zeta-dev-archive=incubator.apache.org@incubator.apache.org Sun Aug 29 12:16:54 2010 Return-Path: Delivered-To: apmail-incubator-zeta-dev-archive@minotaur.apache.org Received: (qmail 35816 invoked from network); 29 Aug 2010 12:16:54 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 29 Aug 2010 12:16:54 -0000 Received: (qmail 13026 invoked by uid 500); 29 Aug 2010 12:16:54 -0000 Delivered-To: apmail-incubator-zeta-dev-archive@incubator.apache.org Received: (qmail 12951 invoked by uid 500); 29 Aug 2010 12:16:52 -0000 Mailing-List: contact zeta-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: zeta-dev@incubator.apache.org Delivered-To: mailing list zeta-dev@incubator.apache.org Received: (qmail 12943 invoked by uid 99); 29 Aug 2010 12:16:51 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 29 Aug 2010 12:16:51 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of giunta.gaetano@gmail.com designates 74.125.82.175 as permitted sender) Received: from [74.125.82.175] (HELO mail-wy0-f175.google.com) (74.125.82.175) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 29 Aug 2010 12:16:27 +0000 Received: by wyg36 with SMTP id 36so5157356wyg.6 for ; Sun, 29 Aug 2010 05:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=ChoMleQQ7bopMi8/YbXS7HJgCORgdkos6vRFbb85kpo=; b=Iz2MElJkUCyKrS7om93U/ZdpOnHHESSh8arL3o7fIxf6AMgqE7kqsfnAw+Y8XJailq E5siP0CvGDzmg38tdkweXaTpTwaWkRWBHP324AcYYH8FSTn7VIblwW+V1jrqnIsbfNlR H0OaXKsx92RuyRmOABqeg5EN2oDBo0jEIWa5Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=JTSSlTJVlPEROHRufPy8VCaIP3KBqMqRYGZ6+9qTkXaEOMpkXGDwjuAvqKqZOGXwmH GN8K/7Y1DiOEnwFZbQF2IjfMfjO7trwEGj4x69nkeIbhjpep+ljPXbnbBzTrn7jwuE5C uZVzaPl2aM9bBzZ3hhzaZnTIVYPxPvifbZ4Tg= Received: by 10.216.188.81 with SMTP id z59mr3463120wem.106.1283084167136; Sun, 29 Aug 2010 05:16:07 -0700 (PDT) Received: from [192.168.0.10] (jem75-9-88-175-95-132.fbx.proxad.net [88.175.95.132]) by mx.google.com with ESMTPS id l55sm3739371weq.17.2010.08.29.05.16.05 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 29 Aug 2010 05:16:06 -0700 (PDT) Message-ID: <4C7A4F84.1020107@gmail.com> Date: Sun, 29 Aug 2010 14:16:04 +0200 From: Gaetano Giunta User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2 MIME-Version: 1.0 To: zeta-dev@incubator.apache.org References: <4C7A47F6.3090301@andreass.net> In-Reply-To: <4C7A47F6.3090301@andreass.net> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Subject: Re: [zeta-dev] Profiler for db component Andreas Schamberger wrote: > Hi, > > I already posted this a year ago on the old ezc mailing list. There was no feedback. So I'll start another attempt here ... > > I was annoyed by not being able to analyze my query execution times. What I want is a profiler that transparently collects the data without adding anything to > my code base. My solution: A new ezcDbHandler implementation as a proxy for the real db handler instance. The new db handler configures a custom PDOStatement > that collects the profiling information and a backtrace of the query. > > I also added the ability to get a prepared SQL string by caching the bindValue/bindParam data in the custom statement class to get a complete query for > debugging. This is also great for doing EXPLAIN by just copy/pasting the queries. > > It was developed with the objective of zero changes to the existing db component code. > > The profiler can simply be added like this: > > $dsn = 'mysql://....'; > if ( ezcBase::inDevMode() ) > { > ezcDbInstance::set( ezcDbFactory::create( $dsn ), > 'mysql_for_profiler' ); > $dbh = ezcDbFactory::create( 'profiler://mysql_for_profiler' ); > // uses ezcDbInstance::get( 'mysql_for_profiler' ) internally > } > else > { > $dbh = ezcDbFactory::create( $dsn ); > } > ezcDbInstance::set( $dbh ); > > // ... > > $dbh = ezcDbInstance::get(); > if ( ezcBase::inDevMode() && $dbh instanceof ezcDbProfiler ) > { > // dump the array of ezcDbProfilerData structs > var_dump( $dbh->getProfilingInformation() ); > } > > The new handler implements: > > interface ezcDbProfiler > { > public function getProfilingInformation(); > public function logProfilingInformation( $query, $duration, > $group=null ); > // group is used to group by unprepared statements > } > > I'd like to contribute the attached profiler code if there is interest in it. > > Regards, > Andreas A couple of notes: . the replacing of 'SELECT' in mysql selects in db_handler_profiler.php might be too greedy: what about columns called SELECTOR? . baking in support for EXPLAIN PLAN into this class (or a subclass) would make it more interesting. You can take a look at ezdb: it already implements 'explain' for both mysql and oracle bye Gaetano