# How can I measure the program performace on SGX

**URL:** <https://forums.imgtec.com/t/how-can-i-measure-the-program-performace-on-sgx/274>\
**Category:** PowerVR Insider\
**Created:** [March 3, 2009, 6:50am UTC](https://forums.imgtec.com/t/how-can-i-measure-the-program-performace-on-sgx/274 "2009-03-03T06:50:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![windy](https://avatars.discourse-cdn.com/v4/letter/w/91b2a8/32.png) [@windy](https://forums.imgtec.com/u/windy)\
**Post date:** [March 3, 2009, 6:50am UTC](https://forums.imgtec.com/t/how-can-i-measure-the-program-performace-on-sgx/274/1 "2009-03-03T06:50:49Z")

</div>

I use gettimeofday to get the time the draw function takes after using glFinigh. However I don’t think that I get the correct result since the swaq function costs too long.   
&nbsp;  
On the other hand, if I want to get some performace datas, is there any tool that is useful for me?

---

<div class="post-metadata">

**Author:** ![windy](https://avatars.discourse-cdn.com/v4/letter/w/91b2a8/32.png) [@windy](https://forums.imgtec.com/u/windy)\
**Post date:** [March 3, 2009, 7:01am UTC](https://forums.imgtec.com/t/how-can-i-measure-the-program-performace-on-sgx/274/2 "2009-03-03T07:01:41Z")

</div>

I use gettimeofday to get the time the draw function takes after using  
  
glFinish. However I don’t think that I get the correct result since the  
  
swap function costs too long.   
&nbsp;  
On the other hand, if I want to get some performace data, is there any tool that is useful for me?  
  
Hardware: SGX 535  
  
Thanks.

---

<div class="post-metadata">

**Author:** ![prabindh](https://avatars.discourse-cdn.com/v4/letter/p/ce73a5/32.png) [@prabindh](https://forums.imgtec.com/u/prabindh)\
**Post date:** [March 3, 2009, 10:25am UTC](https://forums.imgtec.com/t/how-can-i-measure-the-program-performace-on-sgx/274/3 "2009-03-03T10:25:16Z")

</div>

Can you please post your usage of gettimeofday ? Are you converting correctly&nbsp;from microseconds ? Are you talking about eglswapbuffers call taking too long ?

---

<div class="post-metadata">

**Author:** ![windy](https://avatars.discourse-cdn.com/v4/letter/w/91b2a8/32.png) [@windy](https://forums.imgtec.com/u/windy)\
**Post date:** [March 4, 2009, 12:49am UTC](https://forums.imgtec.com/t/how-can-i-measure-the-program-performace-on-sgx/274/4 "2009-03-04T00:49:56Z")

</div>

gettimeofday(&tv1,&tz);  
glDrawArrays(GL\_TRIANGLE\_STRIP,0,4);  
glFinish();  
gettimeofday(&tv2,&tz);  
printf("%ld",((tv2.tv\_sec-tv1.tv\_sec)\*1000000+(tv2.tv\_usec-tv1.tv\_usec)));  
gettimeofday(&tv1,&tz);  
eglSwapBuffers(eglDisplay, eglSurface);  
  
  
gettimeofday(&tv2,&tz);  
  
  
printf("%ld",((tv2.tv\_sec-tv1.tv\_sec)\*1000000+(tv2.tv\_usec-tv1.tv\_usec)));  
  
I test this using two different fragment shader. If the shader code is simple, all above go fast, and after I saw the Swap time, I can immediately saw the result on screen. However, if the shader&nbsp; contains a lot more computation, I can only saw the result after a small break when I saw the Swap time. I think, after calling glFinish, the client and server should synchronize their operations, then calling the eglSwqpBuffers function shouldn’t result in the latency difference.

---

<div class="post-metadata">

**Author:** ![xmas](https://avatars.discourse-cdn.com/v4/letter/x/958977/32.png) [@xmas](https://forums.imgtec.com/u/xmas)\
**Post date:** [March 4, 2009, 11:39am UTC](https://forums.imgtec.com/t/how-can-i-measure-the-program-performace-on-sgx/274/5 "2009-03-04T11:39:19Z")

</div>

glFinish won’t do what you want. If you really want to make sure rendering is finished use glReadPixels to read a single pixel. In that case you don’t even need to measure eglSwapBuffers. However note that this only gives about the right results if all you draw is a full screen quad and you want to measure the time required for the fragment shader.

---

<div class="post-metadata">

**Author:** ![hnyk](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@hnyk](https://forums.imgtec.com/u/hnyk)\
**Post date:** [June 3, 2009, 6:22am UTC](https://forums.imgtec.com/t/how-can-i-measure-the-program-performace-on-sgx/274/6 "2009-06-03T06:22:16Z")

</div>

Hi  
  
Could you please explain more specifically why glFinish won't work here?  
  
glReadPixels generates an error (GL\_INVALID\_OPERATION / 1282) when I try to use it on beagleboard.  
  
hnyk2009-06-03 09:01:04

---

<div class="post-metadata">

**Author:** ![xmas](https://avatars.discourse-cdn.com/v4/letter/x/958977/32.png) [@xmas](https://forums.imgtec.com/u/xmas)\
**Post date:** [June 3, 2009, 12:12pm UTC](https://forums.imgtec.com/t/how-can-i-measure-the-program-performace-on-sgx/274/7 "2009-06-03T12:12:38Z")

</div>

What is the format/type combination you use, and what is the framebuffer/EGLSurface format?

---

<div class="post-metadata">

**Author:** ![hnyk](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@hnyk](https://forums.imgtec.com/u/hnyk)\
**Post date:** [June 4, 2009, 5:25am UTC](https://forums.imgtec.com/t/how-can-i-measure-the-program-performace-on-sgx/274/8 "2009-06-04T05:25:58Z")

</div>

It works on emulator so there shouldn't be anything wrong with formats.&nbsp; I've asked from google and it could be something with wrong thread executing the command, but I didn't find anything how to fix it.  
  
Anyway, I would still be interested to know why glFinish won't work, since instruction description says that it synchronises CPU and GPU so I gather that it should work. But obviously I have tested it and it won't work, so why?  
  
hnyk2009-06-04 07:28:37

---

<div class="post-metadata">

**Author:** ![xmas](https://avatars.discourse-cdn.com/v4/letter/x/958977/32.png) [@xmas](https://forums.imgtec.com/u/xmas)\
**Post date:** [June 4, 2009, 12:22pm UTC](https://forums.imgtec.com/t/how-can-i-measure-the-program-performace-on-sgx/274/9 "2009-06-04T12:22:04Z")

</div>

hnyk wrote:

It works on emulator so there shouldn't be anything wrong with formats.

  
This is not necessarily true. You could get a different surface format in the emulator, and thus a different format/type combination will work. The only format/type combination that is guaranteed to work in OpenGL ES, no matter the surface format, is GL\_RGBA/GL\_UNSIGNED\_BYTE.  
  
  
  

Quote:

Anyway, I would still be interested to know why glFinish won't work, since instruction description says that it synchronises CPU and GPU so I gather that it should work. But obviously I have tested it and it won't work, so why?

  
It's not implemented that way, partly because of applications which use glFinish improperly.
