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
eb8619e2
Commit
eb8619e2
authored
8 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Create log context in Measure if one doesn't exist
parent
4ef7a25c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/util/metrics.py
+17
-6
17 additions, 6 deletions
synapse/util/metrics.py
tests/test_state.py
+2
-2
2 additions, 2 deletions
tests/test_state.py
with
19 additions
and
8 deletions
synapse/util/metrics.py
+
17
−
6
View file @
eb8619e2
...
@@ -50,7 +50,7 @@ block_db_txn_duration = metrics.register_distribution(
...
@@ -50,7 +50,7 @@ block_db_txn_duration = metrics.register_distribution(
class
Measure
(
object
):
class
Measure
(
object
):
__slots__
=
[
__slots__
=
[
"
clock
"
,
"
name
"
,
"
start_context
"
,
"
start
"
,
"
new_context
"
,
"
ru_utime
"
,
"
clock
"
,
"
name
"
,
"
start_context
"
,
"
start
"
,
"
new_context
"
,
"
ru_utime
"
,
"
ru_stime
"
,
"
db_txn_count
"
,
"
db_txn_duration
"
"
ru_stime
"
,
"
db_txn_count
"
,
"
db_txn_duration
"
,
"
created_context
"
]
]
def
__init__
(
self
,
clock
,
name
):
def
__init__
(
self
,
clock
,
name
):
...
@@ -58,14 +58,20 @@ class Measure(object):
...
@@ -58,14 +58,20 @@ class Measure(object):
self
.
name
=
name
self
.
name
=
name
self
.
start_context
=
None
self
.
start_context
=
None
self
.
start
=
None
self
.
start
=
None
self
.
created_context
=
False
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
()
if
self
.
start_context
:
if
not
self
.
start_context
:
self
.
ru_utime
,
self
.
ru_stime
=
self
.
start_context
.
get_resource_usage
()
logger
.
warn
(
"
Entered Measure without log context: %s
"
,
self
.
name
)
self
.
db_txn_count
=
self
.
start_context
.
db_txn_count
self
.
start_context
=
LoggingContext
(
"
Measure
"
)
self
.
db_txn_duration
=
self
.
start_context
.
db_txn_duration
self
.
start_context
.
__enter__
()
self
.
created_context
=
True
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
):
if
exc_type
is
not
None
or
not
self
.
start_context
:
if
exc_type
is
not
None
or
not
self
.
start_context
:
...
@@ -91,7 +97,12 @@ class Measure(object):
...
@@ -91,7 +97,12 @@ class Measure(object):
block_ru_utime
.
inc_by
(
ru_utime
-
self
.
ru_utime
,
self
.
name
)
block_ru_utime
.
inc_by
(
ru_utime
-
self
.
ru_utime
,
self
.
name
)
block_ru_stime
.
inc_by
(
ru_stime
-
self
.
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
.
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
(
block_db_txn_duration
.
inc_by
(
context
.
db_txn_duration
-
self
.
db_txn_duration
,
self
.
name
context
.
db_txn_duration
-
self
.
db_txn_duration
,
self
.
name
)
)
if
self
.
created_context
:
self
.
start_context
.
__exit__
(
exc_type
,
exc_val
,
exc_tb
)
This diff is collapsed.
Click to expand it.
tests/test_state.py
+
2
−
2
View file @
eb8619e2
...
@@ -140,13 +140,13 @@ class StateTestCase(unittest.TestCase):
...
@@ -140,13 +140,13 @@ class StateTestCase(unittest.TestCase):
"
add_event_hashes
"
,
"
add_event_hashes
"
,
]
]
)
)
hs
=
Mock
(
spec
=
[
hs
=
Mock
(
spec
_set
=
[
"
get_datastore
"
,
"
get_auth
"
,
"
get_state_handler
"
,
"
get_clock
"
,
"
get_datastore
"
,
"
get_auth
"
,
"
get_state_handler
"
,
"
get_clock
"
,
])
])
hs
.
get_datastore
.
return_value
=
self
.
store
hs
.
get_datastore
.
return_value
=
self
.
store
hs
.
get_state_handler
.
return_value
=
None
hs
.
get_state_handler
.
return_value
=
None
hs
.
get_auth
.
return_value
=
Auth
(
hs
)
hs
.
get_clock
.
return_value
=
MockClock
()
hs
.
get_clock
.
return_value
=
MockClock
()
hs
.
get_auth
.
return_value
=
Auth
(
hs
)
self
.
state
=
StateHandler
(
hs
)
self
.
state
=
StateHandler
(
hs
)
self
.
event_id
=
0
self
.
event_id
=
0
...
...
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