Monday, October 08, 2018

Enable gc log

When your Java app is running very slow there's a chance that it is caused by some pauses in your app which in turn caused by the diligent garbage collector who loves to take its time cleaning up the memory for you way too often and too long :)

These two steps you might want to do to make sure that it was GC doing its job:
1. Extract the GC log from your app
2. Analyze the log

Extracting GC Log

For extracting the gc log, here's my preferred settings:

-XX:+PrintGCDetails
-XX:+PrintGCApplicationStoppedTime
-XX:+PrintGCApplicationConcurrentTime
-XX:+PrintGCDateStamps
-Xloggc:gc.log
-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=5
-XX:GCLogFileSize=2000k


Add those parameters above on your java runtime parameters, for tomcat you could edit catalina.sh (or catalina.bat), find JAVA_OPTS and add them there.

Restart your Java app or app server and find gc.log on the current directory where you run your java app.

Analyzing GC Log

Refer to the reference 1 below on how to learn to interpret the gc log.
For the tools, choices are you do it using offline tool or online tool.
1. Offline
I'm using GC Viewer (see reference 3 below), simple and easy tool

2. Online
Try gceasy.io, it analyzes your gc log quite awesome :)


Reference:

1. https://dzone.com/articles/enabling-and-analysing-the-garbage-collection-log
2. http://gceasy.io
3. https://github.com/chewiebug/GCViewer

Thursday, October 04, 2018

Updating /etc/hosts in Android emulator

Why? think of it like when all you want is to redirect the target server to another server and you cannot or should not update the dns server and all you need is just one or two lines on the right place ;)

Isn't it as simple as going in and change one or two things? Yes, if it's allowed :)
Anyway here's how we can do it in five simple steps:

1. Assuming emulator is already set up, open the shell and go to the emulator directory under the sdk directory. Start the emulator with this command:

emulator -writable-system -netdelay none -netspeed full -avd {emulator_name}
e.g.
emulator -writable-system -netdelay none -netspeed full -avd Nexus_5X_API_25

2. Go to root mode
Open the shell and run the command:
adb root
3. Remount system partition
adb remount
4. Pull hosts file, edit it as needed
adb pull /etc/hosts hosts
5. Push it back
adb push hosts /etc/hosts

And... we're done, enjoy!