1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_TRACING_ARC_TRACING_EVENT_MATCHER_H_ 6 #define CHROME_BROWSER_CHROMEOS_ARC_TRACING_ARC_TRACING_EVENT_MATCHER_H_ 7 8 #include <stddef.h> 9 10 #include <map> 11 #include <string> 12 13 #include "base/macros.h" 14 #include "base/optional.h" 15 16 namespace arc { 17 18 class ArcTracingEvent; 19 20 // Helper that allows to match events based on provided criteria. 21 class ArcTracingEventMatcher { 22 public: 23 ArcTracingEventMatcher(); 24 // Format category:name[*]?(arg_name=arg_value;..) 25 // For example: 26 // exo:Surface::Attach 27 // exo:Surface::Attach(buffer_id=0x7f9f5110690) 28 // android:HW_VSYNC_0|* 29 explicit ArcTracingEventMatcher(const std::string& data); 30 31 // Returns true in case |event| matches criteria set. 32 bool Match(const ArcTracingEvent& event) const; 33 34 base::Optional<int64_t> ReadAndroidEventInt64( 35 const ArcTracingEvent& event) const; 36 37 // Sets the expected phase. Tested event does not match if its phase does not 38 // match |phase|. This is an optional criteria. 39 ArcTracingEventMatcher& SetPhase(char phase); 40 // Sets the expected category. Tested event does not match if its category 41 // does not match |category|. This is an optional criteria. 42 ArcTracingEventMatcher& SetCategory(const std::string& category); 43 // Sets the expected name. Tested event does not match if its name does not 44 // match |name|. This is an optional criteria. 45 ArcTracingEventMatcher& SetName(const std::string& name); 46 // Adds the expected argument. Tested event does not match if it does not 47 // contains the argument specified by |key| or argument does not match 48 // |value|. 49 ArcTracingEventMatcher& AddArgument(const std::string& key, 50 const std::string& value); 51 52 private: 53 // Defines the phase to match. 54 char phase_ = 0; 55 // Defines the category to match. 56 std::string category_; 57 // Defines the name to match. 58 std::string name_; 59 // If true, name_ is a prefix to match instead of the entire string. 60 bool name_prefix_match_ = false; 61 // Defines set of arguments to match if needed. 62 std::map<std::string, std::string> args_; 63 64 DISALLOW_COPY_AND_ASSIGN(ArcTracingEventMatcher); 65 }; 66 67 } // namespace arc 68 69 #endif // CHROME_BROWSER_CHROMEOS_ARC_TRACING_ARC_TRACING_EVENT_MATCHER_H_ 70