1

Assuming I want to trace method calls in all the classes in packages com.abc and com.def

I put the following in my tracing script:

@OnMethod(clazz = "/com\\.(abc|def)\\..*/", method = "/.*/")

ran the script, but the output only contained method calls in com.abc package.

I changed the above line to:

@OnMethod(clazz = "/com\\.def\\..*/", method = "/.*/")

and ran the script again. The output contained method calls in com.def package. So what's wrong with the part "(abc|def)"?

I've tried to find some information under the following link:

https://github.com/btraceio/btrace/wiki/BTrace-Annotations

The description is very abstract:

/regex/ is a standard regular expression used to identify the class names

Does it support OR-relation?

ka3ak
  • 2,435
  • 2
  • 30
  • 57
  • try this please [`com\.(abc|def)\.?.*`](https://regex101.com/r/30kRqQ/1) – Youcef LAIDANI Nov 30 '17 at 12:41
  • @YCF_L, please use all the necessary escapings in a java file. I've tried clazz="com\\.(abc|def)\\.?.*" Is it correct? If yes, then result is the same - only methods in "abc" are traced. – ka3ak Nov 30 '17 at 13:01
  • Yes it is correct i'm sorry what you get when you use `com\\..*` do you get both `com.abc` and `com.def` ? – Youcef LAIDANI Nov 30 '17 at 13:07
  • This is strange. I get only "com.abc". "com.def" isn't traced. – ka3ak Nov 30 '17 at 13:14
  • hmmm, i really don't have any idea, maybe you can share more information about your packages, or maybe we don't understand how btrace work !:{ – Youcef LAIDANI Nov 30 '17 at 13:22
  • From what is there in the code, it seems the method should be indicated. Thus, it should look like `@OnMethod(clazz = "/com\\.(abc|def)\\..*/", method = "someMethodName")`. Note that this regex actually requires a dot after `abc` or `def`, the previous comment suggested making that dot optional. – Wiktor Stribiżew Nov 30 '17 at 13:43
  • BTrace is using standard Java Pattern for regex matching. Tried it with the BTrace 1.3.10 and modified AllSamples script - `@OnMethod(clazz = "/javax\\.(management|swing)\\..*", method = "/.*/")` and it works as expected. – JB- Dec 01 '17 at 13:50

0 Answers0