-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jmiguel rodriguez
committed
Nov 30, 2015
0 parents
commit 2a9b82f
Showing
23 changed files
with
477 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
Código, notas y Slides de la presentación en Codemotion 2015 de la charla «Crash y YouDebug. Dos viajes al centro de la JVM» , Madrid Nov.2015 | ||
|
||
---- | ||
|
||
Code, notes and slides from my "CRaSH & YouDebug: Two journey to the center of the JVM", Madrid Nov.2015 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
Two example commands (in Spanish, please contact with me if you need help | ||
with them) shown as small CRaSH command examples at Codemotion2015 Madrid | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import org.crsh.cli.* | ||
import org.crsh.command.* | ||
|
||
@Usage("Un par de comandos de prueba para Codemotion 2015") | ||
class cmotionCommands { | ||
@Usage("Comando para decir hola") | ||
@Command | ||
public String diHola( | ||
@Argument @Required String nombre ){ | ||
String hola = metodoHola() | ||
return "${hola} ${nombre}!" | ||
} | ||
def metodoHola(){ | ||
out.println("Estamos en el metodoHola", red) | ||
return "Hola" | ||
} | ||
|
||
// ----------------------------------------------------------------- | ||
|
||
@Usage("Comando para decir adios") | ||
@Man("Informacion extendida del comando diAdios") | ||
@Command | ||
public String diAdios( | ||
@Usage("Tratamiento opcional para incluir") | ||
@Option(names=["t","tratamiento"]) | ||
String tratamiento, | ||
// ------------- | ||
@Argument | ||
@Required | ||
String nombre ) { | ||
|
||
tratamiento = (tratamiento == null ? "" : tratamiento) | ||
out.println("El tratamiento es [${tratamiento}] y el nombre es [${nombre}]", green) | ||
return "Adios ${tratamiento} ${nombre}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
out.println("Hola Codemotioners 2015", green) | ||
return "Aaaadios" // Opcional |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
Notas para liveCoding de Crash. | ||
Codemotion 2015 | ||
|
||
|
||
==================== | ||
STANDALONE | ||
==================== | ||
|
||
Estructura dirs (tree). | ||
cmd base están los fuentes de todo lo que vamos a ver luego | ||
crash.properties. (Las propiedades se pueden sobrescribir desde command line) | ||
Los plugins estan en la carpeta lib. Podemos eliminar cosas que no queremos incluir | ||
|
||
Entramos en modo standalone. Util para probar comandos: | ||
- help | ||
- cmotionHello | ||
- cmotionCommands | ||
|
||
Ventaja: los comandos que hagamos los podemos ejecutar directamente, ventajas de Groovy | ||
|
||
out.println("Hola, yo voy primero" , red) | ||
return "Hola mundo" | ||
|
||
Vemos el cmotionCommands | ||
|
||
|
||
==================== | ||
MODO ATTACH | ||
==================== | ||
|
||
- Enseñamos el setenv.sh (variables de setenv) nos conectamos | ||
- Arrancamos Tomcat, | ||
|
||
crash.sh pid | ||
|
||
|
||
Vemos el runtime en el que estamos | ||
|
||
system propls --filter java.vm.* | ||
-------------------- system propls | egrep /*java*/ | ||
java.runtime.name Java(TM) SE Runtime Environment | ||
java.vm.version 23.7-b01 | ||
java.vm.vendor Oracle Corporation | ||
|
||
Vemos nuestras variables | ||
system propls --filter eu.* | ||
system propset eu.[Tab] | ||
system propls --filter eu.* (cuando conectemos por telnet lo volvemos a ver) | ||
|
||
|
||
==================== VOLVEMOS A DIAPOS ================== | ||
|
||
ENTRAMOS EN MODO SSH | ||
|
||
---------------------------------------... | ||
|
||
|
||
system propls --filter eu.* | ||
|
||
JMX- Manejo de gestion del servidor | ||
|
||
jmx -> | ||
jmx query | ||
|
||
jmx get java.lang:type=Memory | ||
jmx get Catalina:type=Server | ||
jmx get -a NonHeapMemoryUsage java.lang:type=Memory | ||
|
||
|
||
thread ls | ||
thread top | ||
dashboard | ||
|
||
|
||
Enseñamos servlet, hace demo de app web | ||
|
||
thread ls -n 'CODE*' | thread interrupt | ||
|
||
thread dump xxx | ||
|
||
thread ls| thread dump | ||
|
||
--- Interrupt un thread (¿coña?. No demasiado recomendable) | ||
|
||
|
||
Log: | ||
|
||
jul ls | ||
jul send -m "Hola Codemotioners" -l fine net (DEBUG) | ||
jul set -l fine net | ||
jul send -m "Hola Codemotioners" -l warning net | ||
|
||
|
||
Manipulamos los niveles de log de todos los loggers: | ||
|
||
jul ls | jul set -l finest | ||
jul ls | jul set -l info | ||
|
||
jndi --help | ||
jndi find | egrep | ||
jndi find --datasources | ||
|
||
|
||
---- Podemos hacer inserts, select.. de forma practicamente universal | ||
jdbc open java:jboss/datasources/codemotion2015 | ||
|
||
jdbc tables | egrep PUBLIC | ||
|
||
jdbc table clientes | ||
|
||
jdbc execute, jdbc select | ||
|
||
jdbc close | ||
|
||
jdbc connect XXXX cadena de conexion | ||
|
||
JPA si tuvieramos | ||
|
||
------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
src folder contains two small servlets. One to show how CRaSH could | ||
interrupt a Thread from command line and other buggy servlet to show how | ||
YouDebug could help to monkey-patch an application in runtime to solve some | ||
problem. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package eu.jmiguel.cm2015; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
/** | ||
* Handcrafted by jmiguel on Halloween! | ||
*/ | ||
|
||
|
||
public class cmcrash extends javax.servlet.http.HttpServlet { | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, IOException { | ||
procesaPeticion(request, response); | ||
} | ||
|
||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, IOException { | ||
doPost(request, response); | ||
} | ||
|
||
|
||
private void procesaPeticion(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
|
||
String campo1 = request.getParameter("campo1"); | ||
String campo2 = request.getParameter("campo2"); | ||
|
||
String pierdetiempo = pierdeTiempo(); | ||
|
||
PrintWriter out = response.getWriter(); | ||
response.setContentType("text/html"); | ||
out.write("<html><head></head><body bgcolor='#EEEEEE' text='#000000'>"); | ||
out.write("<center><h1>"); | ||
|
||
out.write("<p>Tenemos [" + campo1 + "] y [" + campo2 + "]<p>"); | ||
out.write("<p>Pierde tiempo es [" + pierdetiempo + "]</p>"); | ||
|
||
|
||
out.write("</h1></center>"); | ||
|
||
out.write("</body></html>"); | ||
out.flush(); | ||
|
||
} | ||
|
||
|
||
private String pierdeTiempo() { | ||
String vuelta ; | ||
Long startTime = System.currentTimeMillis(); | ||
|
||
try { | ||
Thread.currentThread().setName("CODEMOTION - " + Thread.currentThread().getName()); | ||
Thread.sleep(15 * 1000); | ||
vuelta = "No nos interrumpen"; | ||
} catch (InterruptedException e) { | ||
vuelta = "Quien osa interrumpir!! (" + (System.currentTimeMillis() - startTime) + "ms)"; | ||
} | ||
|
||
|
||
return vuelta; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package eu.jmiguel.cm2015; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
/** | ||
* Handcrafted by jmiguel | ||
*/ | ||
|
||
|
||
public class cmydb extends javax.servlet.http.HttpServlet { | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, IOException { | ||
procesaPeticion(request, response); | ||
} | ||
|
||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, IOException { | ||
doPost(request, response); | ||
} | ||
|
||
|
||
private void procesaPeticion(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
String nacimiento = request.getParameter("nacimiento"); | ||
|
||
calculaDecada(nacimiento) ; | ||
|
||
Integer nacimientoNumerico = new Integer(nacimiento); // Linea 28 | ||
Integer edad = 2015 - nacimientoNumerico; | ||
|
||
PrintWriter out = response.getWriter(); | ||
response.setContentType("text/html"); | ||
out.write("<html><head></head><body bgcolor='#EEEEEE' text='#000000'>"); | ||
out.write("<center><h1>"); | ||
|
||
out.write("<p>Si naciste en " + nacimiento + " tienes " + edad + " años <p>"); | ||
|
||
out.write("</h1></center>"); | ||
out.write("</body></html>"); | ||
out.flush(); | ||
|
||
} | ||
private String calculaDecada( String anyoNacimiento) { | ||
String decada = anyoNacimiento.substring(2,3) + "0" ; // Linea 44 | ||
return decada; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee | ||
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | ||
version="3.0"> | ||
|
||
<servlet> | ||
<servlet-name>cmcrash</servlet-name> | ||
<servlet-class>eu.jmiguel.cm2015.cmcrash</servlet-class> | ||
</servlet> | ||
|
||
<servlet-mapping> | ||
<servlet-name>cmcrash</servlet-name> | ||
<url-pattern>/cmcrash</url-pattern> | ||
</servlet-mapping> | ||
|
||
<servlet> | ||
<servlet-name>cmydb</servlet-name> | ||
<servlet-class>eu.jmiguel.cm2015.cmydb</servlet-class> | ||
</servlet> | ||
|
||
<servlet-mapping> | ||
<servlet-name>cmydb</servlet-name> | ||
<url-pattern>/cmydb</url-pattern> | ||
</servlet-mapping> | ||
|
||
|
||
</web-app> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<%@ page contentType="text/html;charset=UTF-8" %> | ||
<html> | ||
<head> | ||
<title>CM2015</title> | ||
</head> | ||
<body bgcolor="#FFFFFF" text="#000000"> | ||
<center><h1>Codemotion 2015 - Crash</h1></center> | ||
<form action="/codemotion/cmcrash"> | ||
<center> | ||
<table> | ||
<tr> | ||
<td>Campo 1</td> | ||
<td><input type="text" name="campo1"/></td> | ||
</tr> | ||
<tr> | ||
<td>Campo 2</td> | ||
<td><input type="text" name="campo2"/></td> | ||
|
||
</tr> | ||
</table> | ||
<input type="submit" value="A por ello"> | ||
</center> | ||
|
||
</form> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<%@ page contentType="text/html;charset=UTF-8" %> | ||
<html> | ||
<head> | ||
<title>CM2015</title> | ||
</head> | ||
<body bgcolor="#FFFFFF" text="#000000"> | ||
<center><h1>Codemotion 2015 - Youdebug</h1></center> | ||
<form action="/codemotion/cmydb"> | ||
<center> | ||
<table> | ||
<tr> | ||
<td>¿En que año naciste?</td> | ||
<td><input type="text" name="nacimiento"/></td> | ||
</tr> | ||
</table> | ||
<input type="submit" value="Dime mi edad!"> | ||
</center> | ||
|
||
</form> | ||
|
||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
println vm.virtualMachine.name() | ||
println vm.virtualMachine.description() | ||
|
||
vm.breakpoint("eu.jmiguel.cm2015.cmydb", 44) { | ||
println "Hola! Estoy en la linea 44" | ||
println "Año Nacimiento vale = ${anyoNacimiento}" | ||
} |
Oops, something went wrong.