diff options
author | Aleksey Kladov <[email protected]> | 2018-09-10 18:48:32 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-09-15 22:00:05 +0100 |
commit | 3ae3b3eb0682a4550578b4c35dc6e099d8a04e66 (patch) | |
tree | 8bd66ec01b5ec07ca74d2e16250469fe98bc8627 /crates/libanalysis/src/db.rs | |
parent | 99d02fe583f4747f67debc1973a3eb3ca62e2005 (diff) |
initial query tracing
Diffstat (limited to 'crates/libanalysis/src/db.rs')
-rw-r--r-- | crates/libanalysis/src/db.rs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/crates/libanalysis/src/db.rs b/crates/libanalysis/src/db.rs index 335c79e76..5e3c8fb7a 100644 --- a/crates/libanalysis/src/db.rs +++ b/crates/libanalysis/src/db.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | use std::{ | 1 | use std::{ |
2 | hash::Hash, | 2 | hash::Hash, |
3 | sync::Arc, | 3 | sync::Arc, |
4 | cell::RefCell, | ||
4 | }; | 5 | }; |
5 | use libsyntax2::{File}; | 6 | use libsyntax2::{File}; |
6 | use im; | 7 | use im; |
@@ -36,17 +37,38 @@ impl Db { | |||
36 | self.file_resolver = file_resolver | 37 | self.file_resolver = file_resolver |
37 | } | 38 | } |
38 | pub(crate) fn query_ctx(&self) -> QueryCtx { | 39 | pub(crate) fn query_ctx(&self) -> QueryCtx { |
39 | QueryCtx { db: self.clone() } | 40 | QueryCtx { |
41 | db: self.clone(), | ||
42 | trace: RefCell::new(Vec::new()), | ||
43 | } | ||
40 | } | 44 | } |
41 | } | 45 | } |
42 | 46 | ||
43 | pub(crate) struct QueryCtx { | 47 | pub(crate) struct QueryCtx { |
44 | db: Db | 48 | db: Db, |
49 | pub(crate) trace: RefCell<Vec<TraceEvent>>, | ||
50 | } | ||
51 | |||
52 | #[derive(Clone, Copy, Debug)] | ||
53 | pub(crate) struct TraceEvent { | ||
54 | pub(crate) query_id: u32, | ||
55 | pub(crate) kind: TraceEventKind | ||
56 | } | ||
57 | |||
58 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
59 | pub(crate) enum TraceEventKind { | ||
60 | Start, Finish | ||
45 | } | 61 | } |
46 | 62 | ||
47 | impl QueryCtx { | 63 | impl QueryCtx { |
48 | pub(crate) fn get<Q: Get>(&self, params: &Q::Params) -> Q::Output { | 64 | pub(crate) fn get<Q: Get>(&self, params: &Q::Params) -> Q::Output { |
49 | Q::get(self, params) | 65 | self.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Start }); |
66 | let res = Q::get(self, params); | ||
67 | self.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Finish }); | ||
68 | res | ||
69 | } | ||
70 | fn trace(&self, event: TraceEvent) { | ||
71 | self.trace.borrow_mut().push(event) | ||
50 | } | 72 | } |
51 | } | 73 | } |
52 | 74 | ||