Lines Matching refs:Query
5 // Use trace_analyzer::Query and trace_analyzer::TraceAnalyzer to search for
15 // A Query is a boolean expression tree that evaluates to true or false for a
34 // analyzer.FindEvents(Query(EVENT_NAME) == "my_event", &events);
38 // Query q = (Query(EVENT_NAME) == Query::String("my_event") &&
39 // Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_BEGIN) &&
40 // Query(EVENT_DURATION) > Query::Double(1000000.0));
58 // Query begin(Query(EVENT_NAME) == Query::String("timing1_begin"));
59 // Query end(Query(EVENT_NAME) == Query::String("timing1_end"));
60 // Query match(Query(EVENT_ARG, "id") == Query(OTHER_ARG, "id"));
64 // Query q = (Query(EVENT_NAME) == Query::String("timing1_begin") &&
65 // Query(EVENT_HAS_OTHER));
129 // Query(EVENT_HAS_OTHER) or by calling has_other_event().
149 // Query(HAS_NUMBER_ARG) or Query(HAS_STRING_ARG).
185 class Query {
187 Query(const Query& query);
189 ~Query();
192 // Query literal values
195 static Query String(const std::string& str);
198 static Query Double(double num);
199 static Query Int(int32_t num);
200 static Query Uint(uint32_t num);
203 static Query Bool(bool boolean);
206 static Query Phase(char phase);
209 // Example: Query(EVENT_NAME) == Query::Pattern("MyEvent*")
210 static Query Pattern(const std::string& pattern);
213 // Query event members
215 static Query EventPid() { return Query(EVENT_PID); }
217 static Query EventTid() { return Query(EVENT_TID); }
220 static Query EventTime() { return Query(EVENT_TIME); }
223 // Only works if Query::EventHasOther() == true.
224 static Query EventDuration() { return Query(EVENT_DURATION); }
227 static Query EventCompleteDuration() {
228 return Query(EVENT_COMPLETE_DURATION);
231 static Query EventPhase() { return Query(EVENT_PHASE); }
233 static Query EventCategory() { return Query(EVENT_CATEGORY); }
235 static Query EventName() { return Query(EVENT_NAME); }
237 static Query EventId() { return Query(EVENT_ID); }
239 static Query EventPidIs(int process_id) {
240 return Query(EVENT_PID) == Query::Int(process_id);
243 static Query EventTidIs(int thread_id) {
244 return Query(EVENT_TID) == Query::Int(thread_id);
247 static Query EventThreadIs(const TraceEvent::ProcessThreadID& thread) {
251 static Query EventTimeIs(double timestamp) {
252 return Query(EVENT_TIME) == Query::Double(timestamp);
255 static Query EventDurationIs(double duration) {
256 return Query(EVENT_DURATION) == Query::Double(duration);
259 static Query EventPhaseIs(char phase) {
260 return Query(EVENT_PHASE) == Query::Phase(phase);
263 static Query EventCategoryIs(const std::string& category) {
264 return Query(EVENT_CATEGORY) == Query::String(category);
267 static Query EventNameIs(const std::string& name) {
268 return Query(EVENT_NAME) == Query::String(name);
271 static Query EventIdIs(const std::string& id) {
272 return Query(EVENT_ID) == Query::String(id);
276 static Query EventHasStringArg(const std::string& arg_name) {
277 return Query(EVENT_HAS_STRING_ARG, arg_name);
282 static Query EventHasNumberArg(const std::string& arg_name) {
283 return Query(EVENT_HAS_NUMBER_ARG, arg_name);
287 static Query EventArg(const std::string& arg_name) {
288 return Query(EVENT_ARG, arg_name);
292 static Query EventHasOther() { return Query(EVENT_HAS_OTHER); }
296 static Query OtherPid() { return Query(OTHER_PID); }
298 static Query OtherTid() { return Query(OTHER_TID); }
300 static Query OtherTime() { return Query(OTHER_TIME); }
302 static Query OtherPhase() { return Query(OTHER_PHASE); }
304 static Query OtherCategory() { return Query(OTHER_CATEGORY); }
306 static Query OtherName() { return Query(OTHER_NAME); }
308 static Query OtherId() { return Query(OTHER_ID); }
310 static Query OtherPidIs(int process_id) {
311 return Query(OTHER_PID) == Query::Int(process_id);
314 static Query OtherTidIs(int thread_id) {
315 return Query(OTHER_TID) == Query::Int(thread_id);
318 static Query OtherThreadIs(const TraceEvent::ProcessThreadID& thread) {
322 static Query OtherTimeIs(double timestamp) {
323 return Query(OTHER_TIME) == Query::Double(timestamp);
326 static Query OtherPhaseIs(char phase) {
327 return Query(OTHER_PHASE) == Query::Phase(phase);
330 static Query OtherCategoryIs(const std::string& category) {
331 return Query(OTHER_CATEGORY) == Query::String(category);
334 static Query OtherNameIs(const std::string& name) {
335 return Query(OTHER_NAME) == Query::String(name);
338 static Query OtherIdIs(const std::string& id) {
339 return Query(OTHER_ID) == Query::String(id);
343 static Query OtherHasStringArg(const std::string& arg_name) {
344 return Query(OTHER_HAS_STRING_ARG, arg_name);
349 static Query OtherHasNumberArg(const std::string& arg_name) {
350 return Query(OTHER_HAS_NUMBER_ARG, arg_name);
354 static Query OtherArg(const std::string& arg_name) {
355 return Query(OTHER_ARG, arg_name);
360 static Query PrevPid() { return Query(PREV_PID); }
362 static Query PrevTid() { return Query(PREV_TID); }
364 static Query PrevTime() { return Query(PREV_TIME); }
366 static Query PrevPhase() { return Query(PREV_PHASE); }
368 static Query PrevCategory() { return Query(PREV_CATEGORY); }
370 static Query PrevName() { return Query(PREV_NAME); }
372 static Query PrevId() { return Query(PREV_ID); }
374 static Query PrevPidIs(int process_id) {
375 return Query(PREV_PID) == Query::Int(process_id);
378 static Query PrevTidIs(int thread_id) {
379 return Query(PREV_TID) == Query::Int(thread_id);
382 static Query PrevThreadIs(const TraceEvent::ProcessThreadID& thread) {
386 static Query PrevTimeIs(double timestamp) {
387 return Query(PREV_TIME) == Query::Double(timestamp);
390 static Query PrevPhaseIs(char phase) {
391 return Query(PREV_PHASE) == Query::Phase(phase);
394 static Query PrevCategoryIs(const std::string& category) {
395 return Query(PREV_CATEGORY) == Query::String(category);
398 static Query PrevNameIs(const std::string& name) {
399 return Query(PREV_NAME) == Query::String(name);
402 static Query PrevIdIs(const std::string& id) {
403 return Query(PREV_ID) == Query::String(id);
407 static Query PrevHasStringArg(const std::string& arg_name) {
408 return Query(PREV_HAS_STRING_ARG, arg_name);
413 static Query PrevHasNumberArg(const std::string& arg_name) {
414 return Query(PREV_HAS_NUMBER_ARG, arg_name);
418 static Query PrevArg(const std::string& arg_name) {
419 return Query(PREV_ARG, arg_name);
426 static Query MatchBeginWithEnd() {
427 return (Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_BEGIN)) &&
428 Query(EVENT_HAS_OTHER);
432 static Query MatchComplete() {
433 return (Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_COMPLETE));
437 static Query MatchAsyncBeginWithNext() {
438 return (Query(EVENT_PHASE) ==
439 Query::Phase(TRACE_EVENT_PHASE_ASYNC_BEGIN)) &&
440 Query(EVENT_HAS_OTHER);
444 static Query MatchBeginName(const std::string& name) {
445 return (Query(EVENT_NAME) == Query(name)) && MatchBeginWithEnd();
449 static Query MatchCompleteName(const std::string& name) {
450 return (Query(EVENT_NAME) == Query(name)) && MatchComplete();
454 static Query MatchThread(const TraceEvent::ProcessThreadID& thread) {
455 return (Query(EVENT_PID) == Query::Int(thread.process_id)) &&
456 (Query(EVENT_TID) == Query::Int(thread.thread_id));
460 static Query MatchCrossThread() {
461 return (Query(EVENT_PID) != Query(OTHER_PID)) ||
462 (Query(EVENT_TID) != Query(OTHER_TID));
469 Query operator==(const Query& rhs) const;
470 Query operator!=(const Query& rhs) const;
471 Query operator< (const Query& rhs) const;
472 Query operator<=(const Query& rhs) const;
473 Query operator> (const Query& rhs) const;
474 Query operator>=(const Query& rhs) const;
475 Query operator&&(const Query& rhs) const;
476 Query operator||(const Query& rhs) const;
477 Query operator!() const;
481 Query operator+(const Query& rhs) const;
482 Query operator-(const Query& rhs) const;
483 Query operator*(const Query& rhs) const;
484 Query operator/(const Query& rhs) const;
485 Query
487 Query operator%(const Query& rhs) const;
489 // Return true if the given event matches this query tree.
490 // This is a recursive method that walks the query tree.
570 explicit Query(TraceEventMember member);
573 Query(TraceEventMember member, const std::string& arg_name);
576 explicit Query(const std::string& str);
579 explicit Query(double num);
581 // Construct a boolean Query that returns (left <binary_op> right).
582 Query(const Query& left, const Query& right, Operator binary_op);
584 // Construct a boolean Query that returns (<binary_op> left).
585 Query(const Query& left, Operator unary_op);
597 // Attempt to convert this Query to a double. On success, true is returned
601 // Attempt to convert this Query to a string. On success, true is returned
605 // Evaluate this Query as an arithmetic operator on left_ and right_.
609 // For QUERY_EVENT_MEMBER Query: attempt to get the double value of the Query.
612 // For QUERY_EVENT_MEMBER Query: attempt to get the string value of the Query.
615 // Does this Query represent a value?
629 const Query& left() const;
630 const Query& right() const;
643 // QueryNode allows Query to store a ref-counted query tree.
646 explicit QueryNode(const Query& query);
647 const Query& query() const { return query_; }
653 Query query_;
670 // Associate BEGIN and END events with each other. This allows Query(OTHER_*)
671 // to access the associated event and enables Query(EVENT_DURATION).
695 // |first| - Eligible |first| events match this query.
696 // |second| - Eligible |second| events match this query.
697 // |match| - This query is run on the |first| event. The OTHER_* EventMember
698 // queries will point to an eligible |second| event. The query
711 void AssociateEvents(const Query& first,
712 const Query& second,
713 const Query& match);
719 // Find all events that match query and replace output vector.
720 size_t FindEvents(const Query& query, TraceEventVector* output);
722 // Find first event that matches query or NULL if not found.
723 const TraceEvent* FindFirstOf(const Query& query);
725 // Find last event that matches query or NULL if not found.
726 const TraceEvent* FindLastOf(const Query& query);
771 // Starting from |position|, find the first event that matches |query|.
774 const Query& query,
778 // Starting from |position|, find the last event that matches |query|.
781 const Query& query,
785 // Find the closest events to |position| in time that match |query|.
791 const Query& query,
798 const Query& query,
804 const Query& query) {
805 return CountMatches(events, query, 0u, events.size());