0

I am writing a backend function for loading a profile on android app, want to figure out why its slow , and taking more time to load so want to debug the load time of each query in function how can I ?

  $collection = Mage::getModel("manager/campus")->getCollection()
                                                              ->addFieldToFilter('regionalmanager',array('finset' => $arr))
                                                              ->addFieldToFilter('status', array('eq' => 1));
                foreach ($collection as $collegename)
                {
                    array_push($college, $collegename->getId());
                    array_push($colnames, $collegename->getName());
                    if ($collegename->getCampusmanager() != "")
                    {
                        $ids = explode(",", $collegename->getCampusmanager());
                        $campusmanager = array_merge($campusmanager, $ids);

                    }
                }
                $customerids = Mage::getModel("customer/customer")->getCollection()
                                                                  ->addAttributeToSelect('firstname')
                                                                  ->addAttributeToFilter('grisk_college_new_id', array('in' =>$college))
                                                                  ->getAllIds();

                $order = Mage::getModel('sales/order')->getCollection()
                                                      ->addFieldToFilter('customer_id',array('in' => $customerids));

                $delayedcollectioncount = "SELECT * FROM ".$resource->getTableName('customer/customer').










                $delayedcollectioncount = Mage::getModel("customer/customer")
                                                                    ->getCollection()
                                                                    ->addAttributeToSelect('firstname, entity_id')
                                                                    ->addAttributeToFilter('grisk_college_new_id', array('in' =>$college))
                                                                    ->addFieldToFilter('group_id', array('in' => array(4,5)))
                                                                    ->addAttributeToFilter('assigned_campus_manager', array('null' => true), 'left')
                                                                    ->addAttributeToFilter('physical_verify', array('null' => true), 'left')
                                                                    ->addFieldToFilter('grisk_pv_upload_date', array('lt' => date("Y-m-d H:i:s", strtotime($configValue))))
                                                                    ->addAttributeToSort('grisk_pv_upload_date', 'DESC')
                                                                    ->count();
                //Collection by status.
                $verifycollectioncount = $this->getVerifyListForAsm($CollegeIds,$page);            
                $verifycollectioncount = $verifycollectioncount->count();

                $penddingconfirmation = $this->getPendingConfirmationForAsm($CollegeIds,$custid, $page);         
                $penddingconfirmation = $penddingconfirmation->count();

                $reverifycollectioncount = $this->getReverifyCollectionForAsm($CollegeIds,$custid, $page);
                $reverifycollectioncount = $reverifycollectioncount->count();

                $OrderStudent = Mage::getModel("customer/customer")->getCollection()
                                                                  ->addAttributeToSelect('firstname, entity_id')
                                                                  ->addAttributeToFilter('grisk_college_new_id',array('in' => $college))
                                                                  ->addFieldToFilter('group_id', array('in' => array(4,5,6)));

                $HighPri = $custidArray = $OrderFull = $OrderPPnOA = $OrderPPnOP =  array();
                foreach ($OrderStudent as $each)
                {
                    $custidArray[] = $each->getId();
                }
                    /** **High priority*  **/
                $totorders = Mage::getResourceModel('sales/order_collection')
                                                ->addFieldToSelect('*')
                                                ->addFieldToFilter('customer_id', array('in' => $custidArray))
                                                ->addFieldToFilter('payment_status', array('in' => array('Paid','Partial')))
                                                ->addFieldToFilter('loan_document_status', 'Not signed')
                                                ->addFieldToFilter('facility_loan_type', 'Facility');
                foreach($totorders as $orders):

                    $LfaStatus = '';
                    $checkLfa  = Mage::getModel("customer/customer")->load($orders->getCustomerId());
                    $LfaStatus = $checkLfa->getGriskFacilityStatus();
                    if($LfaStatus==NULL || $LfaStatus=='' || $LfaStatus=='Not signed')
                    {
                        $HighPri[$orders->getId()]=$orders->getCustomerId();
                    }else
                    {
                        $orders->setLoanDocumentStatus($LfaStatus);
                        $orders->save();
                    }
1
2

There are 3 ways as per my knowledge. May be more... not sure though.

Magento's Way

1) Go to lib/Varien/Db/Adapter/Pdo/Mysql.php set $_debug to TRUE and set $_logAllQueries to TRUE. Now in this var/debug/pdo_mysql.log file all your queries will be logged and you will know which is taking how much time.

2) Enable compiler from backend and it will show you per controller basis.(Never used it though and not sure properly.)

PHP's way

3) Use

$start = microtime(true); // when function starts
       $end = microtime(true); // when function ends
      $end - $start = will give you exact time a function is taking to load.
1
0
                     $my_timer = microtime();
                    $time_parts = explode(' ', $my_timer);
                    $time_right_now = $time_parts[1] + $time_parts[0];
                    $starting_time = $time_right_now;


// write your function or collection ;


 $my_timer = microtime();
                    $time_parts = explode(' ', $my_timer);
                    $time_right_now = $time_parts[1] + $time_parts[0];
                    $finishing_time = $time_right_now;
                    $total_time_in_secs = round(($finishing_time - $starting_time), 4);
                    echo 'Page generated in new mycollection count'.$total_time_in_secs.' seconds.'; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.