"Fossies" - the Fresh Open Source Software Archive

Member "httperf-0.9.0/src/gen/uri_wlog.c" (7 Apr 2007, 4869 Bytes) of package /linux/www/old/httperf-0.9.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "uri_wlog.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2     httperf -- a tool for measuring web server performance
    3     Copyright 2000-2007 Hewlett-Packard Company and Contributors listed in
    4     AUTHORS file. Originally contributed by David Mosberger-Tang
    5 
    6     This file is part of httperf, a web server performance measurment
    7     tool.
    8 
    9     This program is free software; you can redistribute it and/or
   10     modify it under the terms of the GNU General Public License as
   11     published by the Free Software Foundation; either version 2 of the
   12     License, or (at your option) any later version.
   13     
   14     In addition, as a special exception, the copyright holders give
   15     permission to link the code of this work with the OpenSSL project's
   16     "OpenSSL" library (or with modified versions of it that use the same
   17     license as the "OpenSSL" library), and distribute linked combinations
   18     including the two.  You must obey the GNU General Public License in
   19     all respects for all of the code used other than "OpenSSL".  If you
   20     modify this file, you may extend this exception to your version of the
   21     file, but you are not obligated to do so.  If you do not wish to do
   22     so, delete this exception statement from your version.
   23 
   24     This program is distributed in the hope that it will be useful,
   25     but WITHOUT ANY WARRANTY; without even the implied warranty of
   26     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   27     General Public License for more details.
   28 
   29     You should have received a copy of the GNU General Public License
   30     along with this program; if not, write to the Free Software
   31     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
   32     02110-1301, USA
   33 */
   34 
   35 /* This load generator can be used to recreate a workload based on a
   36    server log file.
   37  
   38    This module can be used in conjunction with two comands to help in
   39    extracting information from the httpd CLF file (contact
   40    eranian@hpl.hp.com).
   41  
   42    Please note that you don't necessary need any of those tools. You
   43    can recreate the list of URIs by hand or with any other programs as
   44    long as you respect the format expected by this module (and also
   45    provided than you have the corresponding document tree on the
   46    server side).
   47  
   48    The format of the file used by this module is very simple (maybe
   49    too simple):
   50 
   51     URI1\0URI2\0......URIn\0
   52   
   53    It is a simple concatenated list of URI separated by the \0 (end of
   54    string) marker.
   55  
   56    This way, we don't need any parsing of the string when generating
   57    the URI.
   58 
   59    You can choose to loop on te list of URIs by using the following
   60    command line option to httperf:
   61 
   62        % httperf .... --wlog y,my_uri_file
   63 
   64    Otherwise httperf will stop once it reaches the end of the list.
   65  
   66    Any comment on this module contact eranian@hpl.hp.com or
   67    davidm@hpl.hp.com.  */
   68 
   69 #include <assert.h>
   70 #include <errno.h>
   71 #include <fcntl.h>
   72 #include <stdio.h>
   73 #include <string.h>
   74 #include <sys/mman.h>
   75 #include <sys/stat.h>
   76 #include <unistd.h>
   77 
   78 #include <sys/types.h>
   79 
   80 #include <httperf.h>
   81 #include <call.h>
   82 #include <core.h>
   83 #include <event.h>
   84 
   85 static char *fbase, *fend, *fcurrent;
   86 
   87 static void
   88 set_uri (Event_Type et, Call * c)
   89 {
   90   int len, did_wrap = 0;
   91   const char *uri;
   92 
   93   assert (et == EV_CALL_NEW && object_is_call (c));
   94 
   95   do
   96     {
   97       if (fcurrent >= fend)
   98     {
   99       if (did_wrap)
  100         panic ("%s: %s does not contain any valid URIs\n",
  101            prog_name, param.wlog.file);
  102       did_wrap = 1;
  103 
  104       /* We reached the end of the uri list so wrap around to the
  105          beginning.  If not looping, also ask for the test to stop
  106          as soon as possible (the current request will still go
  107          out, but httperf won't wait for its reply to show up).  */
  108       fcurrent = fbase;
  109       if (!param.wlog.do_loop)
  110         core_exit ();
  111     }
  112       uri = fcurrent;
  113       len = strlen (fcurrent);
  114       call_set_uri (c, uri, len);
  115       fcurrent += len + 1;
  116     }
  117   while (len == 0);
  118 
  119   if (verbose)
  120     printf ("%s: accessing URI `%s'\n", prog_name, uri);
  121 }
  122 
  123 void
  124 init_wlog (void)
  125 {
  126   struct stat st;
  127   Any_Type arg;
  128   int fd;
  129 
  130   fd = open (param.wlog.file, O_RDONLY, 0);
  131   if (fd == -1)
  132     panic ("%s: can't open %s\n", prog_name, param.wlog.file);
  133 
  134   fstat (fd, &st);
  135   if (st.st_size == 0)
  136     panic ("%s: file %s is empty\n", prog_name, param.wlog.file);
  137 
  138   /* mmap anywhere in address space: */
  139   fbase = (char *) mmap (0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
  140   if (fbase == (char *) 0 - 1)
  141     panic ("%s: can't mmap the file: %s\n", prog_name, strerror (errno));
  142 
  143   close (fd);
  144 
  145   /* set the upper boundary: */
  146   fend = fbase + st.st_size;
  147   /* set current entry: */
  148   fcurrent = fbase;
  149 
  150   arg.l = 0;
  151   event_register_handler (EV_CALL_NEW, (Event_Handler) set_uri, arg);
  152 }
  153 
  154 static void
  155 stop_wlog (void)
  156 {
  157   munmap (fbase, fend - fbase);
  158 }
  159 
  160 Load_Generator uri_wlog =
  161   {
  162     "Generates URIs based on a predetermined list",
  163     init_wlog,
  164     no_op,
  165     stop_wlog
  166   };