strace for Mac OS X

August 13th, 2010 — 11:16pm

In Leopard it’s called dtrace, but it’s simpler if you just call dtruss

Here is the manual:

NAME
dtruss – process syscall details. Uses DTrace.
-
SYNOPSIS
dtruss [-acdeflhoLs] [-t syscall] { -p PID | -n name | command }
-
DESCRIPTION
dtruss prints details on process system calls. It is like a DTrace ver-
sion of truss, and has been designed to be less intrusive than truss.
Of particular interest is the elapsed times and on cpu times, which can
identify  both  system calls that are slow to complete, and those which
are consuming CPU cycles.
Since  this  uses  DTrace,  only  the  root  user  or  users  with  the
dtrace_kernel privilege can run this command.
-
OPTIONS
-a     print all details
-b bufsize
dynamic  variable  buffer  size.  Increase  this  if  you notice
dynamic  variable  drop  errors.  The  default  is  ”4m”  for  4
megabytes per CPU.
-c     print system call counts
-d     print relative timestamps, us
-e     print elapsed times, us
-f     follow children as they are forked
-l     force printing of pid/lwpid per line
-L     don’t print pid/lwpid per line
-n name
examine processes with this name
-o     print on-cpu times, us
-s     print stack backtraces
-p PID examine this PID
-t syscall
examine this syscall only
-
EXAMPLES
run and examine the “df -h” command
# dtruss df -h
examine PID 1871
# dtruss -p 1871
examine all processes called “tar”
# dtruss -n tar
run test.sh and follow children
# dtruss -f test.sh
run the “date” command and print elapsed and on cpu times,
# dtruss -eo date
-
FIELDS
PID/LWPID
Process ID / Lightweight Process ID
RELATIVE
relative  timestamps  to  the start of the thread, us (microsec-
onds)
ELAPSD elapsed time for this system call, us
CPU    on-cpu time for this system call, us
SYSCALL(args)
system call name, with arguments (some may be evaluated)
-
DOCUMENTATION
See the DTraceToolkit for further documentation under the  Docs  direc-
tory. The DTraceToolkit docs may include full worked examples with ver-
bose descriptions explaining the output.
-
EXIT
dtruss will run forever until Ctrl-C is hit, or if a command  was  exe-
cuted dtruss will finish when the command ends.
-
AUTHOR
Brendan Gregg [Sydney, Australia]
-
SEE ALSO
procsystime(1M), dtrace(1M), truss(1)

Comment » | Bash Shell

Bathroom Remodeling

August 13th, 2010 — 11:15pm

2008-11
We bought this house in Nov 2008. I am Japanese and taking bath has been just my part of my life. However, we fall in love with this house so much that we accepted fact that the house only had Shower in Master. We were thinking… well, bathtub can be easily installed! We can knock down the closet and place shower there and place bathtub where current shower stall is.

2010-01
So yeah… about one year has passed. We got estimate from a few contractors and I was like wow… placing bathtub is not so cheap especially in our case, major pluming work was involving. First we got estimate from homeDepot. They told me it will be like $30K. Then we met a couple of contractors – both were like $13k or so… because of the limited space we have, I have to pick small bathtub and of course, smaller shower…. I just didn’t see the value paying that much to have small bathtub with smaller shower space… Long story short, I decided that steam sauna is what I want…
1) Greener – it use much less water than bath
2) Don’t have to sacrifice on shower space
3) and a lots of benefit – just google “steam sauna benefit”

old bathroom

Old Bathroom

2010-08
We found one company called Bath-Pro who we feel we can trust and offers very reasonable price. The construction was finally started on Aug 9th.

2010-08-09 [Day 1]
They did demo

Bathroom Remodeling Day 1

Bathroom Remodeling Day 1

2010-08-10/11 [Day 2 & 3]
They placed bench and soffit ceiling so that they can tile the ceiling.

Bathroom Remodel Day 3

Bathroom Remodel Day 3

2010-08-10/11 [Day 4~]
I got too excited about design and forgot to check some critical thing.. Permit. My husband thought that they are professional so he assumed that they already got permit for this construction. But I wasn’t sure so I checked with them… they told me it is up to home owner… We requested Permit from city. Phew… good thing we checked with them. If you google “bathroom remodiling permit”, you will see all kinds of helpful information. We decided that getting Permit is right thing to do especially installation of Steam Sauna involves running electric cable etc…

Comment » | Home Improvement

Home Solar – Lease or Purchase

August 6th, 2010 — 5:19am

I have read great things about SolarCity and Sungevity – I believe they are the two leading solar leasing company at the time of writing.

I got estimate form both companies. They do lease very differently…

SloarCity ask you for some down payment then low monthly fee for 20 years regardless of power company you are with.

Sungevity on the other hand requires No down payment. This is probably the only way to go if you have no cache. No down payment and you can go green. Sugevity also wants “inflation rate” to be added every year. So my monthly payment will increase 2.5% every year. This isn’t too bad considering recent energy rate increase.

Both SolarCity and Sungevity will give you “Performance Guarantee” with lease option – meaning that if Solar System generates less than what they projected, they will pay you. Also maintenance is included. So going Solar not only help our planet but also save us money guaranteed!!!! At this point I just could not find any reason why we don’t want to go Solar.

Before we decide to go with this lease option I wanted to see what purchase option would be… Lease make Solar system VERY affordable but after 10/20 years, it is not yours… You end up paying about $20K and you will be given option to purchase at the end of the lease.

So I wanted to see what Purchase option might look like. I reviewed some discussion about Solar lease vs purchase. Both side has valid point. Some says lease is scam… but I don’t think so… Yes you end up paying more money than purchase option but there are many people out there who just cannot come up with cache. Though in my research, if you have cache, purchase is the definitely the way to go.

Purchase option with Sangevity and SolarCity weren’t so fascinating. I think this is because they are trying to promote lease option more than purchase option.

I got quote from American Solar Electric. After the Rebate and Federal Credit, I will end up paying something like $8500. I am going to get quote from other company and see but my mind has almost decided. I will go with purchasing option.

I was listening to NPR this morning saying that my power company lost millions of revenue due to energy efficient rebate etc… so they will increase rate again in 2012 or 2014 (can’t remember) so again, it just no brainer… having own power generator is the way to go.

Comment » | Green Living

Latin 1 to UTF-8

August 5th, 2010 — 7:35am

Long story short, I was doing some screen scraping on web application. My web app use Latin 1 and target is using UTF-8. So I had a few issues to resolve in order for it to work…

1. Display Issue: If target site has beyond ascii character, it wasn’t displaying correctly. To resolve this was easy. I walk through the characters and replaced with html encode if character code is higher than base ascii….(yes i know… the scripting language that I use doesn’t offer nice libraries…)

2. Posting Issue: This was the pain one… because my web app use Latin 1, anything higher than ascii is translated as HTML Encoding. So to post to UTF-8 site, there are 2 steps involving. (1) Convert HTML Encoded character to Unicode (2) Convert Unicode to URL Encode
2.1. Convert HTML Encoded character to Unicode: This is very simple. Basically use this regenx pattern “&#[0-9]{3.5};” to look for HTML Encoded character and extract numeric only and wrap with command to convert it to character (for instance in php it is chr).

2.2. Convert Unicode to URL Encode: Now that you have Unicode prepared, all you have to do is to do url-encoding! (and no, the scripting language i use doesn’t offer native solution. and yes, I have plan to switch scripting language. so this is for person like me who stuck with language that offers very limited set of libary)
2.2.1. My First Attempt: use curl –data-urlencode option. Please note that this was added in version 7.18.0. If you are Mac user like me, you can install/upgrade curl using MacPorts or you can download source from here and install. Unfortunately I could not use this option… because there is one restriction to this – “content cannot contain = or @ symbols, as that will then make the syntax match”.
2.2.2.My Second Attempt: Relies on Shell… Now this is almost always works! I decided to use php rawurlencode. Calling like this from terminal works like a charm.

$ php -r “echo rawurlencode(‘ξακσλξ’)

Issue the command via plugin to execute shell command did not work. It is not unicode supported so it end up returning url encode of ??????
I contacted plugin vendor and he is planning to release unicode support soon… so until then somehow

My co-worker found this article: http://akameng.com/web/php_utf_unicode_convertor. Ooooo, this shows the formula to how to convert this using integer division and multiplication without using bitwise operation. This article also explains this formula.
If ud <128 (7F hex) then UTF-8 is 1 byte long, the value of ud.

If ud >=128 and <=2047 (7FF hex) then UTF-8 is 2 bytes long.
byte 1 = 192 + (ud div 64)
byte 2 = 128 + (ud mod 64)

So as a final product (for now) I have code like this:

$ php -r “echo rawurlencode(chr(206).chr(190).chr(32).chr(32).chr(195).chr(169).chr(110).chr(100));”

I am done for now.

Comment » | PHP

Inspirational Movie FUEL

July 18th, 2010 — 6:22pm

The movie was released in 2008 but I just found this today while browsing new avaialble on Netflix.
Josh Tickell just refused to give up to make change for human and mother earth.
Thank you very much for the inspiration.

Comment » | Green Living

PostgreSQL: Dump Schema Only or Triggers Only

July 17th, 2010 — 2:59pm

I needed to extract triggers only, sequence/index only etc when we migrated database.
I received advice from postgresql General List and thought I should post exact step/script of how to accomplish this.

Open Terminal:

1. dump schema only

pg_dump -h localhost -p 5432 –username UserName –schema-only –format c –file path_to_backup.backup –schema ‘public’ db_name

2. create list of item that you want to extract
2.1. TRIGGERS only

pg_restore –list “path_to_backup.backup” | awk ‘/[0-9]*; [0-9]* [0-9]* (TRIGGER)/ { print }’ > “path_to_triggers.list”

2.2. SEQUENCE, INDEX

pg_restore –list “path_to_backup.backup” | awk ‘/[0-9]*; [0-9]* [0-9]* (SEQUENCE|INDEX)/ { print }’ > “path_to_seq.list”

3. Create SQL script from the list
3.1. TRIGGERS only

pg_restore -L path_to_triggers.list -f dest_path_triggers.sql path_to_backup.backup

3.2. SEQUENCE, INDEX

pg_restore -L path_to_seq.list -f dest_path_seq.sql path_to_backup.backup

Comment » | Bash Shell, PostgreSQL

nightly backup (pg_dump) with shell script and cron job

July 10th, 2010 — 8:00am

1. write a shell script

#!/bin/bash
#backup.sh
logfile=”/backups/logfile.log”
# Location to place backups.
backup_dir=”/backups”
touch $logfile
timeslot=`date +%y%m%d_%H%M`
databases=(“db1″ “db2″ “db3″)
# get length of an array
tLen=${#databases[@]}
for (( i=0; i<${tLen}; i++ )); do
echo “Vacuum Starting at `date` for database: ${databases[$i]} ” >> $logfile
timeinfo=`date ‘+%T %x’`
psql -c “vacuum verbose analyze” -d ${databases[$i]} -U postgres >> $logfile
echo “Vacuum completed. Backup Starting at `date` for database: ${databases[$i]} ” >> $logfile
pg_dump ${databases[$i]} -h 127.0.0.1  -U postgres | gzip > “$backup_dir/${databases[$i]}-$timeslot-backup.gz”
echo “Backup and Vacuum complete at `date` for database: ${databases[$i]} ” >> $logfile
done

2. Add an entry to crontab to execute the script above
2.1. open terminal and login as postgres: $ su – postgres
2.2. list cron job: $ crontab -l
2.3. edit cron job:
2.3.1. $ crontab -e #in terminal vi editor will open)
2.3.2. i for insert mode
2.3.3. enter entry. for instance, to run it every 1 am:

00 01 * * * path_to_backup.sh > /dev/null

2>&1
2.3.4. ESC key to exist edit mode
2.3.5. :wq to save and quit

Comment » | PostgreSQL

great moral leader are made of:

July 6th, 2010 — 2:13am

I salute the man who is going through life always helpful, knowing no fear, and to whom aggressiveness and resentment are alien.

- Albert Einstein

Comment » | inspirational quotes

Install NetBeans 6.9 to OS X 10.5.8

July 5th, 2010 — 11:23pm

NetBeans 6.9 is a great PHP IDE and I have been pretty happy about it. Although initially, I almost gave up installing this on my MacBook Pro – After installation was done and launch the application I have encountered an error saying “Cannot run on older version of Java 6 Standard Edition.
Please install Java 6 Standard Edition or newer or use –jdkhome switch to point to its installation directory.

To solve this problem:

Application: Utilities: Java Preference >> Drag Java SE 6 to the top

If this doesn’t fix the issue try:

Terminal: type “env”. Do you see JAVA_HOME is defined? If so, is this pointing to older version? If so fixing that should resolve the issue (at least it resolved my case). Here is how I fixed:

  1. my JAVA_HOME was set to

    /Library/Java/Home

    which was simply the symlink to

    System/Library/Frameworks/ JavaVM.framework/Versions/1.5.0/Home

  2. rename the symlink to Home_old
  3. then create new symlink point to 1.6 (SE 6) as follows: ln -s

    /System/Library/Frameworks/ JavaVM.framework/Versions/1.6.0/Home /Library/Java/Home

4 comments » | PHP

Back to top