Yii Framework Forum: Profiling and logging - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Profiling and logging how to handle it by hand Rate Topic: -----

#1 User is offline   The Peach 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 08-October 09
  • Location:London, UK

Posted 08 March 2010 - 09:52 AM

Hello all
I'm working on a couple of controllers that mainly output JSON strings
Since I need to check the timings of calls, memory usage, sql calls and all the bits to see how much the code has to be improved I was looking into adding some profiling and logging into the json output.

So I started adding a new CProfileLogRoute to the main configuration but as I was noticing its summary is a table that is rendered through CController->render() that is something I don't really need.

Then I added these bits of code in my controller:
    public function beforeAction($action) {
        parent::beforeAction($action);
        $this->connection = Yii::app()->db;
        if (YII_DEBUG) {
            $this->logger = new CLogger();
        }
        return true;
    }
    private function afterAction($action) {
        parent::afterAction($action);
        if (YII_DEBUG) {
            $this->logger->flush();
        }
        return true;
    }

and in each action something like:
    public function actionX() {
        // main action code
        // ...
        if(YII_DEBUG) {
            $outConfArr['profile']['executionTime']=$this->logger->getExecutionTime();
            $outConfArr['profile']['memoryUsage']=$this->logger->getMemoryUsage();
        }
        Utils::outputJson($outConfArr);
    }

where the outputJson does nothing but sending out the right mime header and calling json_encode($array).

Since now this works well (probably I need some class adjustments but that's not a problem at all), I was looking forward profiling the bits of code as Yii::beginProfile('stmt') and Yii::endProfile('stmt') does and then outputting it via $this->logger->getProfilingResults() but I can't make it and that's the reason I came here.

Plus... do I really need the CProfileLogRoute to be enabled?
and how do I profile the sql calls and output them properly in my JSON ?

Thanks for any hints you can give me.
Cheers
0

#2 User is offline   The Peach 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 08-October 09
  • Location:London, UK

Posted 10 March 2010 - 08:57 AM

anyone?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users