mchr3k/org.intrace — pull request #33 by eostermueller (2013-12-06 18:24:06+00:00)
Title: new [gzip-true parm will gzip traced message format on the wire

This small set of changes will allow you to add the [gzip-true command-line parameter to the intrace javagent.
Once set, the agent will gzip all trace data and the UI un-gzips the data.
By default, this parameter is set to false and the new code will never execute.

GZip implementation came from a single java source file in the public domain: http://iharder.sourceforge.net/current/java/base64/
I added this .java to org.intrace.shared package.
This API is invoked in two places: NetworkDataSenderThread and NetworkDataReceiverThread.

See the new junit test org/intracetest/agent/CompressionTest.java for a rough idea of precisely how much smaller the gzipped trace messages are.

I opted not to add a GUI check box for compression to keep this enhancement less complicated.
Once a client connects to the agent, it discovers whether gzip is enabled or not. There is no switching between gzip-true and gzip-false while the connection is established.

The following details the manual testing done to verify this enhancement
############################################################################

########################################################################
## I started the example.TraceExample program using these intrace arguments:
```
java -javaagent:intrace-agent.jar=[regex-example[gzip-true example.FirstTraceExample
```
#######################################################################
## Then I connected the InTrace GUI to 9123.
## Then I get the port number of the trace connection (64097) as follows:
```
eriks-mbp:bin erikostermueller$ lsof -i | grep java
java 20652 erikostermueller 27u IPv6 0xbe49a2b3acba2363 0t0 TCP localhost:64096->localhost:9123 (ESTABLISHED)
java 20652 erikostermueller 28u IPv6 0xbe49a2b3adec28a3 0t0 TCP localhost:64098->localhost:64097 (ESTABLISHED)
java 20731 erikostermueller 24u IPv6 0xbe49a2b3a4efebe3 0t0 TCP *:9123 (LISTEN)
java 20731 erikostermueller 25u IPv6 0xbe49a2b3adec1363 0t0 TCP localhost:9123->localhost:64096 (ESTABLISHED)
java 20731 erikostermueller 26u IPv6 0xbe49a2b3acba2be3 0t0 TCP *:64097 (LISTEN)
java 20731 erikostermueller 27u IPv6 0xbe49a2b3a4eff023 0t0 TCP localhost:64097->localhost:64098 (ESTABLISHED)
java 20745 erikostermueller 24u IPv6 0xbe49a2b3bb084463 0t0 TCP *:9124 (LISTEN)
java 20746 erikostermueller 49u IPv6 0xbe49a2b3a4efe363 0t0 TCP *:9125 (LISTEN)
java 20746 erikostermueller 57u IPv6 0xbe49a2b3a4efe7a3 0t0 TCP *:http-alt (LISTEN)
```
#########################################################################
## The above output showed me that I could trace on 64097.
## So I started the capture with this:
```
sudo tcpdump -s 0 -w myTrace.pcap -i 7 host localhost and port 64097
```
#########################################################################
## Then I displayed the capture with this:
```
tcpdump -r myTrace.pcap -X -q | more
```
#########################################################################
## You can see the base64/gzip text below:
## See the long string of ASCII that started with IAAAAA ?
## That is roughly the start of the base64/gzip data
```
tcpdump -r myTrace.pcap -X -q | more

23:34:00.096086 IP localhost.64098 > localhost.64097: tcp 0
0x0000: 4500 0034 1107 4000 4006 0000 7f00 0001 E..4..@.@.......
0x0010: 7f00 0001 fa62 fa61 a702 c6cc 80b0 9d16 .....b.a........
0x0020: 8010 3292 fe28 0000 0101 080a 0f2f f975 ..2..(......./.u
0x0030: 0f2f f975 ./.u
23:34:00.096110 IP localhost.64097 > localhost.64098: tcp 111
0x0000: 4500 00a3 81d9 4000 4006 0000 7f00 0001 E.....@.@.......
0x0010: 7f00 0001 fa61 fa62 80b0 9d16 a702 c6cc .....a.b........
0x0020: 8018 23e2 fe97 0000 0101 080a 0f2f f975 ..#........../.u
0x0030: 0f2f f975 7400 6c48 3473 4941 4141 4141 ./.ut.lH4sIAAAAA
0x0040: 4141 4141 4973 324d 7259 794e 7245 794d AAAAIs2MrYyNrEyM
0x0050: 4e41 7a73 4453 4e74 596f 326a 4c56 4b72 NAzsDSNtYo2jLVKr
0x0060: 556a 4d4c 6368 4a31 5850 4c4c 436f 7543 UjMLchJ1XPLLCouC
0x0070: 536c 4b54 4535 3168 5967 415a 5a4a 5443 SlKTE51hYgAZZJTC
0x0080: 306f 7938 2f4e 3855 3073 7938 6c4f 7346 0oy8/N8U0sy8lOsF
0x0090: 4b71 7454 4530 414f 694a 7a2f 3049 4141 KqtTE0AOiJz/0IAA
0x00a0: 4141 3d AA=
23:34:00.096134 IP localhost.64098 > localhost.64097: tcp 0
0x0000: 4500 0034 f7a2 4000 4006 0000 7f00 0001 E..4..@.@.......
0x0010: 7f00 0001 fa62 fa61 a702 c6cc 80b0 9d85 .....b.a........
0x0020: 8010 328b fe28 0000 0101 080a 0f2f f975 ..2..(......./.u
0x0030: 0f2f f975 ./.u
```
##########################################################################
## Then, I repeated the above testing without the new gzip compression.
## I started the sample program like this:
```
java -javaagent:intrace-agent.jar=[regex-example[gzip-false example.FirstTraceExample
```
#########################################################################
## But you can also omit the [gzip parameter and you will get the same result,
## which is no gzip compression.

```
23:29:22.319488 IP localhost.64086 > localhost.64085: tcp 0
0x0000: 4500 0034 103b 4000 4006 0000 7f00 0001 E..4.;@.@.......
0x0010: 7f00 0001 fa56 fa55 908f 36e2 9866 4779 .....V.U..6..fGy
0x0020: 8010 214f fe28 0000 0101 080a 0f2b c291 ..!O.(.......+..
0x0030: 0f2b c291 .+..
23:29:22.319502 IP localhost.64085 > localhost.64086: tcp 149
0x0000: 4500 00c9 ca4d 4000 4006 0000 7f00 0001 E....M@.@.......
0x0010: 7f00 0001 fa55 fa56 9866 4779 908f 36e2 .....U.V.fGy..6.
0x0020: 8018 23e2 febd 0000 0101 080a 0f2b c291 ..#..........+..
0x0030: 0f2b c291 7974 004a 5b32 333a 3239 3a32 .+..yt.J[23:29:2
0x0040: 322e 3331 395d 3a5b 315d 3a65 7861 6d70 2.319]:[1]:examp
0x0050: 6c65 2e46 6972 7374 5472 6163 6545 7861 le.FirstTraceExa
0x0060: 6d70 6c65 3a77 6f72 6b4d 6574 686f 643a mple:workMethod:
0x0070: 2041 7267 2028 666f 6f29 3a20 666f 6f62 .Arg.(foo):.foob
0x0080: 6172 7974 0042 5b32 333a 3239 3a32 322e aryt.B[23:29:22.
0x0090: 3331 395d 3a5b 315d 3a65 7861 6d70 6c65 319]:[1]:example
0x00a0: 2e46 6972 7374 5472 6163 6545 7861 6d70 .FirstTraceExamp
0x00b0: 6c65 3a65 7863 6570 7469 6f6e 4d65 7468 le:exceptionMeth
0x00c0: 6f64 3a20 7b3a 3534 79 od:.{:54y
23:29:22.319509 IP localhost.64086 > localhost.64085: tcp 0
0x0000: 4500 0034 25fd 4000 4006 0000 7f00 0001 E..4%.@.@.......
0x0010: 7f00 0001 fa56 fa55 908f 36e2 9866 480e .....V.U..6..fH.
0x0020: 8010 2146 fe28 0000 0101 080a 0f2b c291 ..!F.(.......+..
0x0030: 0f2b c291 .+..
```