Core Data: I/O Error No Such Column
I'm getting the following error in my application: CoreData: error: (1) I/O error for database at /Users/nick//blah.sqlite. SQLite error code:1, 'no such column: t1.Z_3RELATIONSHIP1 This error only occurs if I build the project in Xcode 4.1 on Lion. If I build the same project on Snow Leopard in Xcode 4.0.2, then it runs as expected. If I launch the code built on 10.6/4.0.2 then it also runs as expected on 10.7. I've narrowed it down to only many-to-many relationships that are causing the issue, too. If I comment out anywhere that accesses [someObj mutableSetValueForKey:@"relationshipKey"] in code and disconnect the relevant bindings in my XIBs, then the application loads and displays the rest of the data fine. The other interesting thing is that if I delete my application data and launch the code built on 10.7/4.1, then it runs as expected - data is saved/loaded correctly. Traditionally I've built against the 10.5 SDK as I supported Leopard, so the database was originally created and managed during the Leopard days. Creating a fresh one on Snow Leopard triggers the same issue. I've tried building on SL for 10.6 and it works fine too. I've searched high and low for others with this issue - I've only found a couple of similar hits, both on cocoa-dev, but unfortunately with no replies: http://www.cocoabuilder.com/archive/cocoa/275386-10-6-2-core-data-incompatibility.html And this one, which seems like a pretty similar issue: http://osdir.com/ml/cocoa-dev/2009-09/msg00709.html So it seems like there is some kind of difference in how many-to-many relationships work somewhere along the line, triggered based on whether I build on SL/4.0.2 or L/4.1. Has anyone encountered this before? I did contact both the posters of those previous threads but unfortunately it didn't lead to a solution. Of course I could stay using 10.6/4.0.2 forever, but that's not ideal. :) This is the stack trace from where I attempt to access a value from one of these relationships, though it's about what you'd expect given the error: 0 CoreFoundation 0x9b466e77 __raiseError + 231 1 libobjc.A.dylib 0x9b25e149 objc_exception_throw + 155 2 CoreData0x9233814b -[NSSQLiteConnection prepareSQLStatement:] + 1435 3 CoreData0x9235f2d0 -[NSSQLChannel selectRowsWithCachedStatement:] + 80 4 CoreData0x923562eb newFetchedRowsForFetchPlan_MT + 875 5 CoreData0x923423d5 -[NSSQLCore newRowsForFetchPlan:] + 325 6 CoreData0x9239b2f4 -[NSSQLCore newFetchedPKsForSourceID:andRelationship:] + 2644 7 CoreData0x9239a235 -[NSSQLCore newValueForRelationship:forObjectWithID:withContext:error:] + 981 8 CoreData0x92399e4e -[NSPersistentStoreCoordinator(_NSInternalMethods) newValueForRelationship:forObjectWithID:withContext:error:] + 78 9 CoreData0x92399db2 -[NSFaultHandler retainedFulfillAggregateFaultForObject:andRelationship:withContext:] + 898 10 CoreData0x923995da -[_NSFaultingMutableSet willRead] + 250 11 CoreData0x923994a3 -[_NSFaultingMutableSet countByEnumeratingWithState:objects:count:] + 35 12 CoreData0x923ba469 -[_NSNotifyingWrapperMutableSet countByEnumeratingWithState:objects:count:] + 57 Cheers, -nick ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Lion doesn't like tricky.key.paths in bindings?
In Interface Builder, I often set a binding like this: Bind to: FooController (an NSObjectController, instantiated in nib) Controller Key: selection (an instance of Foo) Model Key Path: barDate.someFormattingMethod where 'barDate' is an NSDate attribute of 'foo' and 'someFormattingMethod is, for example, a method I've defined in a category of NSDate which formats the receiver into a string. I realize the normal way to do this is with a value transformer, but someone showed me this trick a few years ago, and I've found it to be more convenient and cohesive than value transformers. Until Lion. I've had to rip out several of these recently because, upon changing the content object of the FooController object controller, Cocoa will raise an exception and log one of these turds: Cannot remove an observer for the key path "barDate.someFormattingMethod" from , most likely because the value for the key "barDate" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the Foo class. The problem is solved by either using a value transformer or defining a -barDateString and binding to this simple key instead: Model Key Path: barDateString Added methods in Foo class: - (NSString*)barDateString { return [[self barDate] someFormattingMethod] ; } + (NSSet*)keyPathsForValuesAffectingBarDateString { return [NSSet setWithObjects: @"barDate", nil] ; } Is there anything wrong with my original tricky key path? Why doesn't Lion like it? Thanks, Jerry Krinock___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Determine architecture of a running application
On Jul 22, 2011, at 12:19 PM, danchik wrote: > There might be another issue now, I think safari 5.1 (even when ran in 32bit) > now loads the plugins in another process through > com.apple.WebKit.PluginProcess instead of loading them in the same process as > Safari as it used to before the 5.1 :( In which case nothing wont help since > the plugin in question expects to operate in the same process as the Safari. Yup. This is pretty important for security and stability reasons. (Chrome has always done this.) You’ll need to live with the fact that you’re not in the same process anymore, and fix whatever incompatibility you have. —Jens___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Determine architecture of a running application
what guarantee is there that pligin would be loaded of the same architecture and not proxied through the PluginHost? There might be another issue now, I think safari 5.1 (even when ran in 32bit) now loads the plugins in another process through com.apple.WebKit.PluginProcess instead of loading them in the same process as Safari as it used to before the 5.1 :( In which case nothing wont help since the plugin in question expects to operate in the same process as the Safari. - Original Message - From: "Ken Thomases" To: "danchik" Cc: Sent: Thursday, July 21, 2011 10:57 PM Subject: Re: Determine architecture of a running application On Jul 21, 2011, at 11:34 PM, danchik wrote: Hello, how can one determine if the currently running app is 32bit or 64 Specifically: I have a 32 bit plugin compiled for 10.5+ and it needs to know if it was loaded by 32bit or 64bit Safari You can move this test to compile time. After all, only that variant of your universal binary that was compiled as 64-bit will be loaded by a 64-bit process, and ditto for 32-bit. So, in your code do: #ifdef __LP64__ // 64-bit code #else // 32-bit code #endif If you really want, you can embody this in a function like: static inline BOOL is64Bit(void) { #ifdef __LP64__ return TRUE; #else return FALSE; #endif } Cheers, Ken ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Determine architecture of a running application
I have an existing 32bit plugin that works if loaded in the same process as Safari, but has problems when 64 bit Safari load it through the PluginHost in a different process, so I need to be able to determine what architecture of the safari is running and if it is 64 bit, it would start a new 32 bit safari browser in a new process. - Original Message - From: "David Duncan" To: "danchik" Cc: Sent: Friday, July 22, 2011 9:23 AM Subject: Re: Determine architecture of a running application On Jul 21, 2011, at 9:34 PM, danchik wrote: Hello, how can one determine if the currently running app is 32bit or 64 Specifically: I have a 32 bit plugin compiled for 10.5+ and it needs to know if it was loaded by 32bit or 64bit Safari What do you need to know this for? There is almost certainly a better solution than knowing this, especially since it is likely that you can't know this reliably. -- David Duncan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSDocument: Read-only types and autosavesInPlace
On 22 Jul 2011, at 19:25, Kevin Perry wrote: > > On Jul 22, 2011, at 9:16 AM, Daniel Vollmer wrote: > >> Hello, >> >> I'm trying to add autosavesInPlace support to my NSDocument-based >> Application. It supports a read-only type that is internally converted (as >> suggested in >> https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Documents/Tasks/FAQ.html#//apple_ref/doc/uid/2954-1081265-BAJFDEGD) >> to my writable type. >> >> The viewer- and editor-roles are set correctly in the application's plist, >> +writableTypes also returns only what I can write. For reference, I can read >> .txt and read/write .wowplot. >> >> Now, this seems to interact badly with autosavesInPlace: YES. The following >> happens: >> 1) I open a document of the read-only type (.txt) >> 2) I convert this as suggested above to my writable type, using setFileType >> and setFileURL >> 3) I modify the document >> 4) I attempt to close the document >> 5) Now the autosave-Machinery jumps into action and I get the following >> error: >> [ERROR] genstore_storage.c:GSAddPathAsGeneration:980 copyfile >> "/Volumes/Seerose/Users/maven/Desktop/110720 225338.wowplot" to >> "/Volumes/Seerose/Users/maven/Library/Autosave >> Information/2521980F-37BC-4E21-AF6A-001BE638AEFC.genstore.noindex/.genstore_staging/OUyU4Xi/staged" >> failed with error 2 (No such file or directory) >> >> The errors make sense, as the file under that name never existed. >> >> Now I'm stuck in-between a rock in a hard place: >> If I change the type, autosavesInPlace tries to duplicate a non-existent >> file (because I modified the fileURL); if I don't change the type, >> NSDocument will ask me to write a file of a type I cannot support. >> >> Any ideas? > > > There's a tidbit in the AppKit release notes regarding this (Look for "File > Type Fixing in -[NSDocument > saveToURL:ofType:forSaveOperation:completionHandler:]"). > > While it doesn't say it right out, it suggests that you should give > responsibility for changing to file URL to NSDocument. All you need to do is > change the file type and NSDocument will take care of the file URL and avoid > this error. (Note: you won't get this behavior if you're overriding the old > -saveToURL:ofType:forSaveOperation:error: method.) I've given this a go, but it does not seem to work for me. I set the new fileType after [super readFromURL:...] is done. Then, when - (void)saveToURL:(NSURL *)url ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation completionHandler:(void (^)(NSError *errorOrNil))completionHandler gets called, the arguments are as expected (i.e. the URL is still the original file with the "incorrect" extension and the type is the writable type I set myself), nevertheless, the URL is never changed and it ends up overwriting my original file in the wrong format. :( Could this be due to me using a NSFileWrapper-based directory package (whereas the read-only type is a simple flat-file)? Thanks, Daniel.___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSDocument: Read-only types and autosavesInPlace
On Jul 22, 2011, at 9:16 AM, Daniel Vollmer wrote: > Hello, > > I'm trying to add autosavesInPlace support to my NSDocument-based > Application. It supports a read-only type that is internally converted (as > suggested in > https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Documents/Tasks/FAQ.html#//apple_ref/doc/uid/2954-1081265-BAJFDEGD) > to my writable type. > > The viewer- and editor-roles are set correctly in the application's plist, > +writableTypes also returns only what I can write. For reference, I can read > .txt and read/write .wowplot. > > Now, this seems to interact badly with autosavesInPlace: YES. The following > happens: > 1) I open a document of the read-only type (.txt) > 2) I convert this as suggested above to my writable type, using setFileType > and setFileURL > 3) I modify the document > 4) I attempt to close the document > 5) Now the autosave-Machinery jumps into action and I get the following error: > [ERROR] genstore_storage.c:GSAddPathAsGeneration:980 copyfile > "/Volumes/Seerose/Users/maven/Desktop/110720 225338.wowplot" to > "/Volumes/Seerose/Users/maven/Library/Autosave > Information/2521980F-37BC-4E21-AF6A-001BE638AEFC.genstore.noindex/.genstore_staging/OUyU4Xi/staged" > failed with error 2 (No such file or directory) > > The errors make sense, as the file under that name never existed. > > Now I'm stuck in-between a rock in a hard place: > If I change the type, autosavesInPlace tries to duplicate a non-existent file > (because I modified the fileURL); if I don't change the type, NSDocument will > ask me to write a file of a type I cannot support. > > Any ideas? There's a tidbit in the AppKit release notes regarding this (Look for "File Type Fixing in -[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]"). While it doesn't say it right out, it suggests that you should give responsibility for changing to file URL to NSDocument. All you need to do is change the file type and NSDocument will take care of the file URL and avoid this error. (Note: you won't get this behavior if you're overriding the old -saveToURL:ofType:forSaveOperation:error: method.) The documentation you linked to has not been updated to reflect this. Please file a radar against the documentation to get this updated. -KP___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Determine architecture of a running application
On Jul 21, 2011, at 9:34 PM, danchik wrote: > Hello, how can one determine if the currently running app is 32bit or 64 > > Specifically: > > I have a 32 bit plugin compiled for 10.5+ and it needs to know if it was > loaded by 32bit or 64bit Safari What do you need to know this for? There is almost certainly a better solution than knowing this, especially since it is likely that you can't know this reliably. -- David Duncan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
NSDocument: Read-only types and autosavesInPlace
Hello, I'm trying to add autosavesInPlace support to my NSDocument-based Application. It supports a read-only type that is internally converted (as suggested in https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Documents/Tasks/FAQ.html#//apple_ref/doc/uid/2954-1081265-BAJFDEGD) to my writable type. The viewer- and editor-roles are set correctly in the application's plist, +writableTypes also returns only what I can write. For reference, I can read .txt and read/write .wowplot. Now, this seems to interact badly with autosavesInPlace: YES. The following happens: 1) I open a document of the read-only type (.txt) 2) I convert this as suggested above to my writable type, using setFileType and setFileURL 3) I modify the document 4) I attempt to close the document 5) Now the autosave-Machinery jumps into action and I get the following error: [ERROR] genstore_storage.c:GSAddPathAsGeneration:980 copyfile "/Volumes/Seerose/Users/maven/Desktop/110720 225338.wowplot" to "/Volumes/Seerose/Users/maven/Library/Autosave Information/2521980F-37BC-4E21-AF6A-001BE638AEFC.genstore.noindex/.genstore_staging/OUyU4Xi/staged" failed with error 2 (No such file or directory) The errors make sense, as the file under that name never existed. Now I'm stuck in-between a rock in a hard place: If I change the type, autosavesInPlace tries to duplicate a non-existent file (because I modified the fileURL); if I don't change the type, NSDocument will ask me to write a file of a type I cannot support. Any ideas? Thanks, Daniel. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Core Data dog-slow when using first time after boot
Hello all, I saw an interesting reply from Dr. Hipp posted today: http://www.mail-archive.com/sqlite-users@sqlite.org/msg62618.html This seems to explain why SQLite (and Core Data) might sometimes launch and execute very slowly. -- Tito On Sep 3, 2009, at 5:00 PM, Ben Trumbull wrote: > > On Sep 3, 2009, at 4:49 AM, Ruotger Skupin wrote: > > Since it's not a many to many, you can perform the prefetching > effectively by hand using a fetch request to preload the relevant > destination rows with an IN query based on the data you initially fetched > for the source entity. You shouldn't have to, but if you've run into a > bug, that's how you could workaround it. > > You still haven't described the NSPredicate you were using with > filteredArrayUsingPredicate. Being more forthcoming about the context > and details of your problem will help us get you answers more quickly. This is the predicate I was using for the test of the original post, but since I use Smart Folders predicates can look a lot different (i.e.: complex): (additionalInfo.onTheFlyIsInternal == 0 AND additionalInfo.isSuppressed != 1) AND (account.uniqueID IN {"D1AB3788-00DF-4475-A979-CE3EFC3987B5"} OR FALSEPREDICATE) >>> >>> >>> You'll want to prefetch additionalInfo and account. >> >> Hm. Problem here is: As mentioned I use the predicate for a smart group. So >> the predicate can vary wildly and can reference basically any entity in the >> model. So what is the best strategy here? "Decompile" the predicate (which >> is built by an NSPredicateEditor) and prefetch the keypaths it takes? >> Prefetch "everything"? > > > Prefetching everything is usually undesirable. The easiest approximate > solution is to just track the hot button relationships for each of your core > entities, and look up which keypaths to prefetch by entity name. Of course, > you can also do a lot less filtering in memory if you pass the predicates to > the database with the fetch request. You only need to prefetch relationships > you are going to use in memory. You don't need to prefetch anything that's > simply used as part of the predicate in the fetch request itself. > > Walking through the predicate and gathering up the keypaths used is very > tedious, but not especially difficult, if you find yourself wanting a > complete solution. > > - Ben > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/tciuro%40mac.com > > This email sent to tci...@mac.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
NSDecimalNumber converted to NSNumber
Hi, When I use distributed objects in Lion all NSDecimalNumbers are decoded as NSNumbers. Any thoughts? Thanks, Ferhat ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
NSView trackingAreas and fast enumeration mutation
Hi All, I'm not sure how to track down this issue. A few users of my application have reported the following crash. 0 CoreFoundation 0x7fff8045e7b4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x7fff8354cf03 objc_exception_throw + 45 2 CoreFoundation 0x7fff804b65bf __NSFastEnumerationMutationHandler + 303 3 AppKit 0x7fff853df660 -[NSView trackingAreas] + 271 4 AppKit 0x7fff85434025 -[NSView(NSInternal) _updateTrackingAreas] + 249 5 CoreFoundation 0x7fff803d8d6e CFArrayApplyFunction + 222 6 AppKit 0x7fff85434413 -[NSView(NSInternal) _updateTrackingAreas] + 1255 7 CoreFoundation 0x7fff803d8d6e CFArrayApplyFunction + 222 8 AppKit 0x7fff85434413 -[NSView(NSInternal) _updateTrackingAreas] + 1255 9 CoreFoundation 0x7fff803d8d6e CFArrayApplyFunction + 222 10 AppKit 0x7fff85434413 -[NSView(NSInternal) _updateTrackingAreas] + 1255 11 CoreFoundation 0x7fff803d8d6e CFArrayApplyFunction + 222 12 AppKit 0x7fff85434413 -[NSView(NSInternal) _updateTrackingAreas] + 1255 13 CoreFoundation 0x7fff803d8d6e CFArrayApplyFunction + 222 14 AppKit 0x7fff85434413 -[NSView(NSInternal) _updateTrackingAreas] + 1255 15 CoreFoundation 0x7fff803d8d6e CFArrayApplyFunction + 222 16 AppKit 0x7fff85434413 -[NSView(NSInternal) _updateTrackingAreas] + 1255 17 CoreFoundation 0x7fff803d8d6e CFArrayApplyFunction + 222 18 AppKit 0x7fff85434413 -[NSView(NSInternal) _updateTrackingAreas] + 1255 19 AppKit 0x7fff85433e28 _handleInvalidCursorRectsNote + 451 20 CoreFoundation 0x7fff8041db37 __CFRunLoopDoObservers + 519 21 CoreFoundation 0x7fff803f9464 __CFRunLoopRun + 468 22 CoreFoundation 0x7fff803f8dbf CFRunLoopRunSpecific + 575 23 HIToolbox 0x7fff876f17ee RunCurrentEventLoopInMode + 333 24 HIToolbox 0x7fff876f15f3 ReceiveNextEventCommon + 310 25 HIToolbox 0x7fff876f14ac BlockUntilNextEventMatchingListInMode + 59 26 AppKit 0x7fff85408eb2 _DPSNextEvent + 708 27 AppKit 0x7fff85408801 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155 28 AppKit 0x7fff853ce68f -[NSApplication run] + 395 29 OmniAppKit 0x00010056f774 -[OAApplication run] + 132 30 AppKit 0x7fff853c73b0 NSApplicationMain + 364 31 NovaMind5 0x00011888 start + 52 So it appears that while it is running the "trackingAreas" method of NSView, I must be adding or removing a tracking area. I looked in my code and found: - I have some views that call addTrackingArea in initWithFrame: - I have a controller that creates a view and then calls addTrackingArea on that view. - I have an NSControl subclass that is instantiated in a nib and calls addTrackingArea in its awakeFromNib. I never call removeTrackingArea or updateTrackingAreas in my code, and have not overridden any of the tracking area related methods in my views. I have not been able to reproduce the problem in a test environment, so don't have anything to set a breakpoint on. I'm wondering is any of the tracking rect or cursor rect methods might be using tracking areas behind the scenes, and maybe there is some time when I can't add, remove or invalidate them? I have looked through my code for anything suspicious there, and haven't found anything, but then I'm not exactly sure what I'm looking for. The crashes I have seen so far have all been on Snow Leopard, but given the youth of Lion I can't rule out it being present there too. Any debugging suggestions would be very welcome. Regards Gideon ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Timing some code execution outside Instruments
On Jul 21, 2011, at 7:59 PM, Eric E. Dolecki wrote: > I'm curious if there is a way to NSLog how long some code takes to execute > (outside of using Instruments). > > In Flash one can use getTimer and see how much time passed inline. Is there > a way to do this in Obj-C? > > Would one use a NSDate object? For better accuracy, you may use function mach_absolute_time(). For example: #include #include static uint64_t absoluteTimeToNanoseconds(uint64_t t) { static mach_timebase_info_data_t sTimebaseInfo; // (note: static data will be zero initialized) // setup the mach timebase info if ( sTimebaseInfo.denom == 0 ) { (void) mach_timebase_info(&sTimebaseInfo); } uint64_t elapsedNano = t * sTimebaseInfo.numer / sTimebaseInfo.denom; return elapsedNano; } void foo() { uint64_t t0 = mach_absolute_time(); // do some stuff … // ... uint64_t t1 = mach_absolute_time(); uint64_t elapsedNanoseconds = absoluteTimeToNanoseconds(t1 - t0); NSLog(@"Elapsed time: %.2f ms", elapsedNanoseconds*1e-6]; } There is also the tool "time" (see man time(1)) which can be used to measure runtime of executables running in the console. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: "Nested" runloops
Ken Thomases wrote: On Jul 20, 2011, at 8:01 AM, Eric Matecki wrote: I have to port a software to take advantage of 64 bits adressing. The software was originally written for Windows... So there isn't any real runloop, but there are GetMsg() function calls spread all around the source code (in about 200 files out of the 1000+ !!). My condolences. :) I create a NSWindow and put a subclass of NSOpenGLView as contentView: In that view I override all event processing methods, "decode" the event into our own event structure, and append it to our event queue. In this 'append to queue' method, after appending the event, if it is the first time it is called, I call the working function of the software, which will call GetMsg() from everywhere. You should probably call the working function from -applicationDidFinishLaunching: or the like. Or maybe an override of -[NSApplication run] (see below). GetMsg(), if our event queue is empty, tries to get new 'native' events and decodes and append them to the queue. Thats where my problems really start. I tried all of these : NSRunLoop* runloop = [NSRunLoop currentRunLoop]; assert(runloop); [runloop acceptInputForMode: NSModalPanelRunLoopMode beforeDate: [NSDate dateWithTimeIntervalSinceNow: 1]; //[runloop acceptInputForMode: NSDefaultRunLoopMode beforeDate: [NSDate dateWithTimeIntervalSinceNow: 1]]; //[runloop runMode: NSDefaultRunLoopMode beforeDate: [NSDate dateWithTimeIntervalSinceNow: 1]]; //[runloop runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1]]; The 'timeout' of 1 second is so I have time to read the traces in the console. What happens is: - when I do nothing with the window, the timeout 'fires' and GetMsg() returns nil after one second. - when I 'draw' with the mouse (down,drag,up), the method I call on runloop returns (almost) instantly, thus the event has been processed somehow, but the event methods in my view AREN'T called !! Anything I'm doing wrong ? (beside the fact I really should be using the runloop as it was meant to, but can't ...) The connection to the window server for receiving events is a run loop source, but that source's handler merely queues the event internally. It doesn't dispatch the event. The event is dequeued by -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] and dispatched via -[NSApplication sendEvent:]. It is -[NSApplication run] which normally does this. Review the class overview for NSApplication. Also, see the GLUT sample code linked to from the documentation for -[NSApplication run]. That sample re-implements -run, which will give you some idea of how to do the same. http://developer.apple.com/library/mac/#samplecode/glut/Listings/GLUTApplication_m.html You'll need to turn that run method inside out for your GetMsg() implementation. Good luck, Ken Thanks ! That's a great sample I overlooked somehow. Now I have to take it appart to understand all the details of its inner working. Eric M. -- Keep intel OUTSIDE my Mac ! Hiii !!! I can see Intel chips creeping around my G5 ! Eric M. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com