Skip to content

Commit 377d87c

Browse files
remove profiling code from ogo src
1 parent 6049eae commit 377d87c

File tree

2 files changed

+2
-114
lines changed

2 files changed

+2
-114
lines changed

src/main/java/org/ogo/client/OGO.java

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
package org.ogo.client;
22

3-
import java.io.BufferedWriter;
43
import java.io.File;
5-
import java.io.FileNotFoundException;
6-
import java.io.FileOutputStream;
74
import java.io.IOException;
8-
import java.io.OutputStreamWriter;
95
import java.nio.charset.StandardCharsets;
106
import java.rmi.NotBoundException;
117
import java.rmi.RemoteException;
128
import java.rmi.registry.LocateRegistry;
139
import java.rmi.registry.Registry;
1410
import java.security.MessageDigest;
15-
import java.text.SimpleDateFormat;
1611
import java.util.*;
1712
import java.util.logging.Logger;
1813
import org.ogo.bridge.AbstractGraphQueryInterface;
1914
import org.ogo.util.FileHelper;
2015
import 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
*

todo.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
- [X] Add OGO logo
2727
- [ ] No need to use italics in the README
2828
------------------------------------------------------------------------
29-
- [ ] Check if we need to upgrade Java ASM bytecode analyzer version
30-
- [ ] Remove profiling code from OGO source
29+
- [X] Check if we need to upgrade Java ASM bytecode analyzer version
30+
- [X] Remove profiling code from OGO source
3131
- [ ] Refactor to if/elif to switch case

0 commit comments

Comments
 (0)