1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
/** This method allows to retrieve a specific time from the Oracle Trace file.<br/>
* Commands are directly sent on the database with oracle user.<br/>
* These commands correspond to 'find /../../trace_file_BDB.trc', 'tkprof /../../trace_file_BDB.trc ./javatrace.txt', 'cat javatrace.txt'
*
* @param rs
* @return time from Execution Time
* @throws SQLException
* @throws JSchException
* @throws ClassNotFoundException
*/
public int retrieveTraceTime(ConnectDatas connDatas, String queryToFind, String trace_user_dump_dest) throws ClassNotFoundException, JSchException, SQLException
{
System.out.println("Method retrieveTraceTime");
int time=0;
//String trc_file="";
System.out.println("QueryToFind :"+queryToFind);
try {
ConnectSSH connssh = new ConnectSSH();
sessionSh = connssh.doRemoteConnection(connDatas.getLogin(), connDatas.getPwd(), connDatas.getSsh_host(), "oracle"
, "oracle", connDatas.getRemote_host());
ConnectSSH connssh2 = new ConnectSSH();
String commandFind="find "+trace_user_dump_dest+"/*BDB*.trc";
//trc_file=connssh2.sendCommand(sessionSh, "find /opt/oracle/Oracle11gee/diag/rdbms/orcl/orcl/trace/*BDB*.trc");
trc_file=connssh2.sendCommand(sessionSh, commandFind);
// System.out.println("trc_file :"+trc_file);
trc_file=trc_file.substring(0,trc_file.length()-2);
ConnectSSH connssh3 = new ConnectSSH();
String commandTkprof="tkprof "+trc_file+" ./javatrace.txt";
System.out.println("Commande tkprof : "+commandTkprof);
String tkprof= connssh3.sendCommand(sessionSh,commandTkprof);
ConnectSSH connssh4 = new ConnectSSH();
String trace=connssh4.sendCommand(sessionSh, "cat javatrace.txt");
System.out.println(" cat javatrace "+trace);
time = retrieveElapsedTime(trace, queryToFind);
System.out.println("Le temps trouvé après opérations est :"+time);
ConnectSSH connssh5 = new ConnectSSH();
connssh5.sendCommand(sessionSh, "rm javatrace.txt");
ConnectSSH connssh6 = new ConnectSSH();
String commandRemoveTrc="rm "+trc_file;
System.out.println("Commande remove Trc "+commandRemoveTrc);
connssh6.sendCommand(sessionSh, commandRemoveTrc);
// ConnectSSH connssh7 = new ConnectSSH();
// connssh7.sendCommand(sessionSh, "alter session set sql_trace=false;");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return time;
}
/** This method allows with the Oracle Trace file to retrieve the Elapsed time of the query <br/>
* First, the trace file is parsed with searching the begin of the query 'select s.timeid, ...'<br/>
* In a second time, line with 'elapsed' is searched and columns are counted until finding the word 'elapsed'<br/>
* Finally, at the following line containing 'total', columns are counted and the corresponding time to 'elapsed' is retrieved.<br/>
*
*
* @param trace
* @return - elapsed time from Oracle Trace file
*/
public int retrieveElapsedTime(String trace, String queryToFind)
{
int time=-1;
String line="";
int slashN=trace.indexOf("\n");
line=trace.substring(0, slashN);
while(! line.contains(queryToFind))
{
trace = trace.substring(slashN+1);
slashN=trace.indexOf("\n");
line=trace.substring(0, slashN);
System.out.println("Boucle infinie dans retrievElapsedTime !");
}
System.out.println("Query trouvée !");
while (! line.contains("elapsed"))
{
trace = trace.substring(slashN+1);
slashN=trace.indexOf("\n");
line=trace.substring(0, slashN);
}
System.out.println("Elapsed de query trouvée !");
int nbCol=0;
// Ici la première ligne du texte contient "elapsed"
slashN=line.indexOf("\n");
while (! line.startsWith("elapsed"))
{
//Elimination des espaces en début et fin de ligne
while (line.startsWith(" "))
{
line=line.trim();
}
//Recherche de l'espace suivant
int newIndex = line.indexOf(" ");
line= line.substring(newIndex);
line=line.trim();
nbCol++;
System.out.println("ligne "+line);
System.out.println("Nb Col ds boucle "+nbCol+ " //newIndex "+newIndex);
}
// la colonne est trouvée
System.out.println("NB colonne : "+nbCol);
// on cherche la ligne contenant total
slashN=line.indexOf("\n");
while (!line.contains("total"))
{
trace = trace.substring(slashN+1);
slashN=trace.indexOf("\n");
line=trace.substring(0, slashN);
}
for (int i=0;i<nbCol;i++)
{
line=line.trim();
int newIndex=line.indexOf(" ");
line=line.substring(newIndex);
line=line.trim();
}
int endIndex=line.indexOf(" ");
System.out.println("endindex = "+endIndex);
line=line.substring(0, endIndex);
String resultTime=line;
float floattime=Float.parseFloat(resultTime);
time=(int) Math.floor(floattime);
System.out.println("time "+time);
return time;
} |
Partager