• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
storing profiler data - specifically elapsed time

#1
[eluser]skattabrain[/eluser]
I'm trying to store the memory peak usage and the total script execution time using a post_system hook.

On each page load, I set a "page id" config variable...

Code:
$config['page_id'] = md5(uniqid(mt_rand()));

Then I do a post_controller_constructor hook to log the page view, then at the very end I want to set a post_system update to the tracking record for this page...

Code:
function update_trackme_times()
{
  $data = array(

   'track_total_memory' => memory_get_peak_usage()

   );

  $this->db->where('page_id', config_item('page_id'));
  $this->db->update('page_track', $data);
}

Now it records the peak memory usage really well, but I can't seem to make use of the benchmarking class to get the equivalent of {elapsed time}

Any ideas?

#2
[eluser]CroNiX[/eluser]
Take a look at /system/CodeIgniter.php. It benchmarks that stuff for every request (which is where it gets {elapsed_time} and other from). You just need to access it in the benchmark object. You can access by globalizing $BM and accessing it in your post hook.

#3
[eluser]skattabrain[/eluser]
super, that works... I actually saw a post you made earlier that was similar but I usually avoid globals, figuring there was a more "codeigniter way"

Thanks though!

What are your thoughts on this...

Code:
function update_trackme_times()
{
  global $BM;  
  
  $start = explode(' ', $BM->marker['total_execution_time_start']);
  $end = explode(' ', $BM->marker['total_execution_time_end']);

  $start =  $start[1] + $start[0];
  $end =  $end[1] + $end[0];

  $total_script_time = $end - $start;

  $data = array(

   'track_total_memory' => memory_get_peak_usage(),
   'track_elapsed_time' => $total_script_time

   );

  $this->db->where('page_id', config_item('page_id'));
  $this->db->update('track', $data);
}

I think I'll add conditional code to just return out if these times are under a certain target... hmmm



Thanks again

#4
[eluser]CroNiX[/eluser]
You could use the benchmark class instance itself to do the time calculations.
Code:
function update_trackme_times()
{
  global $BM;  
  
  $data = array(
    'track_total_memory' => memory_get_peak_usage(),
    'track_elapsed_time' => $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end')
  );

  $this->db->where('page_id', config_item('page_id'));
  $this->db->update('track', $data);
}

#5
[eluser]skattabrain[/eluser]
[quote author="CroNiX" date="1330197750"]You could use the benchmark class instance itself to do the time calculations.
Code:
function update_trackme_times()
{
  global $BM;  
  
  $data = array(
    'track_total_memory' => memory_get_peak_usage(),
    'track_elapsed_time' => $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end')
  );

  $this->db->where('page_id', config_item('page_id'));
  $this->db->update('track', $data);
}
[/quote]

Thanks, that's exactly what I was looking for.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.