001/* 002 * ==================================================================== 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 * ==================================================================== 020 * 021 * This software consists of voluntary contributions made by many 022 * individuals on behalf of the Apache Software Foundation. For more 023 * information on the Apache Software Foundation, please see 024 * <http://www.apache.org/>. 025 * 026 */ 027package org.apache.http.benchmark; 028 029/** 030 * Helper to gather statistics for an {@link HttpBenchmark HttpBenchmark}. 031 * 032 * 033 * @since 4.0 034 */ 035public class Stats { 036 037 private long startTime = -1; // nano seconds - does not represent an actual time 038 private long finishTime = -1; // nano seconds - does not represent an actual time 039 private int successCount = 0; 040 private int failureCount = 0; 041 private int writeErrors = 0; 042 private int keepAliveCount = 0; 043 private String serverName = null; 044 private long totalBytesRecv = 0; 045 private long totalBytesSent = 0; 046 private long contentLength = -1; 047 048 public Stats() { 049 super(); 050 } 051 052 public void start() { 053 this.startTime = System.nanoTime(); 054 } 055 056 public void finish() { 057 this.finishTime = System.nanoTime(); 058 } 059 060 public long getFinishTime() { 061 return this.finishTime; 062 } 063 064 public long getStartTime() { 065 return this.startTime; 066 } 067 068 /** 069 * Total execution time measured in nano seconds 070 * 071 * @return duration in nanoseconds 072 */ 073 public long getDuration() { 074 // we are using System.nanoTime() and the return values could be negative 075 // but its only the difference that we are concerned about 076 return this.finishTime - this.startTime; 077 } 078 079 public void incSuccessCount() { 080 this.successCount++; 081 } 082 083 public int getSuccessCount() { 084 return this.successCount; 085 } 086 087 public void incFailureCount() { 088 this.failureCount++; 089 } 090 091 public int getFailureCount() { 092 return this.failureCount; 093 } 094 095 public void incWriteErrors() { 096 this.writeErrors++; 097 } 098 099 public int getWriteErrors() { 100 return this.writeErrors; 101 } 102 103 public void incKeepAliveCount() { 104 this.keepAliveCount++; 105 } 106 107 public int getKeepAliveCount() { 108 return this.keepAliveCount; 109 } 110 111 public long getTotalBytesRecv() { 112 return this.totalBytesRecv; 113 } 114 115 public void incTotalBytesRecv(final long n) { 116 this.totalBytesRecv += n; 117 } 118 119 public long getTotalBytesSent() { 120 return this.totalBytesSent; 121 } 122 123 public void incTotalBytesSent(final long n) { 124 this.totalBytesSent += n; 125 } 126 127 public long getContentLength() { 128 return this.contentLength; 129 } 130 131 public void setContentLength(final long contentLength) { 132 this.contentLength = contentLength; 133 } 134 135 public String getServerName() { 136 return this.serverName; 137 } 138 139 public void setServerName(final String serverName) { 140 this.serverName = serverName; 141 } 142 143}