Skip to content

Commit

Permalink
Compacted log headers
Browse files Browse the repository at this point in the history
  • Loading branch information
cypof committed Apr 18, 2013
1 parent 5606588 commit 5cfe0cd
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 53 deletions.
18 changes: 9 additions & 9 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.formatter.align_type_members_on_columns=true
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
Expand Down Expand Up @@ -140,13 +140,13 @@ org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=true
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
org.eclipse.jdt.core.formatter.comment.format_block_comments=true
org.eclipse.jdt.core.formatter.comment.format_header=false
org.eclipse.jdt.core.formatter.comment.format_html=true
org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
org.eclipse.jdt.core.formatter.comment.format_line_comments=true
org.eclipse.jdt.core.formatter.comment.format_line_comments=false
org.eclipse.jdt.core.formatter.comment.format_source_code=true
org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
Expand All @@ -162,7 +162,7 @@ org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=false
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
Expand All @@ -172,11 +172,11 @@ org.eclipse.jdt.core.formatter.indent_empty_lines=false
org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
org.eclipse.jdt.core.formatter.indentation.size=4
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true
org.eclipse.jdt.core.formatter.indentation.size=2
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
Expand Down Expand Up @@ -362,7 +362,7 @@ org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
org.eclipse.jdt.core.formatter.lineSplit=120
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=true
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
Expand Down
1 change: 1 addition & 0 deletions src/main/java/hex/GLMGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public void compute2() {
GridTask t = new GridTask(GLMGrid.this, a, _parallel);
t.compute2();
}
remove();
}
});
}
Expand Down
98 changes: 54 additions & 44 deletions src/main/java/water/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public final class Log {
private static final ThreadLocal<SimpleDateFormat> _utcFormat = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
SimpleDateFormat format = new SimpleDateFormat("yyMMdd'-'HH:mm:ss.SSS");
SimpleDateFormat format = new SimpleDateFormat("dd' 'HH:mm:ss.SSS");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format;
}
Expand All @@ -25,14 +25,14 @@ protected SimpleDateFormat initialValue() {
private static final long PID;
static {
HOST = H2O.findInetAddressForSelf().getHostAddress();
PID=getPid();
HOST_AND_PID = "" + padRight(HOST + ", ", 17);// + padRight(PID + ", ", 8);
PID = getPid();
HOST_AND_PID = "" + fixedLength(HOST + " ", 11) + fixedLength(PID + " ", 6);
}
private static final String NL = System.getProperty("line.separator");

// Local (not-distributed) log file
private static BufferedWriter LOG_FILE;
public final static Key LOG_KEY = Key.make("Log",(byte)0,Key.BUILT_IN_KEY);
public final static Key LOG_KEY = Key.make("Log", (byte) 0, Key.BUILT_IN_KEY);

private static long getPid() {
try {
Expand Down Expand Up @@ -82,6 +82,16 @@ public static String padRight(String stringToPad, int size) {
return strb.toString();
}

public static String fixedLength(String s, int length) {
String r = padRight(s, length);
if( r.length() > length ) {
int a = Math.max(r.length() - length + 1, 0);
int b = Math.max(a, r.length());
r = "#" + r.substring(a, b);
}
return r;
}

public static void initHeaders() {
if( !(System.out instanceof Wrapper) ) {
System.setOut(new Wrapper(System.out));
Expand Down Expand Up @@ -119,56 +129,55 @@ private static String log(Locale l, boolean nl, String format, Object... args) {
// Build the String to be logged, with all sorts of headers
StringBuilder sb = new StringBuilder();
String date = _utcFormat.get().format(new Date());
sb.append(date).append(", ");
sb.append(date).append(" ");
sb.append(HOST_AND_PID);
String thr = Thread.currentThread().getName();
String thr = fixedLength(Thread.currentThread().getName() + " ", 15);
sb.append(thr);
int len = thr.length();
for( int i=len; i<26; i++ )
sb.append(' ');
String msg = String.format(l,format,args);
String msg = String.format(l, format, args);
sb.append(msg);
if( nl ) sb.append(NL);
if( nl )
sb.append(NL);
String s = sb.toString();
// Write to 3 places: stderr/stdout, the local log file, the K/V store
// Open/create the logfile when we can
if( H2O.SELF != null && LOG_FILE == null )
LOG_FILE = new BufferedWriter(PersistIce.logFile());
// Write to the log file
if( LOG_FILE != null ) {
try { LOG_FILE.write(s,0,s.length()); LOG_FILE.flush(); }
catch( IOException ioe ) {/*ignore log-write fails*/}
try {
LOG_FILE.write(s, 0, s.length());
LOG_FILE.flush();
} catch( IOException ioe ) {/* ignore log-write fails */
}
}
if( Paxos._cloudLocked ) logToKV(date,thr,msg);
if( Paxos._cloudLocked )
logToKV(date, thr, msg);
// Returned string goes to stderr/stdout
return s;
}

private static void logToKV( final String date, final String thr, final String msg ) {
final long pid = PID; // Run locally
private static void logToKV(final String date, final String thr, final String msg) {
final long pid = PID; // Run locally
final H2ONode h2o = H2O.SELF; // Run locally
new TAtomic<LogStr>() {
@Override public LogStr atomic( LogStr l ) {
return new LogStr(l,date,h2o,pid,thr,msg);
@Override public LogStr atomic(LogStr l) {
return new LogStr(l, date, h2o, pid, thr, msg);
}
}.fork(LOG_KEY);
}

@Override
public PrintStream printf(String format, Object... args) {
super.print(log(null,false,format,args));
@Override public PrintStream printf(String format, Object... args) {
super.print(log(null, false, format, args));
return this;
}

@Override
public PrintStream printf(Locale l, String format, Object... args) {
super.print(log(l,false,format, args));
@Override public PrintStream printf(Locale l, String format, Object... args) {
super.print(log(l, false, format, args));
return this;
}

@Override
public void println(String x) {
super.print(log(null,true,"%s",x));
@Override public void println(String x) {
super.print(log(null, true, "%s", x));
}

void printlnParent(String s) {
Expand All @@ -179,24 +188,25 @@ void printlnParent(String s) {
// Class to hold a ring buffer of log messages in the K/V store
public static class LogStr extends Iced {
public static final int MAX = 1024; // Number of log entries
public final int _idx; // Index into the ring buffer
public final String _dates[];
public final H2ONode _h2os [];
public final long _pids [];
public final String _thrs [];
public final String _msgs [];
LogStr( LogStr l, String date, H2ONode h2o, long pid, String thr, String msg ) {
_dates= l==null ? new String [MAX] : l._dates;
_h2os = l==null ? new H2ONode[MAX] : l._h2os ;
_pids = l==null ? new long [MAX] : l._pids ;
_thrs = l==null ? new String [MAX] : l._thrs ;
_msgs = l==null ? new String [MAX] : l._msgs ;
_idx = l==null ? 0 : (l._idx+1)&(MAX-1);
public final int _idx; // Index into the ring buffer
public final String _dates[];
public final H2ONode _h2os[];
public final long _pids[];
public final String _thrs[];
public final String _msgs[];

LogStr(LogStr l, String date, H2ONode h2o, long pid, String thr, String msg) {
_dates = l == null ? new String[MAX] : l._dates;
_h2os = l == null ? new H2ONode[MAX] : l._h2os;
_pids = l == null ? new long[MAX] : l._pids;
_thrs = l == null ? new String[MAX] : l._thrs;
_msgs = l == null ? new String[MAX] : l._msgs;
_idx = l == null ? 0 : (l._idx + 1) & (MAX - 1);
_dates[_idx] = date;
_h2os [_idx] = h2o;
_pids [_idx] = pid;
_thrs [_idx] = thr;
_msgs [_idx] = msg;
_h2os[_idx] = h2o;
_pids[_idx] = pid;
_thrs[_idx] = thr;
_msgs[_idx] = msg;
}
}
}

0 comments on commit 5cfe0cd

Please sign in to comment.