From: Ian Jackson Date: Sat, 2 Apr 2011 17:23:29 +0000 (+0100) Subject: debug logging: replace logprogress and if(dtxt!=null)... with debuglog() function X-Git-Tag: 1.0.5~9 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=jarrg-ian.git;a=commitdiff_plain;h=f0aff42beee7a04001ec97093704144074b35fc6 debug logging: replace logprogress and if(dtxt!=null)... with debuglog() function --- diff --git a/src/net/chiark/yarrg/MarketUploader.java b/src/net/chiark/yarrg/MarketUploader.java index dda1538..4f50228 100644 --- a/src/net/chiark/yarrg/MarketUploader.java +++ b/src/net/chiark/yarrg/MarketUploader.java @@ -86,7 +86,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { } } - private void progresslog(String s) { + private void debuglog(String s) { if (dtxt == null) return; long now = new Date().getTime(); dtxt.println("progress "+(now - startTime)+"ms "+s); @@ -288,8 +288,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { uploadToPCTB=prefs.getBoolean("uploadToPCTB", true); showArbitrage=prefs.getBoolean("showArbitrage", true); - if (dtxt!=null) dtxt.println("main on dispatch thread: "+ - EventQueue.isDispatchThread()); + debuglog("main on dispatch thread: "+EventQueue.isDispatchThread()); EventQueue.invokeLater(this); } @@ -298,12 +297,12 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { * every top-level window, and if it */ public void run() { - if (dtxt!=null) dtxt.println("MarketUploader run()..."); + debuglog("MarketUploader run()..."); if (EventQueueMonitor.isGUIInitialized()) { - if (dtxt!=null) dtxt.println("MarketUploader GUI already ready"); + debuglog("MarketUploader GUI already ready"); guiInitialized(); } else { - if (dtxt!=null) dtxt.println("MarketUploader waiting for GUI"); + debuglog("MarketUploader waiting for GUI"); EventQueueMonitor.addGUIInitializedListener(this); } } @@ -312,13 +311,13 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { Window ws[]= EventQueueMonitor.getTopLevelWindows(); EventQueueMonitor.addTopLevelWindowListener(this); for (int i=0; iPCTB Server said:
"+html+"
"; - if (dtxt!=null) dtxt.println("###" + whole_msg + "###"); + debuglog("###" + whole_msg + "###"); error(whole_msg); } @@ -487,7 +486,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { int index = text.indexOf(":"); String name = text.substring(0,index); islandName = name; - // if (dtxt!=null) dtxt.println(islandName); + // debuglog(islandName); sidePanel.removePropertyChangeListener(this); latch.countDown(); } @@ -569,7 +568,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { public void run() { try { ts = getYarrgTimestamp(); - progresslog("(async) yarrg timestamp ready."); + debuglog("(async) yarrg timestamp ready."); } catch(Exception e) { error("Error getting YARRG timestamp: "+e); } @@ -582,10 +581,10 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { boolean doneyarrg = false, donepctb = false; YarrgTimestampFetcher yarrgts_thread = null; - progresslog("starting"); + debuglog("starting"); if (uploadToYarrg) { - progresslog("(async) yarrg timestamp..."); + debuglog("(async) yarrg timestamp..."); yarrgts_thread = new YarrgTimestampFetcher(); yarrgts_thread.start(); } @@ -612,11 +611,11 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { return null; } - progresslog("(async) getisland..."); + debuglog("(async) getisland..."); getIsland(); - progresslog("getocean..."); + debuglog("getocean..."); getOcean(); - progresslog("getocean done"); + debuglog("getocean done"); return at; }}.exec(); @@ -625,13 +624,13 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { if (latch != null) { latch.await(2, java.util.concurrent.TimeUnit.SECONDS); } - progresslog("(async) getisland done"); + debuglog("(async) getisland done"); String yarrgts = null; if (yarrgts_thread != null) { - progresslog("(async) yarrg timestamp join..."); + debuglog("(async) yarrg timestamp join..."); yarrgts_thread.join(); - progresslog("(async) yarrg timestamp joined."); + debuglog("(async) yarrg timestamp joined."); yarrgts = yarrgts_thread.ts; } @@ -640,7 +639,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { return; } - progresslog("table check..."); + debuglog("table check..."); final ArrayList> data = new UIXR>> @@ -671,20 +670,20 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { } } - progresslog("table read..."); + debuglog("table read..."); return getData(accesstable); }}.exec(); if (data == null) return; if (showArbitrage) { - progresslog("arbitrage..."); + debuglog("arbitrage..."); calculateArbitrage(data); - progresslog("arbitrage done."); + debuglog("arbitrage done."); } if (uploadToYarrg && yarrgts != null) { - progresslog("yarrg prepare..."); + debuglog("yarrg prepare..."); progressNote("Yarrg: Preparing data"); setProgress(10); @@ -706,14 +705,14 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { yarrgdata = yarrgsb.toString(); progressNote("Yarrg: Uploading"); - progresslog("yarrg upload..."); + debuglog("yarrg upload..."); doneyarrg = runYarrg(yarrgts, oceanName, islandName, yarrgdata); - progresslog("yarrg done."); + debuglog("yarrg done."); } if (uploadToPCTB) { - progresslog("pctb prepare..."); + debuglog("pctb prepare..."); progressNote("PCTB: Getting stall names"); setProgress(20); if(isCanceled()) { @@ -729,15 +728,15 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { } // get commod map - progresslog("pctb commodmap..."); + debuglog("pctb commodmap..."); HashMap commodMap = getCommodMap(); if(commodMap == null) { return; } - progresslog("pctb commodmap done."); + debuglog("pctb commodmap done."); int[] offerCount = getBuySellMaps(data,buys,sells,stallMap,commodMap); - // if (dtxt!=null) dtxt.println(sells); - // if (dtxt!=null) dtxt.println("\n\n\n"+buys); + // debuglog(sells); + // debuglog("\n\n\n"+buys); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); setProgress(60); @@ -752,22 +751,22 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { dos.writeBytes(getAbbrevStallList(stallMap)); writeBuySellOffers(buys,sells,offerCount,out); out.finish(); - progresslog("pctb send..."); + debuglog("pctb send..."); byte[] ba = outStream.toByteArray(); debug_write_bytes("pctb-marketdata.gz", ba); InputStream in = sendInitialData(new ByteArrayInputStream(ba)); - progresslog("pctb sent."); + debuglog("pctb sent."); if (in == null) return; setProgress(80); if(isCanceled()) { return; } progressNote("PCTB: Waiting ..."); - progresslog("pctb finish..."); + debuglog("pctb finish..."); donepctb = finishUpload(in); - progresslog("pctb done."); + debuglog("pctb done."); } setProgress(99); @@ -787,7 +786,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { resultSummary.setText(summary_final); }}.exec(); - progresslog("done."); + debuglog("done."); } /** @@ -821,14 +820,14 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { Accessible node = descendNodes(node1,new int[] {0,1,0,0,0,0,1,0,0,1,0,0}); // commod market // commod market: {0,1,0,0,0,0,1,0,0,1,0} {0,1,0,0,0,0,1,0,1,0,0,1,0,0}) - // if (dtxt!=null) dtxt.println(node); + // debuglog(node); if (!(node instanceof JTable)) { node = descendNodes(node1,new int[] {0,1,0,0,0,0,1,0,1,0,0,1,0,0}); // commod market } if (!(node instanceof JTable)) return null; AccessibleTable table = node.getAccessibleContext().getAccessibleTable(); - // if (dtxt!=null) dtxt.println(table); + // debuglog(table); return table; } @@ -865,14 +864,12 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { if (parent == null) return null; int children = parent.getAccessibleContext().getAccessibleChildrenCount(); if (childNum >= children) { - if (dtxt!=null) dtxt.println("DESCEND "+childNum+" > " - +children+" NOT FOUND"); + debuglog("DESCEND "+childNum+" > "+children+" NOT FOUND"); return null; } Accessible child = parent.getAccessibleContext() .getAccessibleChild(childNum); - if (dtxt!=null) dtxt.println("DESCEND "+childNum+" " - +child.getClass().getName()+" OK"); + debuglog("DESCEND "+childNum+" "+child.getClass().getName()+" OK"); return child; } @@ -891,11 +888,11 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { for (int i=0; i> arb_bs) { - // if (dtxt!=null) dtxt.println("ARBITRAGE?"); + // debuglog("ARBITRAGE?"); int profit = 0; SortedSet buys = arb_bs.get(0); SortedSet sells = arb_bs.get(1); @@ -1345,9 +1341,9 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { int unitprofit = buy[0] - sell[0]; int count = buy[1] < sell[1] ? buy[1] : sell[1]; - // if (dtxt!=null) dtxt.println(" sell @"+sell[0]+" x"+sell[1] - // +" buy @"+buy[0]+" x"+buy[1] - // +" => x"+count+" @"+unitprofit); + // debuglog(" sell @"+sell[0]+" x"+sell[1] + // +" buy @"+buy[0]+" x"+buy[1] + // +" => x"+count+" @"+unitprofit); if (unitprofit <= 0) break; @@ -1358,7 +1354,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { if (buy[1]==0) buys.remove(buy); if (sell[1]==0) sells.remove(sell); } - // if (dtxt!=null) dtxt.println(" PROFIT "+profit); + // debuglog(" PROFIT "+profit); return profit; } @@ -1380,15 +1376,15 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { for (ArrayList row : data) { String thiscommod = row.get(0); - // if (dtxt!=null) dtxt.println("ROW "+row.toString()); + // debuglog("ROW "+row.toString()); if (lastcommod == null || !thiscommod.equals(lastcommod)) { if (lastcommod != null) arbitrage += calculateArbitrageCommodity(arb_bs); - // if (dtxt!=null) dtxt.println("ROW rdy"); + // debuglog("ROW rdy"); arb_bs = new ArrayList>(2); arb_bs.add(0, new TreeSet(compar)); arb_bs.add(1, new TreeSet(compar)); - // if (dtxt!=null) dtxt.println("ROW init"); + // debuglog("ROW init"); lastcommod = thiscommod; } for (int bs = 0; bs < 2; bs++) { @@ -1396,7 +1392,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { if (pricestr == null) continue; int[] entry = new int[2]; - // if (dtxt!=null) dtxt.println("ROW BS "+bs); + // debuglog("ROW BS "+bs); entry[0] = parseQty(pricestr); entry[1] = parseQty(row.get(bs*2 + 3)); arb_bs.get(bs).add(entry);