Repository: dmvass/sqlalchemy-easy-profile

Issue:
Does not work on python 3.8
Exception raises when trying to use time.clock on profiler.py.

timer.clock was deprecated since Python 3.3 and removed in 3.8.

From Python DOCs:

Deprecated since version 3.3, will be removed in version 3.8: The behaviour of this function depends on the platform: use perf_counter() or process_time() instead, depending on your requirements, to have a well defined behaviour.



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

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

```diff
@@            Coverage Diff             @@
##           master      #17      +/-   ##
==========================================
- Coverage   98.63%   98.59%   -0.04%     
==========================================
  Files           4        4              
  Lines         219      213       -6     
  Branches       32       32              
==========================================
- Hits          216      210       -6     
  Misses          1        1              
  Partials        2        2              
```


| [Impacted Files](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [easy\_profile/profiler.py](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17/diff?src=pr&el=tree#diff-ZWFzeV9wcm9maWxlL3Byb2ZpbGVyLnB5) | `97.93% <100.00%> (-0.11%)` | :arrow_down: |
| [easy\_profile/reporters.py](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17/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/17?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/17?src=pr&el=footer). Last update [e98f169...e6b9ff4](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 58e2c0a..d446327 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.1] - 2020-07-26
+- Fixed deprecated time.clock [issue-16]
+
 ## [1.1.0] - 2020-06-29
 - Removed support of python 2.7, 3.5
 - Updated documentation
diff --git a/easy_profile/profiler.py b/easy_profile/profiler.py
index bfefff7..bc91152 100644
--- a/easy_profile/profiler.py
+++ b/easy_profile/profiler.py
@@ -3,20 +3,13 @@ import functools
 import inspect
 from queue import Queue
 import re
-import sys
-import time
+from time import perf_counter
 
 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.clock
-else:
-    _timer = time.time
-
 
 SQL_OPERATORS = ["select", "insert", "update", "delete"]
 OPERATOR_REGEX = re.compile("(%s) *." % "|".join(SQL_OPERATORS), re.IGNORECASE)
@@ -177,10 +170,10 @@ class SessionProfiler:
 
     def _before_cursor_execute(self, conn, cursor, statement, parameters,
                                context, executemany):
-        context._query_start_time = _timer()
+        context._query_start_time = perf_counter()
 
     def _after_cursor_execute(self, conn, cursor, statement, parameters,
                               context, executemany):
         self.queries.put(DebugQuery(
-            statement, parameters, context._query_start_time, _timer()
+            statement, parameters, context._query_start_time, perf_counter()
         ))


Test patch:
diff --git a/tests/test_profiler.py b/tests/test_profiler.py
index 1a64f49..eee3a40 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._timer")
+    @mock.patch("easy_profile.profiler.perf_counter")
     def test__before_cursor_execute(self, mocked):
-        expected_time = time.time()
+        expected_time = time.perf_counter()
         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._timer")
+    @mock.patch("easy_profile.profiler.perf_counter")
     def test__after_cursor_execute(self, mocked):
         expected_query = debug_queries[0]
         mocked.return_value = expected_query.end_time