Profiling and logging

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

anyone?