# PVRTrace API

**URL:** <https://forums.imgtec.com/t/pvrtrace-api/2213>\
**Category:** PowerVR Insider\
**Tags:** pvrtrace, pvrhub\
**Created:** [December 3, 2014, 8:33pm UTC](https://forums.imgtec.com/t/pvrtrace-api/2213 "2014-12-03T20:33:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronanbel](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@ronanbel](https://forums.imgtec.com/u/ronanbel)\
**Post date:** [December 3, 2014, 8:33pm UTC](https://forums.imgtec.com/t/pvrtrace-api/2213/1 "2014-12-03T20:33:02Z")

</div>

Hi, I’ve just received an Android device with a PowerVR GPU [Asus fonepad 7 (atom Z3530 + PowerVR 6430)], to be able test my work on all kind of devices, and … of course … it doesn’t work.  
  
  
  
The first thing that doesn’t work is related to update (each frame) a small R8UI texture using glMapBuffer( GL\_PIXEL\_UNPACK\_BUFFER), filling the memory located at the returned pointer, UnMap, then call glTexSubImage2D to transfer to the texture.  
  
(it’s so basic that it works on all GPU/drivers from scratch, until now)  
  
  
  
I’ve got different results (wrong, empty, pseudo-random) trying all of these :  
  
// glBufferData( GL\_PIXEL\_UNPACK\_BUFFER, u32\_DataSize, NULL, GL\_STATIC\_DRAW );  
  
glBufferData( GL\_PIXEL\_UNPACK\_BUFFER, u32\_DataSize, NULL, GL\_STREAM\_DRAW );  
  
// pLock = glMapBufferRange( GL\_PIXEL\_UNPACK\_BUFFER, 0, u32\_DataSize, GL\_MAP\_WRITE\_BIT | GL\_MAP\_UNSYNCHRONIZED\_BIT );  
  
// pLock = glMapBufferRange( GL\_PIXEL\_UNPACK\_BUFFER, 0, u32\_DataSize, GL\_MAP\_WRITE\_BIT | GL\_MAP\_INVALIDATE\_RANGE\_BIT );  
  
// pLock = glMapBufferRange( GL\_PIXEL\_UNPACK\_BUFFER, 0, u32\_DataSize, GL\_MAP\_WRITE\_BIT | GL\_MAP\_INVALIDATE\_BUFFER\_BIT );  
  
pLock = glMapBufferRange( GL\_PIXEL\_UNPACK\_BUFFER, 0, u32\_DataSize, GL\_MAP\_WRITE\_BIT );  
  
all of these working (with different speed) on Windows with AMD, NVidia, Intel GPU, and on Android with Intel, Adreno, Mali GPU  
  
  
  
I took a look at the PVRTrace tool (my device is NOT rooted)(didn’t find a way to root it), and I would like to know if it’s possible to call (C++ code) some functions that Start and Stop the profile (from inside the APP) ? Because dumb results are not at the beginning of the timeline of my code. So I would like to be able to launch a capture when I want to do it.  
  
Moreover, I’m using several dynamic textures (updated by the CPU), lots of big textures, so the amount of data of a frame capture is quite huge. (it takes several minutes to upload to the debugger using Adreno profiler with a compatible device)

---

<div class="post-metadata">

**Author:** ![PaulLy](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@PaulLy](https://forums.imgtec.com/u/PaulLy)\
**Post date:** [December 9, 2014, 2:26pm UTC](https://forums.imgtec.com/t/pvrtrace-api/2213/2 "2014-12-09T14:26:26Z")

</div>

The following steps should help you get a trace recording without having to root the device and let you start the recording from any point you wish:

1. Install the PVRHub.apk (from the PowerVR SDK) to your device.  
2. In PVRHub tap the ‘Home’ button in the top left.  
3. Open the PVRTrace Record options screen.  
4. Tick the ‘Enable Network’ option.  
5. Tick ‘Network Wait’.  
6. Go back to the ‘Home’ screen to ensure settings are saved.  
7. Connect the device to a computer and from a terminal enter the command ‘adb forward tcp:54321 tcp:54321’.  
8. Start your application on the device. At this point your device should just have a blank screen while it searches for a connection.  
9. Start PVRTraceGUI on your computer.  
10. From the ‘Tools’ menu -\> ‘Remote Controller…’  
11. Enter 127.0.0.1 and ‘Go’  
12. Click ‘Start Recording’ from the point you want to start writing out a trace file from.  
  
  
  
We’re still investigating the glMapBuffer issue. If you’re able to take a trace it may help us to reproduce the issue more quickly. You can send the trace file by creating a ticket on [pvrsupport.imgtec.com/new-ticket](https://pvrsupport.imgtec.com/new-ticket) with a link back to this discussion.  
  
  
  
Thanks,  
  
Paul.

---

<div class="post-metadata">

**Author:** ![ronanbel](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@ronanbel](https://forums.imgtec.com/u/ronanbel)\
**Post date:** [December 9, 2014, 9:59pm UTC](https://forums.imgtec.com/t/pvrtrace-api/2213/3 "2014-12-09T21:59:02Z")

</div>

Thank you very much for your help Paul 😃  
  
  
  
To be able to instrument my code, since it’s pure C++ code (no Java at all), I add before loading the .so that uses OpenGL, 3 calls to dlopen to load PVRTrace.so, GLESv2\_PVRTRACE.so, EGL\_PVRTRACE.so  
  
  
  
Now launching results in waiting to connect msg in the logcat  
  
  
  
Connection with PVRtraceGUI running on my PC was successful  
  
Hitting “Start recording” started recording (…)  
  
but my APP crashed displaying this in the logcat without writing any file.  
  
  
  
Would you have an idea of how to make it work till the end of the capture please ?  
  
  
  
(now I go to sleep, I will try tomorrow to change the write path to set it to an already existing folder ?)  
  
(I don’t understand why the file is noted as already existing as I can’t find it on my device)  
  
  
  
12-09 23:45:30.695: I/PVRTrace(I)(4724): Opening trace file ‘/data/data/com.powervr.PVRHub/files/rec/com.example.fromdust.pvrt’ for recording.  
  
12-09 23:45:30.695: I/PVRTrace(I)(4724): ‘/data/data/com.powervr.PVRHub/files/rec/com.example.fromdust.pvrt’ already exists so will be overwritten.  
  
12-09 23:45:30.695: I/PVRTrace(I)(4724): Recorder Version: 3.4@3188797  
  
12-09 23:45:30.695: I/PVRTrace(I)(4724): Start Recording  
  
12-09 23:45:30.695: I/PVRTrace(I)(4724):   
  
12-09 23:45:30.705: I/PVRTrace(I)(4724): Finished saving Render State   
  
12-09 23:45:30.735: A/libc(4724): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 4754 (xample.fromdust)  
  
12-09 23:45:30.795: I/DEBUG(241): \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\*  
  
12-09 23:45:30.795: I/DEBUG(241): Build fingerprint: 'asus/WW\_K019/K019\_2:4.4.2/KVT49L/WW\_fonepad-11.10.1.38-20141020:user/release-keys’  
  
12-09 23:45:30.795: I/DEBUG(241): Revision: '0’  
  
12-09 23:45:30.795: I/DEBUG(241): pid: 4724, tid: 4754, name: xample.fromdust \>\>\> com.example.fromdust \<\<\<  
  
12-09 23:45:30.795: I/DEBUG(241): signal 11 (SIGSEGV), code 1 (SEGV\_MAPERR), fault addr 00000000

---

<div class="post-metadata">

**Author:** ![PaulLy](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@PaulLy](https://forums.imgtec.com/u/PaulLy)\
**Post date:** [December 10, 2014, 10:15am UTC](https://forums.imgtec.com/t/pvrtrace-api/2213/4 "2014-12-10T10:15:30Z")

</div>

Could you double-check that you are loading the libraries in the same order as in this blog post: [withimagination.imgtec.com/powervr-developers/pvrtrace-and-rootless-recording-on-android](https://www.imgtec.com/powervr-developers/pvrtrace-and-rootless-recording-on-android)  
  
  
  
If that doesn’t help, create a support ticket [here](https://pvrsupport.imgtec.com/new-ticket) and send your .apk, and link back to this conversation, then we can investigate why the trace is crashing.  
  
  
  
Otherwise, it may be possible for you to capture a trace but without controlling the start point (it will just capture the entire application run).

1. In PVRHub, tap the ‘Home’ button.  
2. Open the PVRTrace Record options screen.  
3. Untick the ‘Enable Network’ option.  
4. Run your application (logcat should indicate the trace is being captured here).  
5. Stop your application.  
6. Open PVRHub.  
7. Select “File manager”.  
8. Select “Copy to ‘Downloads’”.  
  
  
  
This folder should be accessible without root access, so you can use an ‘adb pull’ command to copy the trace file to your computer.  
  
  
  
Kind regards,  
  
Paul.

---

<div class="post-metadata">

**Author:** ![ronanbel](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@ronanbel](https://forums.imgtec.com/u/ronanbel)\
**Post date:** [December 10, 2014, 2:13pm UTC](https://forums.imgtec.com/t/pvrtrace-api/2213/5 "2014-12-10T14:13:54Z")

</div>

Hi Paul.  
  
I finally found a way to produce a dump file. (setting the output location to my app storage folder)  
  
Opening the file (700KB) in PVRTraceGUI gives me 44 Error “Shader failed to compile” in the Static Analysis window.  
  
Then I used “Export data” =\> file.txt  
  
  
  
[let’s say my APP has a Frame(0) which performs loading & init, then other frames perform rendering]  
  
  
  
it seems to contain all GL calls from the first frame(0), beginning with  
  
  
  
_eglGetDisplay(0) ==\> EGLDisplay(1) Error: EGL\_SUCCESS_  
  
_eglInitialize(EGLDisplay(1),NULL,NULL) ==\> EGL\_TRUE Error: EGL\_SUCCESS_  
  
_eglCreateWindowSurface(EGLDisplay(1),EGLConfig(15)_  
  
   
  
it’s ending with a sequence of code dealing with a texture creation (the code has not already draw something at this point, it’s still loading & initialisation)  
  
  
  
_glGenTextures(1,70001) Error: GL\_NO\_ERROR_  
  
_glBindTexture(GL\_TEXTURE\_2D,70001) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_MIN\_FILTER,GL\_NEAREST\_MIPMAP\_NEAREST) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_MAG\_FILTER,GL\_NEAREST) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_WRAP\_S,GL\_CLAMP\_TO\_EDGE) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_WRAP\_T,GL\_CLAMP\_TO\_EDGE) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_BASE\_LEVEL,0) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_COMPARE\_FUNC,GL\_ALWAYS) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_COMPARE\_MODE,GL\_NONE) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_MIN\_LOD,-1000) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_MAX\_LOD,1000) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_MAX\_LEVEL,0) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_SWIZZLE\_R,GL\_RED) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_SWIZZLE\_G,GL\_GREEN) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_SWIZZLE\_B,GL\_BLUE) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_SWIZZLE\_A,GL\_ALPHA) Error: GL\_NO\_ERROR_  
  
_glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_WRAP\_R,GL\_REPEAT) Error: GL\_NO\_ERROR_  
  
_glTexStorage2D(GL\_TEXTURE\_2D,1,GL\_RGBA8,256,256) Error: GL\_NO\_ERROR_  
  
_glPixelStorei(GL\_UNPACK\_ALIGNMENT,4) Error: GL\_NO\_ERROR_  
  
_glPixelStorei(GL\_UNPACK\_ROW\_LENGTH,0) Error: GL\_NO\_ERROR_  
  
_glPixelStorei(GL\_UNPACK\_SKIP\_ROWS,0) Error: GL\_NO\_ERROR_  
  
_glPixelStorei(GL\_UNPACK\_SKIP\_PIXELS,0) Error: GL\_NO\_ERROR_  
  
 [end of dump file]  
  
  
  
which matches in my code with  
  
  
  
 _mpo\_GLInterface-\>BindTexture( GL\_TEXTURE\_2D, ui\_Texture );_  
  
  mpo\_GLInterface-\>ReportError( “BindTexture” );  
  
 _mpo\_GLInterface-\>TexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_BASE\_LEVEL, 0);_  
  
_mpo\_GLInterface-\>TexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MAX\_LEVEL, GLint(\_po\_Header-\>GetMipNum() - 1));_  
  
_mpo\_GLInterface-\>TexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MIN\_FILTER, GL\_NEAREST\_MIPMAP\_NEAREST);_  
  
_mpo\_GLInterface-\>TexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MAG\_FILTER, GL\_NEAREST);_  
  
_mpo\_GLInterface-\>TexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_WRAP\_S, GL\_CLAMP\_TO\_EDGE);_  
  
_mpo\_GLInterface-\>TexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_WRAP\_T, GL\_CLAMP\_TO\_EDGE);_  
  
  mpo\_GLInterface-\>ReportError( “TexParameteri” );  
  
 _mpo\_GLInterface-\>TexStorage2D( GL\_TEXTURE\_2D, \_po\_Header-\>GetMipNum(), iInternalFormat, \_po\_Header-\>GetWidth(), \_po\_Header-\>GetHeight() );_  
  
  mpo\_GLInterface-\>ReportError( “TexStorage2D” );  
  
  
  
which should be followed by texture contents setup  
  
  
  
mpo\_GLInterface-\>TexSubImage2D(  
  
GL\_TEXTURE\_2D,  
  
j,  
  
0,  
  
0,  
  
\_po\_Header-\>GetWidth() \>\> j,  
  
\_po\_Header-\>GetHeight() \>\> j,  
  
iComponentFormat,  
  
iComponentType,  
  
pData );  
  
mpo\_GLInterface-\>ReportError( “TexSubImage2D” );  
  
}  
  
  
  
mpo\_GLInterface-\>BindTexture( GL\_TEXTURE\_2D, 0 );

---

<div class="post-metadata">

**Author:** ![PaulLy](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@PaulLy](https://forums.imgtec.com/u/PaulLy)\
**Post date:** [December 10, 2014, 3:22pm UTC](https://forums.imgtec.com/t/pvrtrace-api/2213/6 "2014-12-10T15:22:28Z")

</div>

Great, we’re making progress.  
  
  
  
Could you please send up the PVRTrace file? If you can’t send it publically please create a support ticket on [pvrsupport.imgtec.com/new-ticket](https://pvrsupport.imgtec.com/new-ticket), and attach the PVRTrace file. We can investigate further from there.

---

<div class="post-metadata">

**Author:** ![ronanbel](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@ronanbel](https://forums.imgtec.com/u/ronanbel)\
**Post date:** [December 10, 2014, 7:43pm UTC](https://forums.imgtec.com/t/pvrtrace-api/2213/7 "2014-12-10T19:43:39Z")

</div>

Hi Paul.  
  
BTW I’ve just found some RootZenFone tool to root my device.  
  
Tracing is easier (don’t have to add the Trace .so in the APK), but in my case it is still crashing during capture.
