"Fossies" - the Fresh Open Source Software Archive

Member "httperf-0.9.0/src/gen/uri_wset.c" (7 Apr 2007, 3807 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_wset.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 /* Causes accesses to a fixed set of files (working set) in such a way
   36    that is likely to cause disk I/O with a certain probability.  */
   37 
   38 #include <assert.h>
   39 #include <stdio.h>
   40 #include <stdlib.h>
   41 #include <string.h>
   42 
   43 #include <httperf.h>
   44 #include <call.h>
   45 #include <event.h>
   46 
   47 #define MAX_URI_LEN     128
   48 #define CALL_PRIVATE_DATA(c) \
   49  ((void *) ((char *)(c) + call_private_data_offset))
   50 
   51 static double miss_prob;
   52 static unsigned file_num;
   53 static size_t call_private_data_offset;
   54 static size_t uri_prefix_len;
   55 
   56 static void
   57 set_uri (Event_Type et, Call *c)
   58 {
   59   char *cp, *buf_end;
   60   unsigned j, n;
   61 
   62   assert (et == EV_CALL_NEW && object_is_call (c));
   63 
   64   miss_prob += param.wset.target_miss_rate;
   65   if (miss_prob >= 1.0)
   66     {
   67       /* generate (what we hope to be) a miss */
   68       miss_prob -= 1.0;
   69       file_num += param.client.num_clients;
   70       if (file_num >= param.wset.num_files)
   71     file_num -= param.wset.num_files;
   72     }
   73 
   74   /* fill in extension: */
   75   buf_end = (char *) CALL_PRIVATE_DATA (c) + MAX_URI_LEN;
   76   cp = buf_end - 6;
   77   memcpy (cp, ".html", 6);
   78 
   79   /* fill in file & pathname: */
   80   n = file_num;
   81   for (j = 1; j < param.wset.num_files; j *= 10, n /= 10)
   82     {
   83       cp -= 2;
   84       cp[0] = '/'; cp[1] = '0' + (n % 10);
   85     }
   86 
   87   /* fill in the uri prefix specified by param.uri: */
   88   cp -= uri_prefix_len;
   89   if (cp < (char *) CALL_PRIVATE_DATA (c))
   90     {
   91       fprintf (stderr, "%s.uri_wset: URI buffer overflow!\n", prog_name);
   92       exit (1);
   93     }
   94   memcpy (cp, param.uri, uri_prefix_len);
   95 
   96   call_set_uri (c, cp, (buf_end - cp) - 1);
   97 
   98   if (verbose)
   99     printf ("%s: accessing URI `%s'\n", prog_name, cp);
  100 }
  101 
  102 static void
  103 init (void)
  104 {
  105   Any_Type arg;
  106 
  107   miss_prob = drand48 ();
  108   file_num = param.client.id;
  109 
  110   call_private_data_offset = object_expand (OBJ_CALL, MAX_URI_LEN);
  111 
  112   uri_prefix_len = strlen (param.uri);
  113   if (param.uri[uri_prefix_len - 1] == '/')
  114     {
  115       ++param.uri;
  116       --uri_prefix_len;
  117     }
  118 
  119   arg.l = 0;
  120   event_register_handler (EV_CALL_NEW, (Event_Handler) set_uri, arg);
  121 }
  122 
  123 Load_Generator uri_wset =
  124   {
  125     "Generates URIs accessing a working-set at a given rate",
  126     init,
  127     no_op,
  128     no_op
  129   };