11package org .ogo .client ;
22
3- import java .io .BufferedWriter ;
43import java .io .File ;
5- import java .io .FileNotFoundException ;
6- import java .io .FileOutputStream ;
74import java .io .IOException ;
8- import java .io .OutputStreamWriter ;
95import java .nio .charset .StandardCharsets ;
106import java .rmi .NotBoundException ;
117import java .rmi .RemoteException ;
128import java .rmi .registry .LocateRegistry ;
139import java .rmi .registry .Registry ;
1410import java .security .MessageDigest ;
15- import java .text .SimpleDateFormat ;
1611import java .util .*;
1712import java .util .logging .Logger ;
1813import org .ogo .bridge .AbstractGraphQueryInterface ;
1914import org .ogo .util .FileHelper ;
2015import org .ogo .util .OGOProperties ;
21- import org .ogo .util .Profile ;
2216
2317/**
2418 * @author 1sand0s
@@ -30,15 +24,12 @@ public abstract class OGO {
3024 static long sTime ;
3125 static long eTime ;
3226 static File profileFile ;
33- static ArrayList <String > profileData ;
34- static String profileMethod ;
3527 private static String CsvPath = "." ;
3628 private static GraphTriggerException graphException ;
3729 public static boolean printCSV = false ;
3830 public static boolean printWhiteList = false ;
3931 public static boolean printBlackList = false ;
4032 public static boolean clearDatabase = true ;
41- public static boolean printProfileMethodInfo = false ;
4233 public static boolean inMemory = false ;
4334 public static boolean followRoot = true ;
4435 public static boolean forceGC = true ;
@@ -434,24 +425,16 @@ public static Object[] query(Object root, String cQuery, Object... objects)
434425 */
435426 try {
436427 if (!inMemory ) {
437- sTime = System .currentTimeMillis ();
438428 var = graphInterface .query (cQuery );
439- eTime = System .currentTimeMillis ();
440- profileData .add ("Assert_Query, " + (eTime - sTime ));
441429 }
442430 } finally {
443-
444431 /*
445432 * Clear and delete database
446433 * Delete all *.csv files
447434 */
448- sTime = System .currentTimeMillis ();
449435 cleanup ();
450- eTime = System .currentTimeMillis ();
451- profileData .add ("Cleanup, " + (eTime - sTime ));
452436 }
453437
454- if (!profileMethod .isEmpty ()) writeProfileFile (profileData );
455438 if (inMemory ) {
456439 return graphException .getQueryResults ();
457440 }
@@ -461,40 +444,21 @@ public static Object[] query(Object root, String cQuery, Object... objects)
461444 }
462445
463446 private static void setupGraph () throws RemoteException {
464- /*
465- * Read the Profile Data Generated from JVMTI invocation required to create
466- * object graph
467- */
468- profileData = new ArrayList <>();
469447
470- sTime = System .currentTimeMillis ();
471448 try {
472449 /* Dummy exception to trigger object graph construction by native agent */
473450 throw graphException ;
474451 } catch (Exception | Error e ) {
475452 logger .finest ("GraphTriggerException caught (expected behavior)" );
476453 logger .finest ("JVMTI agent triggered successfully" );
477454 }
478- eTime = System .currentTimeMillis ();
479-
480- readJVMTIProfile (profileData );
481- profileData .add ("Graph_Generation, " + (eTime - sTime ));
482-
483- /* Get calling test method */
484- profileMethod = getTestMethodName ();
485455
486456 if (!inMemory ) {
487- sTime = System .currentTimeMillis ();
488457 /* Create nodes from *java.csv files */
489458 graphInterface .createNodes ();
490- eTime = System .currentTimeMillis ();
491- profileData .add ("Creation_of_Nodes, " + (eTime - sTime ));
492459
493- sTime = System .currentTimeMillis ();
494460 /* Create relations from [*TAG*]_Neo4JRelations.csv files */
495461 graphInterface .createRelations ();
496- eTime = System .currentTimeMillis ();
497- profileData .add ("Creation_of_Relations, " + (eTime - sTime ));
498462 }
499463 }
500464
@@ -523,82 +487,6 @@ private static void cleanup() throws RemoteException {
523487 }
524488 }
525489
526- private static void writeProfileFile (ArrayList <String > profileData ) {
527-
528- SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd-HH-mm-ss-z" );
529- Date date = new Date (System .currentTimeMillis ());
530- /* Open file for writing whitelist of packages */
531- File file = new File (CsvPath + "/PROFILE_JAVA_" + profileMethod + "_" + formatter .format (date ));
532-
533- try {
534- /* Create a buffered writer for writing to file */
535- BufferedWriter writer =
536- new BufferedWriter (new OutputStreamWriter (new FileOutputStream (file )));
537-
538- /* Write blacklist of packages to file */
539- for (String profileDatum : profileData ) writer .write (profileDatum + "\n " );
540-
541- writer .close ();
542- } catch (FileNotFoundException e ) {
543- logger .severe ("Error : File " + file .getName () + " could not be opened " + file .getPath ());
544- logger .severe ("Unable to write profile data" );
545- logger .severe (e .getMessage ());
546- } catch (IOException e ) {
547- logger .severe ("Unable to write profile data " + file .getName ());
548- logger .severe (e .getMessage ());
549- }
550- }
551-
552- private static void readJVMTIProfile (ArrayList <String > profileData ) {
553- profileData .clear ();
554- for (File f : Objects .requireNonNull (new File (CsvPath ).listFiles ())) {
555- if (f .getName ().startsWith ("PROFILE_HOQ_C_" )) {
556- Scanner scan ;
557- try {
558- scan = new Scanner (f );
559- while (scan .hasNext ()) {
560- profileData .add (scan .nextLine ());
561- }
562- } catch (FileNotFoundException e ) {
563- logger .severe ("Error : File " + f .getName () + " not found in path " + f .getPath ());
564- logger .severe ("Unable to read JVMTI profile file" );
565- logger .severe (e .getMessage ());
566- }
567- }
568- }
569- }
570-
571- private static String getTestMethodName () {
572- String methodName = "" ;
573-
574- for (StackTraceElement st : Thread .currentThread ().getStackTrace ()) {
575- try {
576- if (Class .forName (st .getClassName ())
577- .getMethod (st .getMethodName ())
578- .isAnnotationPresent (Profile .class )) {
579- methodName = st .getMethodName ();
580- break ;
581- }
582- } catch (NoSuchMethodException e ) {
583- if (printProfileMethodInfo ) {
584- logger .info (
585- "Method with name : "
586- + st .getMethodName ()
587- + " does not exist in Class : "
588- + st .getClassName ());
589- logger .info (e .getMessage ());
590- }
591- } catch (ClassNotFoundException e ) {
592- if (printProfileMethodInfo ) {
593- logger .info ("Class with name : " + st .getClassName () + " not found" );
594- logger .info (e .getMessage ());
595- }
596- }
597- }
598-
599- return methodName ;
600- }
601-
602490 /**
603491 * Sets the blacklist of package names whose instances will be excluded from the object graph.
604492 *
0 commit comments