• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

TestPreProc.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 #include "TestPreProc.h"
00024 #include "IOBufferPool.h"
00025 #include "IOBuffer.h"
00026 #include "HttpPreProc.h"
00027 #include "HttpMessage.h"
00028 #include "HttpPreProcMessageManager.h"
00029 #include "RawHashTable.h"
00030 #include "ink_time.h"           /* ink_time_wall_seconds() */
00031 #include <string.h>
00032 #include <iostream.h>
00033 
00034 /* local functions prototypes */
00035 void dumpMessage(const HttpMessage & msg);
00036 void testPreProc();
00037 
00038 /* some global requests */
00039 char *request1 = "GET http://trafficserver.apache.org HTTP/1.1\r\n\
00040 Accept: text/*, text/html, text/html; level=1\r\n\
00041 Accept-Charset: iso-8859-5, unicode-1-1;q=0.8\r\n\r\n";
00042 char *response1 = "HTTP/1.1 200\r\n\r\n";
00043 //////////////////////////////////////////////////////////////////////////////
00044 // RequestInput().
00045 //////////////////////////////////////////////////////////////////////////////
00046 RequestInput::RequestInput(const char *str, IOBuffer * cb)
00047   :
00048 m_sp(0),
00049 m_len(0),
00050 m_cb(cb)
00051 {
00052   m_len = strlen(str);
00053   m_sp = request1;
00054 
00055   return;
00056 }
00057 
00058 //////////////////////////////////////////////////////////////////////////////
00059 // ~RequestInput()
00060 //////////////////////////////////////////////////////////////////////////////
00061 RequestInput::~RequestInput()
00062 {
00063   return;
00064 }
00065 
00066 //////////////////////////////////////////////////////////////////////////////
00067 // run()
00068 //////////////////////////////////////////////////////////////////////////////
00069 void
00070 RequestInput::run()
00071 {
00072   unsigned maxBytes = 0;
00073 
00074   char *buff = m_cb->getWrite(&maxBytes);
00075   unsigned writeBytes = (m_len < maxBytes) ? m_len : maxBytes;
00076 
00077 
00078   writeBytes = ink_strlcpy(buff, m_sp, maxBytes);
00079   m_cb->wrote(writeBytes);
00080 
00081   m_len -= writeBytes;
00082   m_sp += writeBytes;
00083 
00084   return;
00085 }
00086 
00087 //////////////////////////////////////////////////////////////////////////////
00088 // dumpMessage()
00089 //////////////////////////////////////////////////////////////////////////////
00090 void
00091 dumpMessage(const HttpMessage & msg)
00092 {
00093   if (msg.isResponse()) {
00094     cout << "Http response" << endl;
00095   }
00096   if (msg.isRequest()) {
00097     cout << "Http request" << endl;
00098   }
00099 
00100   cout << "Major version: " << msg.getMajorVersion() << endl;
00101   cout << "Minor version: " << msg.getMinorVersion() << endl;
00102   cout << "Method       : ";
00103   switch (msg.getMethod()) {
00104   case HttpMessage::METHOD_NONE:
00105     cout << "NONE" << endl;
00106   case HttpMessage::METHOD_OPTIONS:
00107     cout << "OPTIONS" << endl;
00108     break;
00109   case HttpMessage::METHOD_GET:
00110     cout << "GET" << endl;
00111     break;
00112   case HttpMessage::METHOD_HEAD:
00113     cout << "HEAD" << endl;
00114     break;
00115   case HttpMessage::METHOD_POST:
00116     cout << "POST" << endl;
00117     break;
00118   case HttpMessage::METHOD_PUT:
00119     cout << "PUT" << endl;
00120     break;
00121   case HttpMessage::METHOD_DELETE:
00122     cout << "DELETE" << endl;
00123     break;
00124   case HttpMessage::METHOD_TRACE:
00125     cout << "TRACE" << endl;
00126     break;
00127   }
00128 
00129   cout << "Scheme     : ";
00130   switch (msg.getScheme()) {
00131   case HttpMessage::SCHEME_NONE:
00132     cout << "NONE" << endl;
00133     break;
00134   case HttpMessage::SCHEME_HTTP:
00135     cout << "HTTP" << endl;
00136     break;
00137   }
00138   cout << "Status code: " << msg.getStatusCode() << endl;
00139   cout << "Request URI: " << msg.getRequestURI() << endl;
00140 
00141   return;
00142 }
00143 
00144 //////////////////////////////////////////////////////////////////////////////
00145 // testPreProc()
00146 //////////////////////////////////////////////////////////////////////////////
00147 double
00148 testPreProc(unsigned loopCount)
00149 {
00150   IOBufferPool pool(96 /* bufferSize */ , 20 /* bufferCount */ );
00151   IOBuffer *cb = pool.newBuffer();
00152 
00153   HttpPreProcMessageManager msgMgr;
00154 
00155   HttpPreProc pp(cb, &msgMgr);
00156 
00157   /* start counting time here */
00158   double startTime = ink_time_wall_seconds();
00159 
00160   for (unsigned i = 0; i < loopCount; i++) {
00161 
00162     RequestInput requestInput(request1, cb);
00163 
00164     while (!requestInput.isDone()) {
00165       requestInput.run();
00166       pp.process();
00167     }
00168   }
00169 
00170   double endTime = ink_time_wall_seconds();
00171 
00172   return (endTime - startTime);
00173 }
00174 
00175 //////////////////////////////////////////////////////////////////////////////
00176 // main().
00177 //////////////////////////////////////////////////////////////////////////////
00178 main()
00179 {
00180   for (unsigned lc = 1; lc < 10000; lc *= 10) {
00181     double elapsedTime = testPreProc(lc);
00182     cout << "Elapsed time for " << lc << "loops is " << elapsedTime << endl;
00183   }
00184 
00185 
00186 
00187   return (0);
00188 }

Generated by  doxygen 1.7.1