Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query profiling and logging. #363

Closed
wants to merge 2 commits into from
Closed

Add query profiling and logging. #363

wants to merge 2 commits into from

Conversation

tuupola
Copy link
Contributor

@tuupola tuupola commented Sep 29, 2013

Adds both query profiling (#133) and logging of reconstructed SQL query. Current logger writes the prepared query and values separately. After this patch logger reconstructs the prepared query to actual SQL before logging it. Log entry is written as single line. This enables you to use command line tools such as grep when debugging.

This patch is based on Yoan Blancs ghh133-profiling branch. Main differences are reconstructing the query and not altering the exception handling.

Example of log entry with the original logger:

2013-09-28 16:44:25 ident [info] INSERT INTO `venues`(`id`,`name`,`city`,`state`,`address`,`phone`) VALUES(?,?,?,?,?,?)
2013-09-28 16:44:25 ident [info] array (
  0 => '6',
  1 => 'The Note - West Chester',
  2 => 'West Chester',
  3 => 'PA',
  4 => '142 E. Market St.',
  5 => '0000000000',
)

Same entry with the new logger:

2013-09-29 19:46:31 ident [info] INSERT INTO `venues`(`id`,`name`,`city`,`state`,`address`,`phone`) VALUES('6','The Note - West Chester','West Chester','PA','142 E. Market St.','0000000000') -- 0.001

Adds both query profiling (#133) and logging of reconstructed SQL query. Current logger writes the prepared query and values separately. After this patch logger reconstructs the prepared query to actual SQL before logging it. Log entry is written as single line. This enables you to use command line tools such as grep when debugging.

This patch is based on Yoan Blancs ghh133-profiling branch. Main differences are reconstructing the query and not altering the exception handling.

https://github.com/greut/php-activerecord/compare/gh133-profiling

Example of log entry with the original logger:

2013-09-28 16:44:25 ident [info] INSERT INTO `venues`(`id`,`name`,`city`,`state`,`address`,`phone`) VALUES(?,?,?,?,?,?)
2013-09-28 16:44:25 ident [info] array (
  0 => '6',
  1 => 'The Note - West Chester',
  2 => 'West Chester',
  3 => 'PA',
  4 => '142 E. Market St.',
  5 => '0000000000',
)

Same entry with the new logger:

2013-09-29 19:46:31 ident [info] INSERT INTO `venues`(`id`,`name`,`city`,`state`,`address`,`phone`) VALUES('6','The Note - West Chester','West Chester','PA','142 E. Market St.','0000000000') -- 0.001
@tuupola tuupola mentioned this pull request Sep 30, 2013
@jpfuentes2
Copy link
Owner

This is so much better than the current logging facility. I only have three concerns:

  1. The code in this patch doesn't conform to the chosen style for this library. While I wish we had used the inline curly braces for control structures we regrettably did not.
  2. I would prefer to see the query timing profile before the query itself.
  3. I think it would be best to extract the prepared query expansion logic to another method to keep the query method simple.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants