Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hivemind
Commits
703fe3b6
Commit
703fe3b6
authored
6 years ago
by
roadscape
Browse files
Options
Downloads
Patches
Plain Diff
remove regex dep from stats
parent
8ec9ed15
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hive/utils/stats.py
+10
-6
10 additions, 6 deletions
hive/utils/stats.py
with
10 additions
and
6 deletions
hive/utils/stats.py
+
10
−
6
View file @
703fe3b6
"""
Tracks SQL timing stats and prints results periodically or on exit.
"""
"""
Tracks SQL timing stats and prints results periodically or on exit.
"""
import
re
import
atexit
import
atexit
import
logging
import
logging
...
@@ -9,10 +8,15 @@ from hive.utils.system import colorize, peak_usage_mb
...
@@ -9,10 +8,15 @@ from hive.utils.system import colorize, peak_usage_mb
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
def
_normalize_sql
(
sql
):
def
_normalize_sql
(
sql
,
maxlen
=
150
):
nsql
=
'
'
.
join
(
sql
[
0
:
512
].
split
())[
0
:
256
]
"""
Collapse whitespace and middle-truncate if needed.
"""
nsql
=
re
.
sub
(
r
'
VALUES (\s*\([^)]+\),?)+
'
,
'
VALUES (...)
'
,
nsql
)
out
=
'
'
.
join
(
sql
.
split
())
return
nsql
if
len
(
out
)
>
maxlen
:
i
=
int
(
maxlen
/
2
-
4
)
out
=
(
out
[
0
:
i
]
+
'
. . .
'
+
out
[
-
i
:
None
])
return
out
def
log_query_stats
(
fn
):
def
log_query_stats
(
fn
):
"""
Decorator for hive.db.adapter::query()
"""
"""
Decorator for hive.db.adapter::query()
"""
...
@@ -71,7 +75,7 @@ class StatsAbstract:
...
@@ -71,7 +75,7 @@ class StatsAbstract:
log
.
info
(
'
%7s %9s %9s %9s
'
,
'
-pct-
'
,
'
-ttl-
'
,
'
-avg-
'
,
'
-cnt-
'
)
log
.
info
(
'
%7s %9s %9s %9s
'
,
'
-pct-
'
,
'
-ttl-
'
,
'
-avg-
'
,
'
-cnt-
'
)
for
call
,
ms
,
reqs
in
self
.
table
(
40
):
for
call
,
ms
,
reqs
in
self
.
table
(
40
):
log
.
info
(
"
% 6.1f%% % 7dms % 9.2f % 8dx -- %s
"
,
log
.
info
(
"
% 6.1f%% % 7dms % 9.2f % 8dx -- %s
"
,
100
*
ms
/
self
.
_ms
,
ms
,
ms
/
reqs
,
reqs
,
call
[
0
:
150
]
)
100
*
ms
/
self
.
_ms
,
ms
,
ms
/
reqs
,
reqs
,
call
)
self
.
clear
()
self
.
clear
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment