English Amiga Board Amiga Lore


Go Back   English Amiga Board > Support > support.WinUAE

 
 
Thread Tools
Old 14 December 2013, 20:56   #1
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,483
Profiling WinUAE with Visual Studio 2013

I've been playing/experimenting with the profiling facility in Visual Studio 2013.

In my Windows 7 VirtualBox VM I couldn't get the sampling method to work; no samples are captured. Am I doing something wrong or is VirtualBox incompatible with Visual Studio sampling? [With sampling, Visual Studio would periodically check which function is being run. Over time it builds up a statistical picture of the functions which use most CPU time.]

The instrumentation profiling method did work. With that method, a special version of the executable is built, which allows all function calls (and the time taken for each) to be recorded and analysed. However that logging adds a significant amount of overhead to the program.

On starting the instrumented winuae.exe, it takes ages (like about 10 minutes) until the settings window appears. While that isn't a big issue for the normal winuae.exe, maybe this has shown up something which could improve startup time slightly.

The profiling results showed a huge number of calls to free() in this code path:
default_prefs() ⇒ inputdevice_default_prefs() ⇒ inputdevice_default_kb_all() ⇒ set_kbr_default() ⇒ clear_id() ⇒ xfree()

Take a look at clear_id():
Code:
static void clear_id (struct uae_input_device *id)
{
#ifndef	_DEBUG
	int i, j;
	for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) {
		for (j = 0; j < MAX_INPUT_SUB_EVENT_ALL; j++)
			xfree (id->custom[i][j]);
	}
#endif
	TCHAR *cn = id->configname;
	TCHAR *n = id->name;
	memset (id, 0, sizeof (struct uae_input_device));
	id->configname = cn;
	id->name = n;
}
To reduce the number of function calls you could change it to only call xfree() when the argument is non-zero. But look at the loop in set_kbr_default() which calls clear_id():
Code:
	for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) {
		clear_id (kbr);
		kbr->extra[i] = -1;
	}
and compare with the for loop in clear_id() itself. Are you doing a lot of unnecessary free()ing with the two nested for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++)???
mark_k is offline  
AdSense AdSense  
Old 15 December 2013, 16:39   #2
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 42
Posts: 19,561
AFAIK there is option to disable part of c-library allocation function tracing which is the horribly slow part.

I am not going to add extra "if (address) free(address)" because first function of free() is NULL check!
Toni Wilen is online now  
Old 15 December 2013, 19:42   #3
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,483
clear_id() basically does this:
- free all memory entries in the custom[][] array
- zero out the entire uae_input_device structure, except for configname and name fields.

In set_kbr_default() there is this though:
Code:
for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) {
	clear_id (kbr);
	kbr->extra[i] = -1;
}
So for each of the 256 loop iterations (MAX_INPUT_DEVICE_EVENTS is 256) you call clear_id() then set the extra[i] field to -1. But on the next loop iteration, because clear_id() zeros out the structure, the previous extra[i] field is also zeroed. And all the custom[][] memory regions will have been freed on the first loop iteration.

So, would it make sense to move clear_id(kbr) out of the loop, doing this instead:
Code:
clear_id (kbr);
for (i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) {
	kbr->extra[i] = -1;
}
Update: I built WinUAE with that change, and now with instrumented profiling the settings window opens in about 6-7 seconds (on my 6-year-old laptop).

Last edited by mark_k; 15 December 2013 at 21:31.
mark_k is offline  
Old 14 January 2014, 20:26   #4
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,483
I found a blog post from the Visual Studio Profile Team which mentions using profiling in virtual environments. Looks like Visual Studio specifically supports VMWare, Hyper-V and Virtual PC. So it is possible to use the sampling profiling method, just not in VirtualBox.

So was the issue I noted in set_kbr_default() a bug?
mark_k is offline  
AdSense AdSense  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Experimental/testing builds of WinUAE 2.7.0 with VS 2013 mark_k support.WinUAE 18 09 September 2014 22:26
Deluxe Galaga on Amiga Forever 2013/WinUAE problem letsplayac support.Games 3 29 August 2013 20:22
Deli's guide to capture WinUAE output with Camtasia Studio NewDeli support.WinUAE 91 13 November 2009 10:54
Visual FX for imagefx amiga request.Apps 0 30 May 2006 12:08
amiga visual editor thinlega request.Apps 1 22 January 2003 15:48

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 16:40.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.11864 seconds with 11 queries