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.


Comments:

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