Re: [basex-talk] Query profiling and debugging support in BaseX
On Mon, 22 Apr 2019 at 11:21, Christian Grün wrote: > That’s good to know. Once we decide to stabilize our profiling and > debugging features and make them public, we’ll have a closer look into the > tracing API of Saxon. > Great. > Thanks > Christian > > PS: Our team member Sabine extended our Wiki article on the integration of > IntelliJ. She might soon give you some feedback on her experiences with > BaseX and your plugin. > That would be useful. NOTE: In version 1.4 it is now possible to select "Active editor file" as the query to run, and specify a context item (currently strings only). I have also changed the output to put the item information into a separate table (see https://plugins.jetbrains.com/files/8612/screenshot_19185.png). Some of the things I am thinking about for the run configurations are: 1. Supporting variables/parameters. 2. Supporting specifying the type of the context item and variables. 3. Highlighting single result items according to the resulting mimetype (text, xml, json, html, rdf, etc.). 4. Support for viewing csv, json, etc. results in a tabular form in addition to the text output. 5. Supporting saving the output to a file, with an option to open the result in IntelliJ, a web browser, or some other application. 6. Providing the ability to edit BaseX configuration files from within the plugin with a UI specific to the BaseX configuration structure. 7. Support navigating from the query error stack trace to the file that caused the error. Some other things I am thinking about are: 1. An IntelliJ inspection to validate XQuery files using the query processor (e.g. using BaseX's xquery:parse API). 2. Log viewer integration for admin:logs. 3. Unit test integration (IntelliJ test view for the unit module). 4. Documentation integration, xqDoc syntax validation, and support for BaseX xqDoc generation via the inspection module. 5. Database navigation (list the database contents, view/add/edit/delete files, view file properties). Kind regards, Reece
Re: [basex-talk] Query profiling and debugging support in BaseX
That’s good to know. Once we decide to stabilize our profiling and debugging features and make them public, we’ll have a closer look into the tracing API of Saxon. Thanks Christian PS: Our team member Sabine extended our Wiki article on the integration of IntelliJ. She might soon give you some feedback on her experiences with BaseX and your plugin. Reece Dunn schrieb am Mo., 22. Apr. 2019, 12:08: > On Mon, 8 Apr 2019 at 15:40, Christian Grün > wrote: > >> Hi Reece, >> >> > I'm wondering how you would go about profiling a query in BaseX to >> determine how long various query statements take, so you can look at the >> places where you need to modify the query to be faster. I have added >> MarkLogic's profiling support into my XQuery plugin that does this and am >> wondering how this can be done in BaseX. >> >> Have you already embedded support for the Saxon debugger in IntelliJ? >> > > The current development version of my plugin adds support for the Saxon > tracing API and am using that to generate a profile report similar to the > one for MarkLogic. This is working well. I am still investigating debugging > support for both Saxon and MarkLogic. > > A similar tracing API could be useful for BaseX. Specifically, the ability > to add trace objects into the evaluation pipeline that call events on a > listener class before and after evaluation. I could make use of that API in > my plugin to provide profiling and debugging functionality. > > I'm still planning on using the timing information and query plan from > BaseX. > > Kind regards, > Reece >
Re: [basex-talk] Query profiling and debugging support in BaseX
On Mon, 8 Apr 2019 at 15:40, Christian Grün wrote: > Hi Reece, > > > I'm wondering how you would go about profiling a query in BaseX to > determine how long various query statements take, so you can look at the > places where you need to modify the query to be faster. I have added > MarkLogic's profiling support into my XQuery plugin that does this and am > wondering how this can be done in BaseX. > > Have you already embedded support for the Saxon debugger in IntelliJ? > The current development version of my plugin adds support for the Saxon tracing API and am using that to generate a profile report similar to the one for MarkLogic. This is working well. I am still investigating debugging support for both Saxon and MarkLogic. A similar tracing API could be useful for BaseX. Specifically, the ability to add trace objects into the evaluation pipeline that call events on a listener class before and after evaluation. I could make use of that API in my plugin to provide profiling and debugging functionality. I'm still planning on using the timing information and query plan from BaseX. Kind regards, Reece
Re: [basex-talk] Query profiling and debugging support in BaseX
On Wed, 10 Apr 2019 at 16:30, Christian Grün wrote: > A little update: > > • I have added a FULLPLAN option [1]. If it’s enabled, information on > the original query string will be attached to the query plan. > • The output of the session info and the internal XQuery command info > has been aligned (the query plan will now be returned to the database > client as well). > Thanks for the quick update. I'll see what I can do for the next update to my plugin. Kind regards, Reece > The release of BaseX 9.2 is scheduled for tomorrow. > > [1] http://docs.basex.org/wiki/Options#FULLPLAN > > > > On Tue, Apr 9, 2019 at 2:16 PM Christian Grün > wrote: > > > > > The MarkLogic profile integration generates results like in > https://plugins.jetbrains.com/files/8612/screenshot_19187.png. It could > be useful to have something similar in BaseX. I would envision that this > would apply the optimization steps first (function call rewriting, constant > count evaluation, index access, etc.) and then profile the resulting query. > It could even be useful in figuring out what queries to rewrite in the > BaseX optimization pass. > > > > Thanks for the example, I’ll take this into consideration. > > > > > Something that might be interesting/useful is being able to relate the > query plan to the original source. Likewise for the information on applying > indices. That would help when working on more advanced integration, such as > annotating the types that BaseX evaluates variables, expressions, etc. to. > > > > I have slightly extended the code for generating the query plan. With > > the latest snapshot, the query… > > > > for $x in 1 to 5 return $x * $x > > > > …will yield the following query plan: > > > > > > > > > > > > > > > >id="0"/> > >id="0"/> > > > > > > > > > > Another example (that involves some rewritings): > > > > let $gauss := function($x) { sum(1 to $x) } > > for $i in 1 to 2 > > return { $gauss(1) } > > > > The optimized query looks as follows: > > > > for $i_1 in util:replicate("", 2) > > return element x { (50005000) } > > > > The corresponding query plan (the COMPPLAN option can be turned off to > > get the plan of the unoptimized AST): > > > > > > > > > > > > > > > > > > > > x_ > > 50005000 > > > > > > > > > > I’m still hesitant to include the line and column numbers in the > > official release, as it would make sense to also include the base URI > > of the module for each expression if other modules are imported (and > > this would bloat the plan noticeably). Maybe we could add yet another > > option for generating a more comprehensive version of the query plan. > > > > > > > Q: Is there any documentation on the format that the query errors can > take? > > > Q: How are query errors with function call stacks formatted, including > from other modules? > > > > Here you can find the construction of the error message and the stack > trace: > > > > > https://github.com/BaseXdb/basex/blob/c813a426267b542b4500ecad0ceca84e2824fc74/basex-core/src/main/java/org/basex/query/QueryException.java#L239-L248 > > > > Hope this helps, > > Christian >
Re: [basex-talk] Query profiling and debugging support in BaseX
A little update: • I have added a FULLPLAN option [1]. If it’s enabled, information on the original query string will be attached to the query plan. • The output of the session info and the internal XQuery command info has been aligned (the query plan will now be returned to the database client as well). The release of BaseX 9.2 is scheduled for tomorrow. [1] http://docs.basex.org/wiki/Options#FULLPLAN On Tue, Apr 9, 2019 at 2:16 PM Christian Grün wrote: > > > The MarkLogic profile integration generates results like in > > https://plugins.jetbrains.com/files/8612/screenshot_19187.png. It could be > > useful to have something similar in BaseX. I would envision that this would > > apply the optimization steps first (function call rewriting, constant count > > evaluation, index access, etc.) and then profile the resulting query. It > > could even be useful in figuring out what queries to rewrite in the BaseX > > optimization pass. > > Thanks for the example, I’ll take this into consideration. > > > Something that might be interesting/useful is being able to relate the > > query plan to the original source. Likewise for the information on applying > > indices. That would help when working on more advanced integration, such as > > annotating the types that BaseX evaluates variables, expressions, etc. to. > > I have slightly extended the code for generating the query plan. With > the latest snapshot, the query… > > for $x in 1 to 5 return $x * $x > > …will yield the following query plan: > > > > > > > >id="0"/> >id="0"/> > > > > > Another example (that involves some rewritings): > > let $gauss := function($x) { sum(1 to $x) } > for $i in 1 to 2 > return { $gauss(1) } > > The optimized query looks as follows: > > for $i_1 in util:replicate("", 2) > return element x { (50005000) } > > The corresponding query plan (the COMPPLAN option can be turned off to > get the plan of the unoptimized AST): > > > > > > > > > > x_ > 50005000 > > > > > I’m still hesitant to include the line and column numbers in the > official release, as it would make sense to also include the base URI > of the module for each expression if other modules are imported (and > this would bloat the plan noticeably). Maybe we could add yet another > option for generating a more comprehensive version of the query plan. > > > > Q: Is there any documentation on the format that the query errors can take? > > Q: How are query errors with function call stacks formatted, including from > > other modules? > > Here you can find the construction of the error message and the stack trace: > > https://github.com/BaseXdb/basex/blob/c813a426267b542b4500ecad0ceca84e2824fc74/basex-core/src/main/java/org/basex/query/QueryException.java#L239-L248 > > Hope this helps, > Christian
Re: [basex-talk] Query profiling and debugging support in BaseX
> The MarkLogic profile integration generates results like in > https://plugins.jetbrains.com/files/8612/screenshot_19187.png. It could be > useful to have something similar in BaseX. I would envision that this would > apply the optimization steps first (function call rewriting, constant count > evaluation, index access, etc.) and then profile the resulting query. It > could even be useful in figuring out what queries to rewrite in the BaseX > optimization pass. Thanks for the example, I’ll take this into consideration. > Something that might be interesting/useful is being able to relate the query > plan to the original source. Likewise for the information on applying > indices. That would help when working on more advanced integration, such as > annotating the types that BaseX evaluates variables, expressions, etc. to. I have slightly extended the code for generating the query plan. With the latest snapshot, the query… for $x in 1 to 5 return $x * $x …will yield the following query plan: Another example (that involves some rewritings): let $gauss := function($x) { sum(1 to $x) } for $i in 1 to 2 return { $gauss(1) } The optimized query looks as follows: for $i_1 in util:replicate("", 2) return element x { (50005000) } The corresponding query plan (the COMPPLAN option can be turned off to get the plan of the unoptimized AST): x_ 50005000 I’m still hesitant to include the line and column numbers in the official release, as it would make sense to also include the base URI of the module for each expression if other modules are imported (and this would bloat the plan noticeably). Maybe we could add yet another option for generating a more comprehensive version of the query plan. > Q: Is there any documentation on the format that the query errors can take? > Q: How are query errors with function call stacks formatted, including from > other modules? Here you can find the construction of the error message and the stack trace: https://github.com/BaseXdb/basex/blob/c813a426267b542b4500ecad0ceca84e2824fc74/basex-core/src/main/java/org/basex/query/QueryException.java#L239-L248 Hope this helps, Christian
Re: [basex-talk] Query profiling and debugging support in BaseX
Hi Christian, On Mon, 8 Apr 2019 at 15:40, Christian Grün wrote: > Hi Reece, > > First of all, thanks for your marvellous and always up-to-date > XQuery/BaseX plugin for IntelliJ. We have included it in our Wiki just > recently [1]. > Thanks :). > > I could display the timings, like in the BaseX GUI. Is there a way to > get this information using the org.basex.api.client interfaces? > > Is there a way to get the query plan, pre-evaluation mapping, and > optimized query for the given query? > > I have attached a little Java example (QueryInfoExample.java) that > uses the session API (the API can be used locally or with a running > server instance). It demonstrates how the GUI timings can be requested > via the client interface. The second code snippet > (QueryPlanExample.java) goes one level deeper; it illustrates how the > internal query plan can be accessed. Thanks for providing the examples. > While the format of the query > plan has been modified in the past quite frequently, the structure of > the textual output hasn’t changed for a longer time now, so it may be > safer to work with the output of the first example. > I may just end up outputting the query plan in the XML format that BaseX provides, like is done in the BaseX GUI. > > I'm wondering how you would go about profiling a query in BaseX to > determine how long various query statements take, so you can look at the > places where you need to modify the query to be faster. I have added > MarkLogic's profiling support into my XQuery plugin that does this and am > wondering how this can be done in BaseX. > > The current version of BaseX has no built-in features for debugging > and profiling code in a programmatical way. We had developed some > prototypical code in the past; so far, it hasn’t been included in the > official version due to performance concerns, and the fact that > profiled code cannot be rewritten that aggressively (profiled code > will often yield other timings than fully optimized code). > That makes sense. The MarkLogic profile integration generates results like in https://plugins.jetbrains.com/files/8612/screenshot_19187.png. It could be useful to have something similar in BaseX. I would envision that this would apply the optimization steps first (function call rewriting, constant count evaluation, index access, etc.) and then profile the resulting query. It could even be useful in figuring out what queries to rewrite in the BaseX optimization pass. > > Have you already embedded support for the Saxon debugger in IntelliJ? > I've had a brief look at them, but nothing in-depth yet. I'm experimenting with the APIs for integrating debuggers with IntelliJ. I see it can be used for profiling, so I will investigate using those APIs for profiling Saxon XPath, XQuery, and XSLT. > Further questions are welcome. For example, we could think about > adding dedicated functions to our API for requesting query information > more elegantly. > The current API should be sufficient. Something that might be interesting/useful is being able to relate the query plan to the original source. Likewise for the information on applying indices. That would help when working on more advanced integration, such as annotating the types that BaseX evaluates variables, expressions, etc. to. I do have some questions about exceptions. I'm currently using a simple regex to extract the error information ( https://raw.githubusercontent.com/rhdunn/xquery-intellij-plugin/master/src/plugin-basex/main/uk/co/reecedunn/intellij/plugin/basex/query/session/BaseXQueryError.kt) so I can standardize the formatting of the errors across the different vendors and do things like link to the source files. Q: Is there any documentation on the format that the query errors can take? Q: How are query errors with function call stacks formatted, including from other modules? Kind regards, Reece > Christian > > [1] http://docs.basex.org/wiki/Integrating_IntelliJ_IDEA >
Re: [basex-talk] Query profiling and debugging support in BaseX
Hi Reece, First of all, thanks for your marvellous and always up-to-date XQuery/BaseX plugin for IntelliJ. We have included it in our Wiki just recently [1]. > I could display the timings, like in the BaseX GUI. Is there a way to get > this information using the org.basex.api.client interfaces? > Is there a way to get the query plan, pre-evaluation mapping, and optimized > query for the given query? I have attached a little Java example (QueryInfoExample.java) that uses the session API (the API can be used locally or with a running server instance). It demonstrates how the GUI timings can be requested via the client interface. The second code snippet (QueryPlanExample.java) goes one level deeper; it illustrates how the internal query plan can be accessed. While the format of the query plan has been modified in the past quite frequently, the structure of the textual output hasn’t changed for a longer time now, so it may be safer to work with the output of the first example. > I'm wondering how you would go about profiling a query in BaseX to determine > how long various query statements take, so you can look at the places where > you need to modify the query to be faster. I have added MarkLogic's profiling > support into my XQuery plugin that does this and am wondering how this can be > done in BaseX. The current version of BaseX has no built-in features for debugging and profiling code in a programmatical way. We had developed some prototypical code in the past; so far, it hasn’t been included in the official version due to performance concerns, and the fact that profiled code cannot be rewritten that aggressively (profiled code will often yield other timings than fully optimized code). Have you already embedded support for the Saxon debugger in IntelliJ? Further questions are welcome. For example, we could think about adding dedicated functions to our API for requesting query information more elegantly. Christian [1] http://docs.basex.org/wiki/Integrating_IntelliJ_IDEA QueryInfoExample.java Description: application/ms-java QueryPlanExample.java Description: application/ms-java
[basex-talk] Query profiling and debugging support in BaseX
Hi, I'm wondering how you would go about profiling a query in BaseX to determine how long various query statements take, so you can look at the places where you need to modify the query to be faster. I have added MarkLogic's profiling support into my XQuery plugin that does this and am wondering how this can be done in BaseX. I'm aware of the prof functions, but these are more useful for manually instrumenting sections of a query, and not an automated way of getting the timing information for all the queries and parts of the query. Specifically for integrating into an IDE. I could display the timings, like in the BaseX GUI. Is there a way to get this information using the org.basex.api.client interfaces? Is there a way to get the query plan, pre-evaluation mapping, and optimized query for the given query? It would be helpful to link these back to the source file, so things like optimisation hints can link back to the file being edited. Finally, I am looking into debugging support and am wondering if this is possible to do for BaseX queries. What approach would be best for this, especially in terms of integrating it into an IDE? Kind regards, Reece