Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
Arc::DataSpeed Class Reference

Keeps track of average and instantaneous transfer speed. More...

#include <DataSpeed.h>

Collaboration diagram for Arc::DataSpeed:
Collaboration graph
[legend]

List of all members.

Public Types

typedef void(* show_progress_t )(FILE *o, const char *s, unsigned int t, unsigned long long int all, unsigned long long int max, double instant, double average)

Public Member Functions

 DataSpeed (time_t base=DATASPEED_AVERAGING_PERIOD)
 Constructor.
 DataSpeed (unsigned long long int min_speed, time_t min_speed_time, unsigned long long int min_average_speed, time_t max_inactivity_time, time_t base=DATASPEED_AVERAGING_PERIOD)
 Constructor.
 ~DataSpeed (void)
 Destructor.
void verbose (bool val)
 Activate printing information about current time speeds, amount of transfered data.
void verbose (const std::string &prefix)
 Print information about current speed and amout of data.
bool verbose (void)
 Check if speed information is going to be printed.
void set_min_speed (unsigned long long int min_speed, time_t min_speed_time)
 Set minimal allowed speed.
void set_min_average_speed (unsigned long long int min_average_speed)
 Set minmal avaerage speed.
void set_max_inactivity_time (time_t max_inactivity_time)
 Set inactivity tiemout.
time_t get_max_inactivity_time ()
 Get inactivity timeout.
void set_base (time_t base_=DATASPEED_AVERAGING_PERIOD)
 Set averaging time period.
void set_max_data (unsigned long long int max=0)
 Set amount of data to be transfered. Used in verbose messages.
void set_progress_indicator (show_progress_t func=NULL)
 Specify which external function will print verbose messages. If not specified internal one is used.
void reset (void)
 Reset all counters and triggers.
bool transfer (unsigned long long int n=0)
 Inform object, about amount of data has been transfered. All errors are triggered by this method. To make them work application must call this method periodically even with zero value.
void hold (bool disable)
 Turn off speed control.
bool min_speed_failure ()
 Check if minimal speed error was triggered.
bool min_average_speed_failure ()
 Check if minimal average speed error was triggered.
bool max_inactivity_time_failure ()
 Check if maximal inactivity time error was triggered.
unsigned long long int transfered_size (void)
 Returns amount of data this object knows about.

Private Member Functions

void print_statistics (FILE *o, time_t t)

Private Attributes

time_t first_time
time_t last_time
time_t last_activity_time
unsigned long long int N
unsigned long long int Nall
unsigned long long int Nmax
time_t first_speed_failure
time_t last_printed
time_t T
time_t min_speed_time
time_t max_inactivity_time
unsigned long long int min_speed
unsigned long long int min_average_speed
bool be_verbose
std::string verbose_prefix
bool min_speed_failed
bool min_average_speed_failed
bool max_inactivity_time_failed
bool disabled
show_progress_t show_progress

Static Private Attributes

static Logger logger

Detailed Description

Keeps track of average and instantaneous transfer speed.

Also detects data transfer inactivity and other transfer timeouts.

Definition at line 16 of file DataSpeed.h.


Member Typedef Documentation

typedef void(* Arc::DataSpeed::show_progress_t)(FILE *o, const char *s, unsigned int t, unsigned long long int all, unsigned long long int max, double instant, double average)

Definition at line 43 of file DataSpeed.h.


Constructor & Destructor Documentation

Constructor.

Parameters:
basetime period used to average values (default 1 minute).

Definition at line 156 of file DataSpeed.cpp.

                                   {
    min_speed = 0;
    min_speed_time = 0;
    min_average_speed = 0;
    max_inactivity_time = 600; /* MUST have at least pure timeout */
    T = base_;
    be_verbose = false;
    disabled = false;
    show_progress = NULL;
    Nmax = 0;
    reset();
  }

Here is the call graph for this function:

Arc::DataSpeed::DataSpeed ( unsigned long long int  min_speed,
time_t  min_speed_time,
unsigned long long int  min_average_speed,
time_t  max_inactivity_time,
time_t  base = DATASPEED_AVERAGING_PERIOD 
)

Constructor.

Parameters:
basetime period used to average values (default 1 minute).
min_speedminimal allowed speed (Butes per second). If speed drops and holds below threshold for min_speed_time_ seconds error is triggered.
min_speed_time
min_average_speed_minimal average speed (Bytes per second) to trigger error. Averaged over whole current transfer time.
max_inactivity_time- if no data is passing for specified amount of time (seconds), error is triggered.

Definition at line 134 of file DataSpeed.cpp.

                                                                  {
    min_speed = min_speed_;
    min_speed_time = min_speed_time_;
    min_average_speed = min_average_speed_;
    max_inactivity_time = max_inactivity_time_;
    T = base_;
    be_verbose = false;
    disabled = false;
    show_progress = NULL;
    Nmax = 0;
    reset();
  }

Here is the call graph for this function:

Destructor.

Definition at line 150 of file DataSpeed.cpp.

                            {
    /* statistics to screen */
    if (be_verbose)
      print_statistics(stderr, time(NULL));
  }

Here is the call graph for this function:


Member Function Documentation

Get inactivity timeout.

Definition at line 94 of file DataSpeed.h.

{ return max_inactivity_time; };

Here is the caller graph for this function:

void Arc::DataSpeed::hold ( bool  disable)

Turn off speed control.

Parameters:
disabletrue to turn off.

Definition at line 28 of file DataSpeed.cpp.

                                   {
    disabled = disable;
  }

Here is the caller graph for this function:

Check if maximal inactivity time error was triggered.

Definition at line 124 of file DataSpeed.h.

Here is the caller graph for this function:

Check if minimal average speed error was triggered.

Definition at line 120 of file DataSpeed.h.

Here is the caller graph for this function:

Check if minimal speed error was triggered.

Definition at line 116 of file DataSpeed.h.

                             {
      return min_speed_failed;
    }

Here is the caller graph for this function:

void Arc::DataSpeed::print_statistics ( FILE *  o,
time_t  t 
) [private]

Definition at line 77 of file DataSpeed.cpp.

                                                    {
    if (show_progress != NULL) {
      (*show_progress)(o, verbose_prefix.c_str(),
                       (unsigned int)(t - first_time), Nall, Nmax,
                       (t > first_time ?
                        (((double)N) / (((t - first_time) > T) ? T :
                                        (t - first_time))) : ((double)0)),
                       (t > first_time ?
                        (((double)Nall) / (t - first_time)) : ((double)0)));
      return;
    }
    std::string::size_type outlen = verbose_prefix.length()+100;
    char out[outlen];
    snprintf(out,outlen,
            "%s%5u s: %10.1f kB  %8.1f kB/s  %8.1f kB/s    %c %c %c       ",
            verbose_prefix.c_str(),
            (unsigned int)(t - first_time),
            ((double)Nall) / 1024,
            (t > first_time ?
             (((double)N) / (((t - first_time) > T) ? T :
                             (t - first_time)) / 1024) : ((double)0)),
            (t > first_time ?
             (((double)Nall) / (t - first_time) / 1024) : ((double)0)),
            (min_speed_failed ? '!' : '.'),
            (min_average_speed_failed ? '!' : '.'),
            (max_inactivity_time_failed ? '!' : '.'));
    logger.msg(VERBOSE, out);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void Arc::DataSpeed::reset ( void  )

Reset all counters and triggers.

Definition at line 169 of file DataSpeed.cpp.

Here is the caller graph for this function:

Set averaging time period.

Parameters:
basetime period used to average values (default 1 minute).

Definition at line 121 of file DataSpeed.cpp.

                                       {
    N = (N * base_) / T; /* allows ro change T on the fly */
    T = base_;
  }
void Arc::DataSpeed::set_max_data ( unsigned long long int  max = 0)

Set amount of data to be transfered. Used in verbose messages.

Parameters:
maxamount of data in bytes.

Definition at line 130 of file DataSpeed.cpp.

                                                         {
    Nmax = max;
  }

Here is the caller graph for this function:

void Arc::DataSpeed::set_max_inactivity_time ( time_t  max_inactivity_time)

Set inactivity tiemout.

Parameters:
max_inactivity_time- if no data is passing for specified amount of time (seconds), error is triggered.

Definition at line 117 of file DataSpeed.cpp.

                                                                     {
    max_inactivity_time = max_inactivity_time_;
  }

Here is the caller graph for this function:

void Arc::DataSpeed::set_min_average_speed ( unsigned long long int  min_average_speed)

Set minmal avaerage speed.

Parameters:
min_average_speed_minimal average speed (Bytes per second) to trigger error. Averaged over whole current transfer time.

Definition at line 112 of file DataSpeed.cpp.

                                                            {
    min_average_speed = min_average_speed_;
  }

Here is the caller graph for this function:

void Arc::DataSpeed::set_min_speed ( unsigned long long int  min_speed,
time_t  min_speed_time 
)

Set minimal allowed speed.

Parameters:
min_speedminimal allowed speed (Butes per second). If speed drops and holds below threshold for min_speed_time_ seconds error is triggered.
min_speed_time

Definition at line 106 of file DataSpeed.cpp.

                                                        {
    min_speed = min_speed_;
    min_speed_time = min_speed_time_;
  }

Here is the caller graph for this function:

Specify which external function will print verbose messages. If not specified internal one is used.

Parameters:
pointerto function which prints information.

Definition at line 126 of file DataSpeed.cpp.

                                                             {
    show_progress = func;
  }

Here is the caller graph for this function:

bool Arc::DataSpeed::transfer ( unsigned long long int  n = 0)

Inform object, about amount of data has been transfered. All errors are triggered by this method. To make them work application must call this method periodically even with zero value.

Parameters:
namount of data transfered (bytes).

Definition at line 32 of file DataSpeed.cpp.

                                                   {
    if (disabled) {
      last_time = time(NULL);
      return true;
    }
    time_t t = time(NULL);
    time_t dt = t - last_time;
    Nall += n;
    if (dt > T)
      N = (n * dt) / T;
    else
      N = (N * (T - dt)) / T + n;
    if ((t - first_time) >= T * 3) {
      /* make decision only after statistics settles */
      /* check for speed */
      if (N < (T * min_speed))
        if (first_speed_failure != 0) {
          if (t > (first_speed_failure + min_speed_time))
            min_speed_failed = true;
        }
        else
          first_speed_failure = t;
      else
        first_speed_failure = 0;
      /* check for avearge speed */
      if ((min_average_speed * (t - first_time)) > Nall)
        min_average_speed_failed = true;
      /* check for inactivity time */
      if (t > (last_activity_time + max_inactivity_time))
        max_inactivity_time_failed = true;
    }
    if (n > 0)
      last_activity_time = t;
    last_time = t;
    if (be_verbose)
      /* statistics to screen */
      if ((t - last_printed) >= 1) {
        print_statistics(stderr, t);
        last_printed = t;
      }
    return !(min_speed_failed || min_average_speed_failed ||
             max_inactivity_time_failed);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned long long int Arc::DataSpeed::transfered_size ( void  ) [inline]

Returns amount of data this object knows about.

Definition at line 128 of file DataSpeed.h.

                                                 {
      return Nall;
    }

Here is the caller graph for this function:

void Arc::DataSpeed::verbose ( bool  val)

Activate printing information about current time speeds, amount of transfered data.

Definition at line 19 of file DataSpeed.cpp.

                                  {
    be_verbose = val;
  }

Here is the caller graph for this function:

void Arc::DataSpeed::verbose ( const std::string &  prefix)

Print information about current speed and amout of data.

Parameters:
'prefix'add this string at the beginning of every string.

Definition at line 23 of file DataSpeed.cpp.

                                                 {
    be_verbose = true;
    verbose_prefix = prefix;
  }
bool Arc::DataSpeed::verbose ( void  )

Check if speed information is going to be printed.

Definition at line 15 of file DataSpeed.cpp.

                              {
    return be_verbose;
  }

Member Data Documentation

Definition at line 32 of file DataSpeed.h.

bool Arc::DataSpeed::disabled [private]

Definition at line 39 of file DataSpeed.h.

Definition at line 24 of file DataSpeed.h.

time_t Arc::DataSpeed::first_time [private]

Definition at line 18 of file DataSpeed.h.

Definition at line 20 of file DataSpeed.h.

time_t Arc::DataSpeed::last_printed [private]

Definition at line 25 of file DataSpeed.h.

time_t Arc::DataSpeed::last_time [private]

Definition at line 19 of file DataSpeed.h.

Logger Arc::DataSpeed::logger [static, private]

Definition at line 40 of file DataSpeed.h.

Definition at line 29 of file DataSpeed.h.

Definition at line 37 of file DataSpeed.h.

unsigned long long int Arc::DataSpeed::min_average_speed [private]

Definition at line 31 of file DataSpeed.h.

Definition at line 36 of file DataSpeed.h.

unsigned long long int Arc::DataSpeed::min_speed [private]

Definition at line 30 of file DataSpeed.h.

Definition at line 35 of file DataSpeed.h.

Definition at line 28 of file DataSpeed.h.

unsigned long long int Arc::DataSpeed::N [private]

Definition at line 21 of file DataSpeed.h.

unsigned long long int Arc::DataSpeed::Nall [private]

Definition at line 22 of file DataSpeed.h.

unsigned long long int Arc::DataSpeed::Nmax [private]

Definition at line 23 of file DataSpeed.h.

Definition at line 48 of file DataSpeed.h.

time_t Arc::DataSpeed::T [private]

Definition at line 27 of file DataSpeed.h.

std::string Arc::DataSpeed::verbose_prefix [private]

Definition at line 33 of file DataSpeed.h.


The documentation for this class was generated from the following files: