Tuesday, August 28, 2012

Mac OS X Lion: kernel_task with High CPU

My Mac has occasionally been going nuts and the fans start spinning up like crazy.  Tonight I sat down and took another stab at finding the culprit.

First I took at look with Activity Monitor but nothing obvious in My Processes.  So I switched to All Processes to see what root processes were doing.  Bingo, a nondescript Process Name called kernel_task was eating up just over 100% (110% before turning off some apps).

I read this article (Kernel_task process taking up an inordinate amount of CPU) at MacFixIt, which indicated to start cleaning stuff up (ya, I knew that, housekeeping). 

First I uninstalled some stuff that sounded good but which I just never use:
  • ShoveBox
  • Eye-Fi
Ok, CPU usage on kernel_task now down to about 104%.

Then I brought up the System Preferences -> Sharing panel.  In here I had Bluetooth sharing on for a previous project but I am not currently using it.  So I turned that off.

Bingo!  Kernel_task is down to about a peak of 4% CPU usage now in a steady state (ie. when I am not opening new processes).

The basic gist is that kernel_task is a catchall for a multitude of system processes and hence it can take some rooting around playing with settings to get it to decrease.  Good luck.

Friday, August 24, 2012

Git + Code Collaborator: Post Checkin Code Review

Sometimes you submit your code before you setup a review with code collaborator.  Here are a couple ways to create a code review with code collaborator for git checkins.  I will cover the standard cases, before you stage the code, once the code has been staged for commit, and after you have submitted the code.

With Unstaged Changes

This one is easy, nothing special needed.
git status 
# On branch master 
# Changes not staged for commit: 
#   (use "git add ..." to update what will be committed) 
#   (use "git checkout -- ..." to discard changes in working directory) 
# 
# modified:   changedFile.m 
# 
Now run the command to add a diff of the modified files:
ccollab addgitdiffs new

With Staged Changes

This is not very tricky, but you do need to give the git diff option for staged files, --cached.

git status 
# On branch master 
# Changes to be committed: 
#   (use "git reset HEAD ..." to unstage) 
# 
# modified:   changedFile.m
 Now run the command to add a diff of the cached/staged files:
ccollab addgitdiffs new --cached

With Committed Changes

This one is more tricky.  You have committed the files.  Let's use reflag to see the commits.  Then take the SHA1 hash of the commit you want to diff and the previous commit do a diff between commits.

git status 
# On branch master 
nothing to commit (working directory clean)


As you see, git status will not show any changes since you committer your work.

git reflog
aa90bc4 HEAD@{0}: commit: Changes I forgot to code review.
bb37e6c HEAD@{1}: commit: Some other changes
......

Now use the SHA1 hash of each commit to make your diff:

ccollab addgitdiffs new bb37e6c aa90bc4
Now you should have a code review with the difference between your changes and the previous commit.

Hope that helps

Wednesday, July 18, 2012

Fixing dyld image not found on Mac OS

If you've every used command line process and wanted to relocate it you may have run into the error:

dylib: Library not found:
....
Reason: image not found

You can fix this by doing the following:

  1. Figure out what libraries are dynamically linked to the process using:
    • otool -L process_name
    • Note: You may have to do this for each dynamic library as well and change the paths for the libraries in the dynamic libraries you are linking into your process.  As you can tell this can result in a lot of changes but if you want to move stuff to a new location, it's your best option, as compared to building from source all the required libraries and process.
  2. Change the path of those dynamic libraries using:
    • install_name_tool -change old new process_name
UPDATE:

While relocating the library paths for the library I was working with I came up with a pattern of steps to fix this:

Run: otool -L .dylid For example:

otool -L libintl.8.dylib
libintl.8.dylib:
/opt/local/lib/libintl.8.dylib (compatibility version 10.0.0, current version 10.1.0)
/opt/local/lib/libiconv.2.dylib (compatibility version 8.0.0, current version 8.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.19.0)
 Then notice that we want to change /opt/local/lib/ to /mypath/lib/.  To do that you need to run:
install_name_tool -change /opt/local/lib/libintl.8.dylib /mypath/lib/libintl.8.dylib /path/to/libintl.8.dylib

This works great until you run into this error:

install_name_tool: changing install names can't be redone for: /mypath/lib/libintl.8.dylib (for architecture i386) because larger updated load commands do not fit (the program must be relinked)
[Reference: http://annoyingtechnicaldetails.wordpress.com/2007/04/18/install_name_tool-changing-install-names-cant-be-redone-for-for-architecture-ppc-because-larger-updated-load-commands-do-not-fit-the-program-must-be-relinked/]
To fix this you need to recompile the library with options to enable the relocation of the library paths.  If the library uses configure then chances are you can add these options to the configure to make it build such that the path for the libraries are relocatable:

  1. Add this to your LDFLAGS=-headerpad_max_install_names
  2. And if available use the configure options: --disable-rpath --enable-relocatable Reference[http://www.manpagez.com/info/relocatable/]
  1. So for example here is an example for libiconv:
./configure --prefix=/mypath/ --disable-rpath --enable-relocatable LDFLAGS=-headerpad_max_install_names


Sunday, July 8, 2012

Change Apple Logo on your Mac in Lion

On Mac OS X Lion, you can change the Apple logo to your own logo.  Let's do that now.  Here's a BB logo we want to use:

Grab the file and copy it to your system (let's say /Users/YOUR_USER_NAME/Downloads/BBRocks_256x256.png).

Then open Terminal and type the following to backup the original file:

sudo cp /System/Library/PrivateFrameworks/LoginUIKit.framework/Versions/A/Frameworks/LoginUICore.framework/Versions/A/Resources/appleLinen.png ~/Desktop/

And then this to copy over the Apple logo with your new logo:

sudo cp /Users/YOUR_USER_NAME/Downloads/BBRocks_256x256.png /System/Library/PrivateFrameworks/LoginUIKit.framework/Versions/A/Frameworks/LoginUICore.framework/Versions/A/Resources/appleLinen.png

Since you are running sudo, you will have to enter your password.  This is due to the fact you are copying over the original file which is owned by root.

Now your login window should look like something like this:

Friday, June 22, 2012

Xcode 4, I love you but why do you treat me this way?

When you work on legacy systems (ya, I am calling 10.5 and 10.6 legacy, get over it) you have to work with older dev tools.  So, using Xcode 4 has been something I have only done occasionally in my spare time and when writing prototype code.

Production has been Xcode 3.x until recently.

Sweet, I get to go to the new (ok old) hotness.  So Xcode 4.3.3 we meet.

As first, there were some early courtship fumbles as we got to know each other.  But now I feel like we've been together for a few months, I know where you like to store your derived data, and you know I a fanatic about build clean, build.

But why do you have to keep springing these crazy fits on me.  I mean I try simple things and you just disappear.  Sometimes a simple, sorry, I'll try again is not enough.

Sometimes I have to say, ok, let's start over baby.  I'll just reboot and then it will be like we just met again for the first time.

E...
x...
c...
e...
p...
t...

it's not the first time.

You have a memory like an elephant.

Why just tonight when I opened a project in the wrong folder (it's my Perforce workspace I am using as the backing store for my git-p4 repo, don't ask) you just wouldn't let it go?  I mean, I know, I am sorry.  I said p4 instead of git.  WRONG FOLDER!  My fault!  Let it go!

Then to mess with me, after I restart again, you open the wrong project again without my noticing.  I know, the name was git not p4.  So you get even by launching the git version underneath the p4 version; with the windows aligned perfectly.

What's a guy have to go to get you to forget my mistake?

It's ok, I didn't mean it.

Let me restart you again.

Sunday, February 12, 2012

Making the Leap to Music on BlackBerry

Disclaimer

So you bought a PlayBook on a screaming deal.  Excellent, and thanks, I work at BlackBerry and appreciate your faith in us.  Like you I am a user of BlackBerry products as well and I work with Media (specifically Media syncing).  I write this blog post from the point of view of a BlackBerry user, not an employee, so don't take this as official from Research In Motion (the makers of BlackBerry).

Purchased Music and Your PlayBook

Perhaps like me you have been using iTunes for years to purchase music.  iTunes has been a great source of content as I have moved from physical media to digital content.  I won't talk about the BlackBerry options for syncing your iTunes library to your PlayBook but take a look at the BlackBerry Desktop Software if you'd like to do this.

What I want to talk about today is making the leap to purchasing music on your BlackBerry PlayBook and show you how easy it is to do.

First, swipe up your PlayBook and go to the Music Store app.

Next register a new account (and your credit card with 7 Digital) if you need to, or login to your account.  To get to your account swipe down to get to the "Options".

Purchase some music and you are done for purchasing music.

ReDownloading My Music Later (ie. Do I lose my music if my PlayBook gets wiped?)

Ok, easy, but let's talk about losing your music.  Like what if you had to reset your PlayBook.  Losing Music is not Cool!  (Note, I have never had to reset my PlayBook, I am just using it as an example, I could also say what if it was stolen, lost, you bought a 2nd BlackBerry, etc.)

No problem.  When you are your PlayBook setup after wiping it, or maybe after setting up your 2nd PlayBook, let's get your Music back onto your PlayBook.

Open the Music Store again.


Now choose the "My Purchases" tab to see your past purchases:

Cool, there's your Music.  Let's select my Flash Gordon soundtrack...

"Flash Ah AH...Savior Of The Universe!"....ah, sorry, where were we.  Right, downloading my previously purchased music.

This being Flash let's download the entire album by selecting the Download button under the artwork.

Sweet, here comes Flash.

What if I have a 2nd Device like another PlayBook or a BlackBerry Bold?

No problem.  On the 2nd PlayBook:
  • Do the above.
On the BlackBerry Bold (or Curve or any BlackBerry that has the 7 Digital Music Store App):
  • If the 7 Digital App is not installed on your phone, go to the App World app and search for 7 Digital.
  • Download the app.
  • Setup your 7 Digital account.
  • Download you music.
Purchasing and using music on your BlackBerrys is easy and you can rest assured that you can get your music later when you want it on a new device.


Read More About

Friday, December 30, 2011

Setting the Serial Port of a OSEPP Uno On Mac OS X Lion

I am new to Arduino hacking and as such I installed the latest Arduino software that comes without the need to install separate USB drivers, ie. the FTDIUSBSerialDriver_10_4_10_5_10_6.mpkg file with older Arduino software installs for Mac.

I am on Mac OS X 10.7 (Lion) as well.

So, when I hooked up a second Arduino board I bought yesterday, an OSEPP Uno Rev 1.1, I could not load sketches onto it.

I went to the getting started website for the OSEPP Uno, which suggested setting the board to an “Arduino Duemilanove or Nano w/ ATmega328″ to get it to work. Still nothing.

I looked at the Serial Ports but there were no usbserial ports listed. So, start debugging. I opened the Console and tried unplugging/plugging in the board, sure enough there was an error:

kernel: 0 0 AppleUSBCDC: start - initDevice failed


So, rereading the getting started site, I released that since this board was a little older I might just need to the older drivers.

I downloaded the Arduino 0023 drivers from the Arduino Software page for Mac OS X. I installed just the FTDIUSBSerialDriver_10_4_10_5_10_6.mpkg file.

Restart the Arduino IDE and voila, there should not be a /dev/tty.usbserial-* device that will be the OSEPP Uno board. You can then load your programs.

Hope that helps.