test_class.file: node/etl/src/test/java/com/alibaba/otter/node/etl/common/jmx/StageAggregationTest.java
test_class.identifier: StageAggregationTest
test_class.superclass: extends BaseOtterTest
test_case.body: @Test
      public void test_zero() {
          StageAggregation aggregation = new StageAggregation(256);
          String result = aggregation.histogram();
          System.out.println(result);
      }
test_case.class_method_signature: StageAggregationTest.test_zero()
test_case.full_signature: @Test public void test_zero()
test_case.identifier: test_zero
test_case.invocations: histogram println
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void test_zero()
focal_class.declarator: HISTOGRAM_FORMAT = "{total:%s,count:%s,maximum:%s,minimum:%s,average:%s,tps:%s,tpm:%s}"
focal_class.modifier: private static final
focal_class.original_string: private static final String HISTOGRAM_FORMAT = "{total:%s,count:%s,maximum:%s,minimum:%s,average:%s,tps:%s,tpm:%s}";
focal_class.type: String
focal_class.var_name: HISTOGRAM_FORMAT
focal_class.declarator: ONE_SECOND       = 1000L
focal_class.modifier: private static final
focal_class.original_string: private static final Long   ONE_SECOND       = 1000L;
focal_class.type: Long
focal_class.var_name: ONE_SECOND
focal_class.declarator: ONE_MINUTE       = 60 * 1000L
focal_class.modifier: private static final
focal_class.original_string: private static final Long   ONE_MINUTE       = 60 * 1000L;
focal_class.type: Long
focal_class.var_name: ONE_MINUTE
focal_class.declarator: bufferSize       = 1 * 1024
focal_class.modifier: private
focal_class.original_string: private int                 bufferSize       = 1 * 1024;
focal_class.type: int
focal_class.var_name: bufferSize
focal_class.declarator: indexMask
focal_class.modifier: private
focal_class.original_string: private int                 indexMask;
focal_class.type: int
focal_class.var_name: indexMask
focal_class.declarator: table
focal_class.modifier: private
focal_class.original_string: private AggregationItem[]   table;
focal_class.type: AggregationItem[]
focal_class.var_name: table
focal_class.declarator: sequence         = new AtomicLong(-1)
focal_class.modifier: private
focal_class.original_string: private AtomicLong          sequence         = new AtomicLong(-1);
focal_class.type: AtomicLong
focal_class.var_name: sequence
focal_class.file: node/etl/src/main/java/com/alibaba/otter/node/etl/common/jmx/StageAggregation.java
focal_class.identifier: StageAggregation
focal_class.class_method_signature: StageAggregation.StageAggregation(int bufferSize)
focal_class.full_signature: public  StageAggregation(int bufferSize)
focal_class.identifier: StageAggregation
focal_class.modifiers: public
focal_class.parameters: (int bufferSize)
focal_class.signature:  StageAggregation(int bufferSize)
focal_class.class_method_signature: StageAggregation.push(AggregationItem aggregation)
focal_class.full_signature: public void push(AggregationItem aggregation)
focal_class.identifier: push
focal_class.modifiers: public
focal_class.parameters: (AggregationItem aggregation)
focal_class.return: void
focal_class.signature: void push(AggregationItem aggregation)
focal_class.class_method_signature: StageAggregation.count()
focal_class.full_signature: public Long count()
focal_class.identifier: count
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Long
focal_class.signature: Long count()
focal_class.class_method_signature: StageAggregation.histogram()
focal_class.full_signature: public String histogram()
focal_class.identifier: histogram
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String histogram()
focal_class.class_method_signature: StageAggregation.getIndex(long sequcnce)
focal_class.full_signature: private int getIndex(long sequcnce)
focal_class.identifier: getIndex
focal_class.modifiers: private
focal_class.parameters: (long sequcnce)
focal_class.return: int
focal_class.signature: int getIndex(long sequcnce)
focal_method.body: public String histogram() {
          Long costs = 0L;
          Long items = 0L;
          Long max = 0L;
          Long min = Long.MAX_VALUE;
          Long tps = 0L;
          Long tpm = 0L;
          Long avg = 0L;
  
          Long lastTime = 0L;
          Long tpsCount = 0L;// 记录每秒的请求数，临时变量
          Long tpsTotal = 0L;// 总tps数多少
          Long tpsSecond = 0L;// 多少秒中有数据
  
          Long tpmCount = 0L; // 记录每分钟的请求数，临时变量
          Long tpmTotal = 0L; // 总tps数多少
          Long tpmMinute = 0L;// 多少分钟有数据
          for (int i = 0; i < table.length; i++) {
              AggregationItem aggregation = table[i];
              if (aggregation != null) {
                  Long cost = aggregation.getEndTime() - aggregation.getStartTime();
                  items += 1;
                  costs += cost;
                  if (cost > max) {
                      max = cost;
                  }
                  if (cost < min) {
                      min = cost;
                  }
  
                  if (lastTime != 0) {
                      if (lastTime > aggregation.getEndTime() - ONE_SECOND) {// 说明在同一秒
                          tpsCount++;
                      } else {
                          tpsTotal += tpsCount;
                          tpsSecond++;
                          tpsCount = 0L;
                      }
  
                      if (lastTime > aggregation.getEndTime() - ONE_MINUTE) {// 说明在同一分钟
                          tpmCount++;
                      } else {
                          tpmTotal += tpmCount;
                          tpmMinute++;
                          tpmCount = 0L;
                      }
  
                  }
  
                  lastTime = aggregation.getEndTime();
              }
          }
          // 设置一下最后一批tps/m统计信息
          tpsTotal += tpsCount;
          tpsSecond++;
          tpsCount = 0L;
          tpmTotal += tpmCount;
          tpmMinute++;
          tpmCount = 0L;
  
          if (items != 0) {
              avg = costs / items;
          }
  
          if (tpsSecond != 0) {
              tps = tpsTotal / tpsSecond;
          }
  
          if (tpmMinute != 0) {
              tpm = tpmTotal / tpmMinute;
          }
  
          if (min == Long.MAX_VALUE) {
              min = 0L;
          }
  
          return String.format(HISTOGRAM_FORMAT, new Object[] { sequence.get() + 1, items, max, min, avg, tps, tpm });
      }
focal_method.class_method_signature: StageAggregation.histogram()
focal_method.full_signature: public String histogram()
focal_method.identifier: histogram
focal_method.invocations: getEndTime getStartTime getEndTime getEndTime getEndTime format get
focal_method.modifiers: public
focal_method.parameters: ()
focal_method.return: String
focal_method.signature: String histogram()