<?xml version="1.0"?>
<!DOCTYPE gsdoc PUBLIC "-//GNUstep//DTD gsdoc 1.0.4//EN" "http://www.gnustep.org/gsdoc-1_0_4.dtd">
<gsdoc base="GSThroughput">
  <head>
    <title>GSThroughput class documentation</title>
    <author name="Richard Frith-Macdonald">
      <email address="rfm@gnu.org">
        rfm@gnu.org
      </email>
    </author>
    <date>Generated at 2024-09-28 15:36:41 -0600</date>
    <copy>2005-2008 Free Software Foundation, Inc.</copy>
  </head>
  <body>
    <front><contents /></front>
    <chapter>
      <heading>
        Software documentation for the GSThroughput class
      </heading>
      <class name="GSThroughput" super="NSObject">
        <declared>GSThroughput.h</declared>
        <desc>
          <p>
            The GSThroughput class is used maintain statistics
            about the number of events or the duration of
            operations in your software.
          </p>
          <p>
            For performance reasons, the class avoids locking and
            you must ensure that an instance of the class is only
            ever used by a single thread (the one in which it was
            created). You are responsible for ensuring that a
            run loop runs in each thread in which you use an
            instance, so that stats can be updated for that
            thread every second.
          </p>
          <p>
            You create an instance of the class for each
            event/operation that you are interested in
            monitoring, and you call the
            <ref type="method" id="-add:">
              -add:
            </ref>
            or
            <ref type="method" id="-addDuration:">
              -addDuration:
            </ref>
            method to record events. <br /> For duration
            logging, you may also use the
            <ref type="method" id="-startDuration:">
              -startDuration:
            </ref>
            and
            <ref type="method" id="-endDuration">
              -endDuration
            </ref>
            methods to handle adding of the amount of time
            taken between the two calls.
          </p>
          <p>
            To dump a record of the gathered statistics, you may
            call the
            <ref type="method" id="-description">
              -description
            </ref>
            method of an instance or the class
            <ref type="method" id="+description">
              +description
            </ref>
            method to dump statistics for all instances in the
            current thread. <br /> If you need to gather a
            record for all the threads you use, you must
            generate a dump in each thread and combine the
            results.
          </p>
          <p>
            To be notified of statistics at the end of each minute,
            you may call the
            <ref type="method" id="-enableNotifications:">
              -enableNotifications:
            </ref>
            method for an instance. The notifications are
            generated in the thread that instance belongs to.
          </p>
        </desc>
        <ivariable type="void*" name="_data" validity="protected">
          <desc>
            <em>Warning</em> the underscore at the start of the
            name of this instance variable indicates that, even
            though it is not technically <em>private</em>, it is
            intended for internal use within the package, and
            you should not use the variable in other code.
          </desc>
        </ivariable>
        <method type="NSArray*" factory="yes">
          <sel>allInstances</sel>
          <desc>
            Return all the current throughput measuring objects
            in the current thread. NB. This does not return
            instances from other threads.
          </desc>
        </method>
        <method type="NSString*" factory="yes">
          <sel>description</sel>
          <desc>
            Return a report on all GSThroughput instances in the
            current thread... <br /> This calls the
            <ref type="method" id="-description" class="GSThroughput">
              [GSThroughput -description]
            </ref>
            method of the individual instances to get a report
            on each one. <br /> The results are ordered
            alphabetically by name of the instances (an
            instance without a name is treated as having an
            empty string as a name).
          </desc>
        </method>
        <method type="void" factory="yes">
          <sel>setTick:</sel>
          <arg type="BOOL">aFlag</arg>
          <desc>
            Instructs the monitoring system to use a timer at
            the start of each second for keeping its idea of the
            current time up to date. This timer is used to call
            the <ref type="method" id="+tick">+tick</ref> method in
            the current thread. <br /> Passing a value of
            <code>NO</code> for <var>aFlag</var> will turn off
            the timer for the current thread. <br /> For the timer
            to work, the thread's runloop must be running. <br />
            Keeping the notion of the current time up to date
            is important for instances configured to record stats
            broken down over a number of periods, since the
            periodic breakdown must be adjusted each second.
          </desc>
        </method>
        <method type="void" factory="yes">
          <sel>tick</sel>
          <desc>
            Updates the monitoring system's notion of the
            current time for all instances associated with the
            current thread. <br /> This should be called at the
            start of each second (or more often) if you want an
            accurate breakdown of monitoring by the second.
            <br /> If you don't want to call this yourself, you
            can call
            <ref type="method" id="+setTick:">
              +setTick:
            </ref>
            to have it called automatically. <br /> If you are not
            using any instances of the class configured to
            maintain a breakdown of stats by periods, you do
            not need to call this method.
          </desc>
        </method>
        <method type="void">
          <sel>add:</sel>
          <arg type="unsigned">count</arg>
          <desc>
            Add to the <var>count</var> of the number of
            transactions for the receiver. <br /> You may
            use this method only if the receiver was initialised
            with duration logging turned off.
          </desc>
        </method>
        <method type="void">
          <sel>add:</sel>
          <arg type="unsigned">count</arg>
          <sel>duration:</sel>
          <arg type="NSTimeInterval">length</arg>
          <desc>
            Adds a record for multiple events of the specified
            <em>total</em> duration. <br /> This is useful where
            you know a lot of similar events have completed in a
            particular period of time, but can't afford to
            measure the duration of the individual events
            because the timing overheads would be too great.
            <br /> You may use this method only if the receiver
            was initialised with duration logging turned on.
          </desc>
        </method>
        <method type="void">
          <sel>addDuration:</sel>
          <arg type="NSTimeInterval">length</arg>
          <desc>
            Adds a record for a single event of the specified
            duration. <br /> You may use this method only if
            the receiver was initialised with duration logging
            turned on.
          </desc>
        </method>
        <method type="NSString*">
          <sel>description</sel>
          <desc>
            Returns a string describing the status of the
            receiver. <br /> For an instance configured to
            maintain a periodic breakdown of stats, this
            reports information for the current second, all
            seconds in the current minute, all minutes in the
            current period, and all periods in the configured
            number of periods. <br /> For an instance configured
            with no periodic breakdown, this produces a
            <strong>short</strong> summary of the total count
            of events and, where durations are used, the maximum,
            minimum and average duration of events.
          </desc>
        </method>
        <method type="BOOL">
          <sel>enableNotifications:</sel>
          <arg type="BOOL">flag</arg>
          <desc>
            Sets a <var>flag</var> to say whether the receiver
            will send GSThroughputNotification at the end of each
            minute to provide information about statistics.
            <br /> The method returnes the previous setting. The
            initial setting is <code>NO</code>. <br /> The
            notification object is the reciever, and the
            user info dictionary contains some or all of the
            following keys depending on how the receiver was
            configured:
            <deflist>
              <term>GSThroughputCountKey</term>
              <desc>
                The number of events recorded (
                <strong>unsigned</strong> integer number)
              </desc>
              <term>GSThroughputMaximumKey</term>
              <desc>
                The maximum event duration (<strong>double</strong>
                floating point number)
              </desc>
              <term>GSThroughputMinimumKey</term>
              <desc>
                The minimum event duration (<strong>double</strong>
                floating point number) or -1.0 if no events
                occurred during the minute.
              </desc>
              <term>GSThroughputTimeKey</term>
              <desc>
                The time of the start of the minute (an NSDate)
              </desc>
              <term>GSThroughputTotalKey</term>
              <desc>
                The sum of event durations (<strong>double</strong>
                floating point number)
              </desc>
            </deflist>
          </desc>
        </method>
        <method type="void">
          <sel>endDuration</sel>
          <desc>
            Ends duration recording for the current event started
            by a matching call to the
            <ref type="method" id="-startDuration:">
              -startDuration:
            </ref>
            method. <br /> Calls to this method without a
            matching call to
            <ref type="method" id="-startDuration:">
              -startDuration:
            </ref>
            are quietly ignored. This is useful if you wish to time
            a function or method by starting/ending timing
            before/after calling it, but also want the
            function/method to be able to end timing of
            itsself before it calls another function/method.
          </desc>
        </method>
        <method type="void">
          <sel>endDuration:</sel>
          <arg type="unsigned">count</arg>
          <desc>
            Acts like
            <ref type="method" id="-endDuration">
              -endDuration
            </ref>
            but records the duration as a total for
            <var>count</var> events (if <var>count</var> is zero
            then this ends the interval started by the
            corresponding
            <ref type="method" id="-startDuration:">
              -startDuration:
            </ref>
            call, but nothing is logged). <br /> This can be used
            when recording multiple events where the overhead of
            timing each event individually would be too great.
          </desc>
        </method>
        <method type="id">
          <sel>init</sel>
          <desc>
            Initialises the receiver for duration logging
            (in the current thread only) for fifteen minute periods
            over the last twentyfour hours.
          </desc>
        </method>
        <method type="id" init="yes">
          <sel>initWithDurations:</sel>
          <arg type="BOOL">aFlag</arg>
          <sel>forPeriods:</sel>
          <arg type="unsigned">numberOfPeriods</arg>
          <sel>ofLength:</sel>
          <arg type="unsigned">minutesPerPeriod</arg>
          <desc>
            <p>
              Initialises the receiver to maintain stats
              (for the current thread only) over a particular time
              range, specifying whether duration statistics are
              to be maintained, or just event/transaction counts.
            </p>
            <p>
              If the specified <var>numberOfPeriods</var> or
              <var>minutesPerPeriod</var> is zero, only a running
              total is maintained rather than a per-second
              breakdown for the current minute and per minute
              breakdown for the current period and period
              breakdown for the number of periods.
            </p>
            <p>
              If all instances in a thread are initialised with
              <var>numberOfPeriods</var> or
              <var>minutesPerPeriod</var> of zero, the
              <ref type="method" id="+tick">
                +tick
              </ref>
              method does not need to be called and
              <ref type="method" id="+setTick:">
                +setTick:
              </ref>
              should not be used.
            </p>
          </desc>
        </method>
        <method type="NSString*">
          <sel>name</sel>
          <desc>
            Return the name of this instance (as set using
            -setName:). <br /> This is used in the
            <ref type="method" id="-description">
              -description
            </ref>
            method and for ordering instances in the
            <ref type="method" id="+description">
              +description
            </ref>
            method.
          </desc>
        </method>
        <method type="void">
          <sel>setName:</sel>
          <arg type="NSString*">name</arg>
          <desc>
            Sets the <var>name</var> of this instance.
          </desc>
        </method>
        <method type="void">
          <sel>startDuration:</sel>
          <arg type="NSString*">name</arg>
          <desc>
            Starts recording the duration of an event. This must
            be followed by a matching call to the
            <ref type="method" id="-endDuration">
              -endDuration
            </ref>
            method. <br /> The <var>name</var> argument is used
            to identify the location of the call for
            debugging/logging purposes, and you must
            ensure that the string continues to exist up to the
            point where
            <ref type="method" id="-endDuration">
              -endDuration
            </ref>
            is called, as the receiver will not retain it. <br />
            You may use this method only if the receiver was
            initialised with duration logging turned on.
            <br /> Use of this method if the reciever does not
            support duration logging or if the method has
            already been called without a matching call to
            <ref type="method" id="-endDuration">
              -endDuration
            </ref>
            will cause an exception to be raised.
          </desc>
        </method>
      </class>
    </chapter>
    <chapter>
      <heading>GSThroughput constants</heading>
      <p></p>
      <constant type="NSString* const" name="GSThroughputCountKey">
        <desc>
          <em>Description forthcoming.</em>
        </desc>
      </constant>
      <constant type="NSString* const" name="GSThroughputMaximumKey">
        <desc>
          <em>Description forthcoming.</em>
        </desc>
      </constant>
      <constant type="NSString* const" name="GSThroughputMinimumKey">
        <desc>
          <em>Description forthcoming.</em>
        </desc>
      </constant>
      <constant type="NSString* const" name="GSThroughputNotification">
        <desc>
          <em>Description forthcoming.</em>
        </desc>
      </constant>
      <constant type="NSString* const" name="GSThroughputTimeKey">
        <desc>
          <em>Description forthcoming.</em>
        </desc>
      </constant>
      <constant type="NSString* const" name="GSThroughputTotalKey">
        <desc>
          <em>Description forthcoming.</em>
        </desc>
      </constant>
    </chapter>
  </body>
</gsdoc>
