kamens/gae_mini_profiler — pull request #69 by phleet (2013-11-18 15:18:35+00:00)
Title: Add import guard and installation instructions on line profiler for non OSX users

## Test Plan:

On OSX, load up a page with the profiler turned on and change the profiling mode to line-by-line.
You should see usage instructions as normal.

Now replace the `_line_profiler.so` file with a garbage file, e.g. like this:
```
echo 'garbage' > _line_profiler.so
```
This is to emulate wrong architecture trying to be loaded.
Reload the page in browser, and you should be presented with a message similar to this once you expand the profiling results:

```
Could not load line_profiler c extension.

Try installing it like so:
sudo pip install line_profiler==1.0b3
(cd / && cp `python -c 'import _line_profiler; print _line_profiler.__file__'` /Users/jlfwong/khan/webapp/third_party/gae_mini_profiler)
```

Except with the paths customized for your installation.
Run the commands, reload the page, and you should see usage instructions again.

## Notes:

My original plan of trying to import it from several different sources was canned because apparently the import name you give when importing a c extension has to match some internally compiled function. For instance:

```
$ python -c 'import _line_profiler; print _line_profiler.__file__'
_line_profiler.so
$ mv _line_profiler.so _line_profiler_osx.so
$ python -c 'import _line_profiler_osx; print _line_profiler_osx.__file__'
Traceback (most recent call last):
File "", line 1, in
ImportError: dynamic module does not define init function (init_line_profiler_osx)
```

I tried to get around this using

```
import imp
fileobj, path, desc = imp.find_module('_line_profiler_osx')
imp.load_module('_line_profiler', fileobj, path, desc)
```

which works when I tried it in the REPL, but not when I tried using it in `line_profiler.py`. I suspect this is GAE sandboxing in action.

@cdman @spicyj @kamens