Skip to content

Commit

Permalink
Increased efficiency of logging with Protocol Buffers, and including …
Browse files Browse the repository at this point in the history
…com.google.protobuf in skip.txt
  • Loading branch information
rmega12 committed Jul 30, 2020
1 parent 4e335c7 commit 71bea9d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
Binary file modified data/logging.dex
Binary file not shown.
1 change: 1 addition & 0 deletions data/skip.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
android.support
com.google.protobuf
ProtoDefs
37 changes: 23 additions & 14 deletions logging/app/src/main/java/org/umd/logging/FileWriterHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
import android.widget.RadioButton;
import android.widget.TextView;

import com.google.protobuf.CodedOutputStream;
import com.google.protobuf.CodedOutputStream;

import ProtoDefs.LogStructure;

public class FileWriterHandler implements Runnable{
Expand All @@ -54,7 +57,7 @@ public class FileWriterHandler implements Runnable{

// A hash map that holds--for each thread ID--a file to which to
// write the output
private HashMap<Long, BufferedOutputStream> outs;
private HashMap<Long, CodedOutputStream> outs;

final static String tag = Logger.class.getPackage().getName();

Expand All @@ -77,18 +80,24 @@ static File getFileName(long threadId) {
return f;
}

static void writeDelimToPB(CodedOutputStream cos, LogStructure.Line msg_out) throws IOException {
final int serialized = msg_out.getSerializedSize();
cos.writeUInt32NoTag(serialized);
msg_out.writeTo(cos);
}

public FileWriterHandler(ConcurrentLinkedQueue<Object[]> p){
pipe = p;
try{
File f = getFileName(1);
FileOutputStream fos = new FileOutputStream(f);
BufferedOutputStream out = new BufferedOutputStream(fos, 65536);
outs = new HashMap();
outs.put(new Long(1),out);
}catch(IOException e){
Log.i(tag, "logging error");
e.printStackTrace();
}
// try{
// File f = getFileName(1);
// FileOutputStream fos = new FileOutputStream(f);
// CodedOutputStream out = CodedOutputStream.newInstance(fos, 65536);
// outs = new HashMap();
// outs.put(new Long(1), out);
// }catch(IOException e){
// Log.i(tag, "logging error");
// e.printStackTrace();
// }
}

static final Set<Class> WRAPPER_TYPES = new HashSet(Arrays.asList(
Expand Down Expand Up @@ -159,7 +168,7 @@ public void run() {
try{
File f = getFileName(id);
FileOutputStream fos = new FileOutputStream(f);
BufferedOutputStream out = new BufferedOutputStream(fos, 65536);
CodedOutputStream out = CodedOutputStream.newInstance(fos, 65536);
outs.put(new Long(id),out);
} catch(IOException e){
Log.i(tag, "logging error");
Expand All @@ -170,7 +179,7 @@ public void run() {
// Block entry
if (io == "b") {
curLine.setBBloc((Long) args[4]);
curLine.build().writeDelimitedTo(outs.get(id));
writeDelimToPB(outs.get(id), curLine.build());
curLine.clear();
continue;
}
Expand Down Expand Up @@ -319,7 +328,7 @@ else if (io == "m") {
curLine.addParameters(argCount, curParam);
curParam.clear();
}
curLine.build().writeDelimitedTo(outs.get(id));
writeDelimToPB(outs.get(id), curLine.build());
curLine.clear();
} catch(IOException e){
Log.i(tag, "logging error");
Expand Down

0 comments on commit 71bea9d

Please sign in to comment.