jeudi 1 janvier 2015

Heavy CPU processing to heat device

My company has created an enterprise app that is used out on the field.


We've discovered that our iPhone 5 does not function properly below 0*C.


One solution we're looking to experiment with is running heavy CPU-intensive tasks (equivalent to running a 3D game) which will add heat to the device (outside of the other external heat we're using to help them).


Using a laser temperature gauge indoors as a baseline, I measured 24*C on the iPhone 5 screen when it's idling on the app home screen. When I launch an intensive 3D game, the phone heats up and the screen registers 35*C within a few minutes.


How can we recreate an intensive background-threaded CPU process that does not consume resources and crash the app? I've tried various open-source iOS benchmark apps from GitHub but when I put them on an infinite loop in a background thread, after a few minutes the app goes out of memory and crashes.


Here's an example of one of the benchmarks I put in to the background on an infinite loop. (while 1=1). No matter what variation of benchmark code I try, the "Total Bytes" will grow without stopping until the app crashes. Click to see Instruments Screenshot.


Does anyone have examples of CPU-intensive code that I could use that would make the device get nice and hot and also prevent the app from eating resources indefinitely?


Battery drain is not an issue as we will use external battery packs connected to offset any drain.


All help appreciated!


Adam



UIApplication * application = [UIApplication sharedApplication];

if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
{
NSLog(@"Multitasking Supported");

__block UIBackgroundTaskIdentifier background_task;
background_task = [application beginBackgroundTaskWithExpirationHandler:^ {

//Clean up code. Tell the system that we are done.
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
}];

//To make the code block asynchronous
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{

//### background task starts
NSLog(@"Running in the background\n");
static NSString *staticString = @"some const value string to referece";
while (1 == 1)
{
NSDictionary *dictionary;
NSString *string;
NSDate *staticStart = [NSDate date];
NSLog(@"start timing");
int times = 10000000;
while (times--) {
static dispatch_once_t onceToken;
static NSDictionary *dict;
dispatch_once(&onceToken, ^{
dict = @{@"somekey":@"someotherlongvalue", @"someotherkey":@"someotherlongvalue", @"onelastkey":@"onelastvalue"};
});
dictionary = dict;
}
NSDate *staticEnd = [NSDate date];
NSLog(@"finished static dict in %f sec", [staticEnd timeIntervalSinceDate:staticStart]);

times = 10000000;
while (times--) {
dictionary = @{@"somekey":@"someotherlongvalue", @"someotherkey":@"someotherlongvalue", @"onelastkey":@"onelastvalue"};
}

NSDate *dictEnd = [NSDate date];
NSLog(@"finished dict create in %f sec", [dictEnd timeIntervalSinceDate:staticEnd]);

times = 10000000;
while (times--) {
static dispatch_once_t stringOnceToken;
static NSString *dispatchString;
dispatch_once(&stringOnceToken, ^{
dispatchString = @"someotherlongvalue";
});
string = dispatchString;
}
NSDate *staticStringEnd = [NSDate date];
NSLog(@"finished static string in %f sec", [staticStringEnd timeIntervalSinceDate:dictEnd]);
times = 10000000;
while (times--) {
string = @"someotherlongvalue";
}
NSDate *stringEnd = [NSDate date];
NSLog(@"finished string create in %f sec", [stringEnd timeIntervalSinceDate:staticStringEnd]);
times = 10000000;
while (times--) {
string = staticString;
}
NSDate *refEnd = [NSDate date];
NSLog(@"finished string reference in %f sec", [refEnd timeIntervalSinceDate:stringEnd]);
}
//#### background task ends

//Clean up code. Tell the system that we are done.
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
});
}
else
{
NSLog(@"Multitasking Not Supported");
}



Aucun commentaire:

Enregistrer un commentaire