performance problem with IORegistryEntryCreateCFProperties
performance problem with IORegistryEntryCreateCFProperties
- Subject: performance problem with IORegistryEntryCreateCFProperties
- From: Brad Justice <email@hidden>
- Date: Mon, 08 Dec 2008 15:11:49 -0800
My application spawns a POSIX background thread that polls for certain
hardware changes. I have found that according to Activity Monitor and
BigTop it is consuming about 5% of the CPU, which seems inexplicable to me.
The thread loop calls sleep(2) and then begins its checks. Setting
Activity Monitor granularity to 0.5 seconds, I find that every 4 periods
the thread consumes 20% of the CPU, and 0 % for the other three. By
commenting out sections of code, I have isolated the CPU usage to one
loop that executes 7 times. I have confirmed the number of iterations by
single stepping in the debugger.In particular, the execution of seven
paired calls to IORegistryEntryCreateCFProperties and CFRelease result
in 5% CPU usage on my MacBook Pro according to my tools.
Am I misinterpreting my tools, is this an Activity Monitor bug, or are
IORegistryEntryCreateCFProperties and CFRelease heavily CPU intensive
for some reason? It seems to me seven calls every two seconds should not
register activity at this level.
Thanks for any advice that you can provide. Source for the offending
loop below.
classToMatch = IOServiceMatching (kIOHIDDeviceKey);
if (classToMatch)
{
numberRef = NULL;
mach_port_t mport = [myList getMasterport];
result =
IOServiceGetMatchingServices(mport,classToMatch,&iterator);
if (KERN_SUCCESS == result)
{
if(iterator)
{
while( ( serviceObject = IOIteratorNext ( iterator ) ) )
{
CFMutableDictionaryRef hidProperties = 0;
result = IORegistryEntryCreateCFProperties
(serviceObject, &hidProperties, kCFAllocatorDefault, kNilOptions);
if (result == KERN_SUCCESS)
{
serialNumberValue = (NSString *)
CFDictionaryGetValue(hidProperties,CFSTR("SerialNumber"));
if (serialNumberValue != NULL)
{
range = [serialNumberValue
rangeOfString:matchingString];
if (range.length != 0)
{
count++;
}
}
}
CFRelease(hidProperties);
}
IOObjectRelease(iterator);
}
}
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden