Mastering regular expression searches inside PVRTraceGUI

As part of our PowerVR SDK v3.3 development, we chose to refine navigation in PVRTraceGUI – our OpenGL ES analysis utility. This work consisted of many minor tweaks to simplify the interface. It also included a bigger change – a brand new search engine. One of the most important features of the new, streamlined Find dialog is its powerful regular expression search engine.

PVRTrace_find

In this blog post, I’ll detail a few tricks I’ve picked so far (despite being a regular expression novice) to significantly speed up my OpenGL ES debugging process.

What are regular expressions?

For those unfamiliar, regular expressions (a.k.a. RegEx) allow explicit definition of search patterns. They’re extremely useful when you want to search for something more specific than a single keyword. Before going any further, it’s worth mentioning that PVRTraceGUI actually supports Extended RegEx. This basically means there are some additional metacharacters to make life easier (this section of the Wikipedia RegEx article explains the differences).

Complex regular expressions can look a little daunting. Appendix A of the PVRTrace User Manual includes a table of all supported metacharacters. For convenience, I’ve included a cheat sheet below. If you can, I’d recommend also trying an online RegEx prototyping tool while reading this (e.g. www.rubular.com) to help you wrap your head around the basics.

Metacharacter Description
. Matches any single character.
[ ] A bracket expression. Matches a single character that is contained within the brackets.
[^ ] Matches a single character that is not contained within the brackets.
^ Matches the starting position within the string.
$ Matches the ending position of the string or the position just before a string-ending newline.
( ) Defines a marked subexpression.
n Matches what the nth marked subexpression matched, where n is a digit from 1 to 9
* Matches the preceding element zero or more times.
{m,n} Matches the preceding element at least m and not more than n times. For example, a{3,5} matches only “aaa”, “aaaa”, and “aaaaa”.
? Matches the preceding element zero or one time. For example, ab?c matches only “ac” or “abc”.
+ Matches the preceding element one or more times. For example, ab+c matches “abc”, “abbc”, “abbbc”, and so on, but not “ac”.
| The choice (also known as alternation or set union) operator matches either the expression before or the expression after the operator. For example, abc|def matches “abc” or “def”.
b Matches a word boundary.

Do the Find dialog’s options affect the search?

PVRTrace_find2

Regular expression searches can be used at the same time as the dialog’s other options.

  • “Look in” – Search in the Current Frame, the Whole Trace or a Frame Range. In multi-threaded applications, you can also choose which rendering thread should be searched
  • “Match case” – By default, the search is case-insensitive. Enabling this flag forces all pattern matches to be case-sensitive

How can I use regular expressions?

A very simple use I’ve found is to isolate all occurrences of a specific GL name with a family of calls. For example, the pattern below will find the creation, linking & binding of a particular shader program (135311933).

Program.*b135311933b

TheChase_findA

This pattern uses the ‘.’ metacharacter to capture any character type (a-z, A-Z, 0-9 etc.). The ‘*’ indicates that any number of the previous character should be captured (zero or more). Together, ‘.*’ tells the RegEx engine that we don’t care what characters are between the two search terms. The ‘b’ word boundary metacharacters ensure we match the word exactly and ignore cases where the word is a sub-string of a larger word (e.g. ignore 135311933456). When the expression is executed, PVRTraceGUI’s Search widget will list all matches in call order, grouped by the frame number they occurred in.

TheChase_findA_results

From this expression, we can go further and expand the search to include other GL calls that take the program name as an argument.

(Program|ActiveAttrib|ActiveUniform|AttachedShaders
|AttribLocation|GetUniform).*b135311933b

TheChase_findB_results

In this search, the ‘(‘ and ‘)’ brackets are used to define a sub expression. ‘|’ metacharacters indicate an OR operation. It’s possible to include multiple sub-expressions, so we can easily expand this search to include several GL names:

(Program|ActiveAttrib|ActiveUniform|AttachedShaders
|AttribLocation|GetUniform).*b(135311933|40810583|50050715)b

TheChase_findC_results

Any more suggestions?

As the search is performed on all textual data captured in the GL and EGL call stream, we can search for any call and/or parameter name. For example, the pattern below finds all compressed ETC2 texture data uploads where the resolution is 512×512, regardless of format (i.e. COMPRESSED_RGB8_ETC2, COMPRESSED_SRGB8_ETC2, COMPRESSED_SRGB8_ALPHA8_ETC2_EAC etc.).

glCompressedTex.*Image.*GL_COMPRESSED_.*ETC2.*b512b, b512b,

This is great! Where can I learn more?

There are countless wikis, blog posts and documents out there that explain clever uses of RegEx patterns to find needles in haystacks. The online tool I mentioned earlier is really useful (www.rubular.com). The best thing to do though is capture a PVRT, load it into PVRTraceGUI and start experimenting!

Leave a Comment

Search by Tag

Search for posts by tag.

Search by Author

Search for posts by one of our authors.

Featured posts
Popular posts

Blog Contact

If you have any enquiries regarding any of our blog posts, please contact:

United Kingdom

benny.har-even@imgtec.com
Tel: +44 (0)1923 260 511

Related blog articles

What is PowerVR Automotive? Register NOW to hear our webinar.

The automotive industry is going through many changes and that is having a huge impact on the semiconductor IP industry. The vehicle will move from being predominantly mechanical to primarily a computer on wheels enabling a future of self-driving cars,

Image-based lighting

PowerVR Tools and SDK 2018 Release 2 now available

Here’s an early Christmas present for graphics developers – the release of the latest version of our PowerVR Tools and SDK! The headline features for this release include some exciting new examples demonstrating new techniques in our SDK, and some very

on stage in China

PVRIC4 a hit at ICCAD 2018 in China

Imagination’s PVRIC4 image compression tech garnered plenty of attention at the recent ICCAD China 2018 symposium, which took place on 29th and 30th November at the Zhuhai International Convention & Exhibition Centre, China. The annual event focusses on integrated circuit

The ultimate embedded GPUs for the latest applications

Introducing PowerVR Series9XEP, Series9XMP, and Series9XTP As Benjamin Franklin once said, only three things in life are certain: death, taxes and the ongoing rapid advancement of GPUs for embedded applications*. Proving his point, this week, Imagination has once again pushed

Stay up-to-date with Imagination

Sign up to receive the latest news and product updates from Imagination straight to your inbox.

  • This field is for validation purposes and should be left unchanged.