You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Stats.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.memory;
  19. import java.util.Iterator;
  20. import java.util.List;
  21. class Stats {
  22. private static final int INTERVAL = 2000;
  23. private long startTime = System.currentTimeMillis();
  24. private long lastProgressDump = startTime;
  25. private int pagesProduced;
  26. private int totalPagesProduced;
  27. private int step;
  28. private int stepCount;
  29. private List samples = new java.util.LinkedList();
  30. public void checkStats() {
  31. long now = System.currentTimeMillis();
  32. if (now > lastProgressDump + INTERVAL) {
  33. dumpStats();
  34. reset();
  35. }
  36. }
  37. public void notifyPagesProduced(int count) {
  38. pagesProduced += count;
  39. totalPagesProduced += count;
  40. }
  41. public void reset() {
  42. pagesProduced = 0;
  43. lastProgressDump = System.currentTimeMillis();
  44. }
  45. public void dumpStats() {
  46. long duration = System.currentTimeMillis() - lastProgressDump;
  47. if (stepCount != 0) {
  48. int progress = 100 * step / stepCount;
  49. System.out.println("Progress: " + progress + "%, " + (stepCount - step) + " left");
  50. }
  51. long ppm = 60000 * pagesProduced / duration;
  52. System.out.println("Speed: " + ppm + "ppm");
  53. samples.add(new Sample((int)ppm));
  54. }
  55. public void dumpFinalStats() {
  56. long duration = System.currentTimeMillis() - startTime;
  57. System.out.println("Final statistics");
  58. System.out.println("Pages produced: " +totalPagesProduced);
  59. long ppm = 60000 * totalPagesProduced / duration;
  60. System.out.println("Average speed: " + ppm + "ppm");
  61. }
  62. public String getGoogleChartURL() {
  63. StringBuffer sb = new StringBuffer("http://chart.apis.google.com/chart?");
  64. //http://chart.apis.google.com/chart?cht=ls&chd=t:60,40&chs=250x100&chl=Hello|World
  65. sb.append("cht=ls");
  66. sb.append("&chd=t:");
  67. boolean first = true;
  68. int maxY = 0;
  69. Iterator iter = samples.iterator();
  70. while (iter.hasNext()) {
  71. Sample sample = (Sample)iter.next();
  72. if (first) {
  73. first = false;
  74. } else {
  75. sb.append(',');
  76. }
  77. sb.append(sample.ppm);
  78. maxY = Math.max(maxY, sample.ppm);
  79. }
  80. int ceilY = ((maxY / 1000) + 1) * 1000;
  81. sb.append("&chs=1000x300"); //image size
  82. sb.append("&chds=0,").append(ceilY); //data scale
  83. sb.append("&chg=0,20"); //scale steps
  84. sb.append("&chxt=y");
  85. sb.append("&chxl=0:|0|" + ceilY);
  86. return sb.toString();
  87. }
  88. private static class Sample {
  89. private int ppm;
  90. public Sample(int ppm) {
  91. this.ppm = ppm;
  92. }
  93. }
  94. public void progress(int step, int stepCount) {
  95. this.step = step;
  96. this.stepCount = stepCount;
  97. }
  98. }