Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Maunium
synapse
Commits
9daa4e2a
Commit
9daa4e2a
authored
9 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Don't create new logging context
parent
241b7185
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/util/metrics.py
+15
-12
15 additions, 12 deletions
synapse/util/metrics.py
with
15 additions
and
12 deletions
synapse/util/metrics.py
+
15
−
12
View file @
9daa4e2a
...
@@ -48,33 +48,34 @@ block_db_txn_duration = metrics.register_distribution(
...
@@ -48,33 +48,34 @@ block_db_txn_duration = metrics.register_distribution(
class
Measure
(
object
):
class
Measure
(
object
):
__slots__
=
[
"
clock
"
,
"
name
"
,
"
start_context
"
,
"
start
"
,
"
new_context
"
]
__slots__
=
[
"
clock
"
,
"
name
"
,
"
start_context
"
,
"
start
"
,
"
new_context
"
,
"
ru_utime
"
,
"
ru_stime
"
,
"
db_txn_count
"
,
"
db_txn_duration
"
]
def
__init__
(
self
,
clock
,
name
):
def
__init__
(
self
,
clock
,
name
):
self
.
clock
=
clock
self
.
clock
=
clock
self
.
name
=
name
self
.
name
=
name
self
.
start_context
=
None
self
.
start_context
=
None
self
.
start
=
None
self
.
start
=
None
self
.
new_context
=
LoggingContext
(
self
.
name
)
def
__enter__
(
self
):
def
__enter__
(
self
):
self
.
start
=
self
.
clock
.
time_msec
()
self
.
start
=
self
.
clock
.
time_msec
()
self
.
start_context
=
LoggingContext
.
current_context
()
self
.
start_context
=
LoggingContext
.
current_context
()
self
.
new_context
.
__enter__
()
self
.
ru_utime
,
self
.
ru_stime
=
self
.
start_context
.
get_resource_usage
()
self
.
db_txn_count
=
self
.
start_context
.
db_txn_count
self
.
db_txn_duration
=
self
.
start_context
.
db_txn_duration
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
current_context
=
LoggingContext
.
current_context
()
self
.
new_context
.
__exit__
(
exc_type
,
exc_val
,
exc_tb
)
if
exc_type
is
not
None
:
if
exc_type
is
not
None
:
return
return
duration
=
self
.
clock
.
time_msec
()
-
self
.
start
duration
=
self
.
clock
.
time_msec
()
-
self
.
start
block_timer
.
inc_by
(
duration
,
self
.
name
)
block_timer
.
inc_by
(
duration
,
self
.
name
)
context
=
self
.
new
_context
context
=
LoggingContext
.
current
_context
()
if
context
!=
curren
t_context
:
if
context
!=
self
.
star
t_context
:
logger
.
warn
(
logger
.
warn
(
"
Context have unexpectedly changed from
'
%s
'
to
'
%s
'
. (%r)
"
,
"
Context have unexpectedly changed from
'
%s
'
to
'
%s
'
. (%r)
"
,
context
,
self
.
start_context
,
self
.
name
context
,
self
.
start_context
,
self
.
name
...
@@ -87,7 +88,9 @@ class Measure(object):
...
@@ -87,7 +88,9 @@ class Measure(object):
ru_utime
,
ru_stime
=
context
.
get_resource_usage
()
ru_utime
,
ru_stime
=
context
.
get_resource_usage
()
block_ru_utime
.
inc_by
(
ru_utime
,
self
.
name
)
block_ru_utime
.
inc_by
(
ru_utime
-
self
.
ru_utime
,
self
.
name
)
block_ru_stime
.
inc_by
(
ru_stime
,
self
.
name
)
block_ru_stime
.
inc_by
(
ru_stime
-
self
.
ru_stime
,
self
.
name
)
block_db_txn_count
.
inc_by
(
context
.
db_txn_count
,
self
.
name
)
block_db_txn_count
.
inc_by
(
context
.
db_txn_count
-
self
.
db_txn_count
,
self
.
name
)
block_db_txn_duration
.
inc_by
(
context
.
db_txn_duration
,
self
.
name
)
block_db_txn_duration
.
inc_by
(
context
.
db_txn_duration
-
self
.
db_txn_duration
,
self
.
name
)
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