Tuesday, November 23, 2004

Of ascetics: Follow-up

oh man! What a misunderstanding. I didn't mean to degrade Kanchi Sankaracharya Jayendra Saraswathi. Not at all. Quite the contrary actually.

I guess if you have done pure Mathematics for as long as I have then you would take the words "reductio-ad-absurdum" for granted too. Its meaning in Mathematics is "proof by the method of contradiction". Basically to prove a hypothesis, you assume that its opposite is true, and then by reducing and simplifying it, you arrive at a known contradiction or absurdity.

I leave it as an exercise to the reader to work back from my contradiction to my hypothesis :-)

Monday, November 22, 2004

Java Profiling with hprof

Ok. I learned something today. I hadn't known that JVM had always included in it a tool for profiling and monitoring Heap and CPU. It seems that we are always fighting preformance problems with Java/J2EE apps. HPROF does come in handy for situations like this. HPROF provides simple profiling based on command line arguments supplied at JVM startup.

Here is how I used it to profile a simple Java application:

java -Xrunhprof:cpu=samples,heap=sites,file=classFinder_profiled.log SomeClass

Some key things to observe in the output:

SITES BEGIN (ordered by live bytes) Mon Nov 22 11:24:13 2004
percent live alloc'ed stack class
rank self accum bytes objs bytes objs trace name
1 22.88% 22.88% 253704 2602 8184488 73802 345 [C
2 22.88% 45.76% 253632 2601 8184488 73802 343 [C
3 16.90% 62.66% 187344 2602 5313744 73802 346 java.util.zip.ZipEntry
4 5.63% 68.29% 62448 2602 1771248 73802 344 java.lang.String
5 4.55% 72.85% 50488 234 50672 240 1 [B
6 4.48% 77.33% 49712 371 50976 397 1 [C
7 2.81% 80.14% 31128 485 621408 497 1 [I
8 2.54% 82.68% 28168 222 29616 251 1 [C
9 2.23% 84.91% 24776 312 24776 312 1 [S

Note the memory allocation that occurs in various parts of the program. The above log shows for example that 16.9% of the total space was allocated for java.util.zip.ZipEntry objects at a particular SITE (a unique stack trace of a fixed depth). The live data figure differs from the total allocated figure, which means that a garbage collection has probably not happened before HPROF iterated over the heap.

There is a lot of useful stuff to pore over in this log. Check it out for yourself. The other thing to note is that these JVM args do affect the performance of your app - obviously because of the large amount of data collection that is involved while running the app.

In Java 5.0 this HPROF has been re-implemented, but I haven't experimented with that yet. We are still in 1.4.1 land in our project, and I don't see us upgrading in the near future.

Of ascetics and heartaches

Much as I hate to talk religion in a supposedly techy blog, I can't help it. This whole Shankaracharya arrest episode has actually shaken my psyche. The drivel dished out by politicos and the media has left me utterly confused and dazed. Talk about FUD - the media - they are of the meanest kind of FUD generators around. Responsibility is not a word in their dictionary it would seem. But they have succeeded in making me question my basics tenets. Sometimes I wish I didn't have to read everything they throw-up, but alas, my right-index finger has its own brain it seems, from the obsessive way it clicks every link that I see on the topic.

Sanatana Dharma says that you pay your respects to Mata, Pita Guru, Deivam - in that order exactly - and that has been drilled into us in childhood. The Guru, or the Acharya, takes a place even before the Lord himself. Can such a man do wrong? Would a "holy" man who lives a life of complete abstinence and celibacy, a man who supposedly has all his "indriyas" under control, a man of no emotion, completely detached from all material possession, a man who has no desires, who has forsaken pleasure and family life, a "gyana margi" who lives for the pursuit of "Knowledge of God" and its dissemination, a man who for the past 50 years has only had a kaavi vasthra and loin-cloth, danda (staff), vibhuti and a rudraksha mala, and drinks only self-cooked kanji (porridge), a man who epitomizes virtue in all ways - Can such a man commit a dastardly crime? Can such a man have someone murdered? Is the very foundation of my belief - and therefore everything that I ever believed in - wrong?

I vividly remember going to Kaladi in Kerala many many years ago, maybe as an eight year old kid. It was a long ride (at the time) from Ernakulam to Kaladi. My Dad rode the Lambretta scooter (KLF 8451) with my mom in the pillion and I was seated in a wide carrier in the rear. My little brother was standing in the front enjoying the thrill of the wind in his face as lorries buzzed past us on NH47. When we got to Kaladi we went to the temple and the Sankara madom and the "puzha" (river). I remember seeing picture stories of the young Adi Sankara along the walls of the madom. While we were sitting there taking in the serene sights, and eating packed lunch, my mother, who is a full-blown Sanskrit scholar now, had narrated to us the story of the crocodile and Adi-Sankara. I remember listening with rapt attention as she described little Sankara's deepest desire to renounce family life and become a Sanyasi. And how Sankara's mom was not too pleased with that idea. And then as Sankara and his mom bathed in the river, the Crocodile caught little Sankara's leg and began taking him down. By this time in the story I was tense with anticipation, and I couldn't wait for the climax...amma appuram ennachu...sollu.... Then when Sankara calls out to his mother saying "Give me permission to become a Sanyasi amma, and I assure you the crocodile will let me go". Sankara's mom, concerned only with the immediate well-being of her child agrees to his request. And lo and behold! The crocodile lets go of Sankara!! And my mom goes on to relate the moral of the story - basically about the power of Faith. At that age, the moral went in one ear and out the other but I was quite happy with the story itself, thinking... wow this Sankara is so cool....getting nasty crocs to let go of him with just a word, he didn't even have to fight the beast!

Now I am a lot older and supposedly wiser. I now understand the moral of that story. However, my own faith is not that strong - after all I am only an ordinary human being and not an Acharya. My mind is fickle, as opposed to the Acharya's. Unholy thoughts cross my mind all the time. I am steeped in materialism. I have a nice car and a house and everything, yet I want more. I am greedy. I have little control over my desires or emotions. I get angry, irrational and stubborn at various times. I can't tell you about the Shankaracharya's case, but I can tell you that irrational thoughts (like murdering someone) HAVE crossed my mind. Heck even the other day I thought Ganguly should be killed because he didn't play Irfan for the Kanpur test. OF COURSE I dismiss these thoughts instantly. I realize I am irrational, though I don't seem to be able to do anything about it. So I am the exact opposite of the acharyas in all respects. In other words "virtue" shouldn't be a word that one would associate with me.

But of late I am really disturbed. I am getting these contradictory thoughts these days. Tell me, Am I really that hopeless? Seriously, am I really that bad? Is it not being virtuous to take care of your family? I don't think about God all the time, but I do pray every now and then. Is that bad? Is it not being virtuous to work hard for your money? Is it not being virtuous to spend it wisely for your family and the community? Is it so bad to maybe indulge a little bit every once in a while? And the most taboo thought of all - are the modern day Sanyasis really more virtuous than I? Yes, I get these thoughts, I admit it. Feels like I got a big weight off my chest, just to have said that.

But wait! How can I even entertain such thoughts. Doesn't it go against everything that I ever believed in? Man what an utter state of confusion and contradiction. Reductio-ad-absurdum. Reduced to absurdity.

There seem to be no answers. Its dark everywhere....can someone turn the light on?

Sunday, November 21, 2004


I found this cool Firefox extension the other day. (btw if you aren't using Firefox yet shame on you!). The plugin is called SwitchProxy (http://jgillick.nettripper.com/switchproxy/). Its a boon for people whose company has multiple firewalls. Back when IE ruled I had always felt the need for such a thing because I was having to go into IE settings and change the proxy server settings very often. SwitchProxy lets you change your proxy server with a mouse click....just check it out yourself. The other extensions I use are "Dictionary Search" (http://dictionarysearch.mozdev.org/), "Copy Plain Text" (http://jgillick.nettripper.com/copyplaintext/), and IE View (http://ieview.mozdev.org/)

While on the subject of Firefox extensions, I don't understand why the plugin developers fail to update their xpi files to keep abreast of the Firefox releases. Its a major gripe that people have with the plugin developers. After some digging I found that it isn't hard at all to make an older version of the plugin work with a new(er) release of Firefox. Its a two minute job in most of the cases. All I had to do was to open the .xpi file with Winzip (yeah it is just a zip file!), extract the install.rdf file out of it, open the .rdf file in a text editor and change the em:maxversion element to 1.00 or whatever your release of Firefox is.

Later then....

Copy one CVS branch over another

I ran into a little CVS problem the other day at work. We had a branch on which we had our stable production codebase. We were starting the next phase of the project and we decided that the new code should be developed in the trunk. Normally in a situation like this one would merge the Production branch into the trunk and tag the trunk as "NEW_DEVELOPMENT_STARTS_HERE" or some such and start developing from there. But the problem was the trunk was in a sort of messed up state from even earlier and the code in the trunk wasn't even compiling. So our decision was to copy over everything from the Production branch and make the trunk an exact copy of the Production branch. We were not interested in retaining the files in the Trunk.

We attempted to do this with the Eclipse CVS repository plugin - with disastrous results, that too after several hours of frustrating merges and compares! Fortunately for us the trunk was messed up from even before the operations. I decided to finally ditch Eclipse and do this from Unix. My personal opinion is that Eclipse just sucks for something like this, but I will vent about that some other time.

Here is how I accomplished it finally:

First login to a Unix box that has access to your CVS repository.

1. Export your production branch to a folder (say prodBranch) with the following command:
$ cvs export -r -d prodBranch
Export ensures that you don't get the CVS subfolders under each folder. You could also, equivalently, checkout your production branch and manually delete the CVS directories.

2. Now checkout the Trunk to another folder (say trunk :-))
$ cvs checkout -d trunk

3. Find all the files in the trunk that are not present in prodBranch.
$ cd trunk; find . -print | sort > ../trunkFiles
$ cd ../prodBranch; find . -print | sort > ../prodFiles
$ comm -23 trunkFiles prodFiles > ./filesInTrunkNotInProd

The entries in filesInTrunkNotInProd (other than the CVS files/dirs) are files that you had either deleted in the Production branch or had added to the trunk after you had branched off your Production branch. Anyway, you are going to have to get rid of these files from the Trunk, since your purpose to make the Trunk an exact copy of the Production branch.

4. Now do a recursive copy of all files from your prodBranch to your trunk. This will give you everything you have in your stable production branch and retains the CVS information for any of those files that you copied over that may have existed in the trunk previously.
$ cd trunk; cp -r ../prodBranch/* .

To make the Trunk an exact copy of Production, the only thing left to do is to delete all those files that you have in your trunk that are not present in your production branch - i.e. the files in the list that you made above filesInTrunkNotInProd (other than the CVS admin files). We will do that in just a little bit.

5. No go into your trunk directory and do:
$ cvs -nq update
This will give you a list of files that are new in your trunk (indicated by a '?') as a result of your recursive copy from Production and the list of files that were modified because of your copy (indicated by an 'M')

6. Do a "cvs add" for all the files indicated by '?'. (if you saved the output from the previous command it would be a lot easier. Jus replace the '?' with 'cvs add')

7. Grep out all the lines in filesInTrunkNotInProd that don't have the word CVS in them (those are the CVS admin files and folder). Save the output in filesToRemove.

8. Do a "cvs remove -f" for all the files in filesToRemove.

9. Now do a "cvs commit".

You should be done.