OpenDDS  Snapshot(2023/04/28-20:55)
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
OpenDDS::DCPS::ThreadStatusManager::Thread Class Reference

#include <ThreadStatusManager.h>

Collaboration diagram for OpenDDS::DCPS::ThreadStatusManager::Thread:
Collaboration graph
[legend]

Classes

struct  Bucket
 

Public Types

enum  ThreadStatus { ThreadStatus_Active, ThreadStatus_Idle }
 

Public Member Functions

 Thread (const String &bit_key)
 
const Stringbit_key () const
 
const SystemTimePointtimestamp () const
 
const MonotonicTimePointlast_update () const
 
void update (const MonotonicTimePoint &m_now, const SystemTimePoint &s_now, ThreadStatus next_status, const TimeDuration &bucket_limit, bool nested)
 
double utilization (const MonotonicTimePoint &now) const
 

Static Public Attributes

static const size_t bucket_count = 8
 

Private Attributes

const String bit_key_
 
SystemTimePoint timestamp_
 
ThreadStatus status_
 
MonotonicTimePoint last_update_
 
Bucket total_
 
Bucket bucket_ [bucket_count]
 
size_t current_bucket_
 
size_t nesting_depth_
 

Detailed Description

Definition at line 33 of file ThreadStatusManager.h.

Member Enumeration Documentation

◆ ThreadStatus

Constructor & Destructor Documentation

◆ Thread()

OpenDDS::DCPS::ThreadStatusManager::Thread::Thread ( const String bit_key)
inline

Member Function Documentation

◆ bit_key()

const String& OpenDDS::DCPS::ThreadStatusManager::Thread::bit_key ( ) const
inline

◆ last_update()

const MonotonicTimePoint& OpenDDS::DCPS::ThreadStatusManager::Thread::last_update ( ) const
inline

Definition at line 51 of file ThreadStatusManager.h.

◆ timestamp()

const SystemTimePoint& OpenDDS::DCPS::ThreadStatusManager::Thread::timestamp ( void  ) const
inline

Definition at line 50 of file ThreadStatusManager.h.

◆ update()

void OpenDDS::DCPS::ThreadStatusManager::Thread::update ( const MonotonicTimePoint m_now,
const SystemTimePoint s_now,
ThreadStatus  next_status,
const TimeDuration bucket_limit,
bool  nested 
)

Definition at line 19 of file ThreadStatusManager.cpp.

References OpenDDS::DCPS::ThreadStatusManager::Thread::Bucket::active_time, bucket_, bucket_count, current_bucket_, OpenDDS::DCPS::ThreadStatusManager::Thread::Bucket::idle_time, last_update_, nesting_depth_, status_, ThreadStatus_Active, ThreadStatus_Idle, timestamp_, and total_.

24 {
25  timestamp_ = s_now;
26 
27  if (nested) {
28  switch(next_status) {
31  break;
32  case ThreadStatus_Idle:
34  break;
35  }
36  }
37 
38  if (!nested ||
39  (next_status == ThreadStatus_Active && nesting_depth_ == 1) ||
40  (next_status == ThreadStatus_Idle && nesting_depth_ == 0)) {
41  if (bucket_[current_bucket_].active_time + bucket_[current_bucket_].idle_time > bucket_limit) {
47  }
48 
49  const TimeDuration t = m_now - last_update_;
50 
51  switch (status_) {
54  total_.active_time += t;
55  break;
56  case ThreadStatus_Idle:
58  total_.idle_time += t;
59  break;
60  }
61 
62  last_update_ = m_now;
63  status_ = next_status;
64  }
65 }

◆ utilization()

double OpenDDS::DCPS::ThreadStatusManager::Thread::utilization ( const MonotonicTimePoint now) const

Definition at line 67 of file ThreadStatusManager.cpp.

References OpenDDS::DCPS::ThreadStatusManager::Thread::Bucket::active_time, OpenDDS::DCPS::ThreadStatusManager::Thread::Bucket::idle_time, OpenDDS::DCPS::TimeDuration::is_zero(), last_update_, status_, ThreadStatus_Active, ThreadStatus_Idle, total_, and OpenDDS::DCPS::TimeDuration::zero_value.

68 {
69  const TimeDuration active_bonus = (now > last_update_ && status_ == ThreadStatus_Active) ? (now - last_update_) : TimeDuration::zero_value;
70  const TimeDuration idle_bonus = (now > last_update_ && status_ == ThreadStatus_Idle) ? (now - last_update_) : TimeDuration::zero_value;
71  const TimeDuration denom = total_.active_time + active_bonus + total_.idle_time + idle_bonus;
72 
73  if (!denom.is_zero()) {
74  return (total_.active_time + active_bonus) / denom;
75  }
76  return 0;
77 }
static const TimeDuration zero_value
Definition: TimeDuration.h:31

Member Data Documentation

◆ bit_key_

const String OpenDDS::DCPS::ThreadStatusManager::Thread::bit_key_
private

Definition at line 63 of file ThreadStatusManager.h.

◆ bucket_

Bucket OpenDDS::DCPS::ThreadStatusManager::Thread::bucket_[bucket_count]
private

Definition at line 73 of file ThreadStatusManager.h.

Referenced by update().

◆ bucket_count

const size_t OpenDDS::DCPS::ThreadStatusManager::Thread::bucket_count = 8
static

Definition at line 60 of file ThreadStatusManager.h.

Referenced by update().

◆ current_bucket_

size_t OpenDDS::DCPS::ThreadStatusManager::Thread::current_bucket_
private

Definition at line 74 of file ThreadStatusManager.h.

Referenced by update().

◆ last_update_

MonotonicTimePoint OpenDDS::DCPS::ThreadStatusManager::Thread::last_update_
private

Definition at line 71 of file ThreadStatusManager.h.

Referenced by update(), and utilization().

◆ nesting_depth_

size_t OpenDDS::DCPS::ThreadStatusManager::Thread::nesting_depth_
private

Definition at line 75 of file ThreadStatusManager.h.

Referenced by update().

◆ status_

ThreadStatus OpenDDS::DCPS::ThreadStatusManager::Thread::status_
private

Definition at line 65 of file ThreadStatusManager.h.

Referenced by update(), and utilization().

◆ timestamp_

SystemTimePoint OpenDDS::DCPS::ThreadStatusManager::Thread::timestamp_
private

Definition at line 64 of file ThreadStatusManager.h.

Referenced by update().

◆ total_

Bucket OpenDDS::DCPS::ThreadStatusManager::Thread::total_
private

Definition at line 72 of file ThreadStatusManager.h.

Referenced by update(), and utilization().


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