Repository: dmvass/sqlalchemy-easy-profile

Issue:
No report shown in console in 1.1.1
**Describe the bug**
A clear and concise description of what the bug is.

I have updated to 1.1.1 today.
The SQL report no longer shows in console output.

I am using a mac but not sure if it has anything to do with it.
The setup to enable app - wide console logging of SQL statements is the same.

This is the function that is run if env variable SQL_PROFILING = True. The app is simply flask app passed into the function. All of this works fine in 1.0.3 (and worked for last year) and is as per instructions manual. In the newest version nothing is logged to the console.

```python
def add_sql_profiling(app, config_: Config):
    """
    Adds profiling of the SQL queries performed by sqlalchemy with number of duplicates and execution times.
    """
    if config_.SQL_PROFILING:
        try:
            from easy_profile import EasyProfileMiddleware

            app.wsgi_app = EasyProfileMiddleware(app.wsgi_app)
        except ModuleNotFoundError:
            logging.warning(
                'Easy profile not installed, SQL profiling not available. Install using requirements-for-dev.txt'
            )
```

**To Reproduce**
Steps to reproduce the behavior or test case.

pip install sqlalchemy-easy-profile==1.1.1

**Expected behavior**
A clear and concise description of what you expected to happen.

SQL statements report is logged in the console.

**Additional context**
Add any other context about the problem here.


Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/19?src=pr&el=h1) Report
> Merging [#19](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/19?src=pr&el=desc) into [master](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/commit/889e2dbf43f78743e9d822cbe10c7b843ee234fe?el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/19/graphs/tree.svg?width=650&height=150&src=pr&token=0d9Lc3Cmzr)](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/19?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #19      +/-   ##
==========================================
- Coverage   98.61%   98.60%   -0.02%     
==========================================
  Files           4        4              
  Lines         217      215       -2     
  Branches       32       32              
==========================================
- Hits          214      212       -2     
  Misses          1        1              
  Partials        2        2              
```


| [Impacted Files](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/19?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [easy\_profile/profiler.py](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/19/diff?src=pr&el=tree#diff-ZWFzeV9wcm9maWxlL3Byb2ZpbGVyLnB5) | `97.97% <100.00%> (-0.03%)` | :arrow_down: |
| [easy\_profile/reporters.py](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/19/diff?src=pr&el=tree#diff-ZWFzeV9wcm9maWxlL3JlcG9ydGVycy5weQ==) | `100.00% <0.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/19?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/19?src=pr&el=footer). Last update [889e2db...82763a1](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/19?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Tomasz-Kluczkowski: Hi, 

Tested with this installation: 

`sqlalchemy-easy-profile @ git+git://github.com/dmvass/sqlalchemy-easy-profile@80e0944a125b58e09bb295bd3e8c43eceea894cc
`

Confirmed working ok.
dmvass: @Tomasz-Kluczkowski the commit hash is right, thanks!

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d446327..90450c4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 
 ## [Unreleased]
 
+## [1.1.2] - 2020-10-21
+- Fixed queries for UNIX platforms [issue-18]
+
 ## [1.1.1] - 2020-07-26
 - Fixed deprecated time.clock [issue-16]
 
diff --git a/easy_profile/profiler.py b/easy_profile/profiler.py
index bc91152..ce5793a 100644
--- a/easy_profile/profiler.py
+++ b/easy_profile/profiler.py
@@ -3,13 +3,20 @@ import functools
 import inspect
 from queue import Queue
 import re
-from time import perf_counter
+import sys
+import time
 
 from sqlalchemy import event
 from sqlalchemy.engine.base import Engine
 
 from .reporters import StreamReporter
 
+# Optimize timer function for the platform
+if sys.platform == "win32":  # pragma: no cover
+    _timer = time.perf_counter
+else:
+    _timer = time.time
+
 
 SQL_OPERATORS = ["select", "insert", "update", "delete"]
 OPERATOR_REGEX = re.compile("(%s) *." % "|".join(SQL_OPERATORS), re.IGNORECASE)
@@ -170,10 +177,10 @@ class SessionProfiler:
 
     def _before_cursor_execute(self, conn, cursor, statement, parameters,
                                context, executemany):
-        context._query_start_time = perf_counter()
+        context._query_start_time = _timer()
 
     def _after_cursor_execute(self, conn, cursor, statement, parameters,
                               context, executemany):
         self.queries.put(DebugQuery(
-            statement, parameters, context._query_start_time, perf_counter()
+            statement, parameters, context._query_start_time, _timer()
         ))


Test patch:
diff --git a/tests/test_profiler.py b/tests/test_profiler.py
index eee3a40..1a64f49 100644
--- a/tests/test_profiler.py
+++ b/tests/test_profiler.py
@@ -142,9 +142,9 @@ class TestSessionProfiler(unittest.TestCase):
         self.assertListEqual(debug_queries, stats["call_stack"])
         self.assertDictEqual(stats["duplicates"], duplicates)
 
-    @mock.patch("easy_profile.profiler.perf_counter")
+    @mock.patch("easy_profile.profiler._timer")
     def test__before_cursor_execute(self, mocked):
-        expected_time = time.perf_counter()
+        expected_time = time.time()
         mocked.return_value = expected_time
         profiler = SessionProfiler()
         context = mock.Mock()
@@ -158,7 +158,7 @@ class TestSessionProfiler(unittest.TestCase):
         )
         self.assertEqual(context._query_start_time, expected_time)
 
-    @mock.patch("easy_profile.profiler.perf_counter")
+    @mock.patch("easy_profile.profiler._timer")
     def test__after_cursor_execute(self, mocked):
         expected_query = debug_queries[0]
         mocked.return_value = expected_query.end_time