Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/pcp/iostat/pcp-iostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,18 @@ class IostatReport(pmcc.MetricGroupPrinter):
Hcount = 0
def timeStampDelta(self, group):
s = group.timestamp.tv_sec - group.prevTimestamp.tv_sec
n = group.timestamp.tv_nsec - group.prevTimestamp.tv_nsec
# n may be negative here, calculation is still correct.
return s + n / 1000000000.0
# pmapi timestamps may provide sub-second resolution via tv_nsec (nanoseconds)
# or tv_usec (microseconds) depending on the collector. Prefer nanoseconds
# when available, but gracefully fall back to microseconds to avoid
if hasattr(group.timestamp, 'tv_nsec') and hasattr(group.prevTimestamp, 'tv_nsec'):
n = group.timestamp.tv_nsec - group.prevTimestamp.tv_nsec
# n may be negative here, calculation is still correct.
return s + n / 1_000_000_000.0
elif hasattr(group.timestamp, 'tv_usec') and hasattr(group.prevTimestamp, 'tv_usec'):
u = group.timestamp.tv_usec - group.prevTimestamp.tv_usec
return s + u / 1_000_000.0
# it should not reach here
return s

def instlist(self, group, name):
return dict(map(lambda x: (x[1], x[2]), group[name].netValues)).keys()
Expand Down
13 changes: 11 additions & 2 deletions src/pcp/mpstat/pcp-mpstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,17 @@ def __init__(self, cpu_util_reporter, total_interrupt_usage_reporter, soft_inter

def timeStampDelta(self, group):
s = group.timestamp.tv_sec - group.prevTimestamp.tv_sec
n = group.timestamp.tv_nsec - group.prevTimestamp.tv_nsec
return s + n / 1000000000.0
# pmapi timestamps may provide sub-second resolution via tv_nsec (nanoseconds)
# or tv_usec (microseconds) depending on the collector. Prefer nanoseconds
# when available, but gracefully fall back to microseconds to avoid
if hasattr(group.timestamp, 'tv_nsec') and hasattr(group.prevTimestamp, 'tv_nsec'):
n = group.timestamp.tv_nsec - group.prevTimestamp.tv_nsec
return s + n / 1_000_000_000.0
elif hasattr(group.timestamp, 'tv_usec') and hasattr(group.prevTimestamp, 'tv_usec'):
u = group.timestamp.tv_usec - group.prevTimestamp.tv_usec
return s + u / 1_000_000.0
# it should not reach here
return s

def print_machine_info(self,group, context):
self.get_summary_metrics(group)
Expand Down
13 changes: 11 additions & 2 deletions src/pcp/pidstat/pcp-pidstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,17 @@ class PidstatReport(pmcc.MetricGroupPrinter):

def timeStampDelta(self, group):
s = group.timestamp.tv_sec - group.prevTimestamp.tv_sec
n = group.timestamp.tv_nsec - group.prevTimestamp.tv_nsec
return s + n / 1000000000.0
# pmapi timestamps may provide sub-second resolution via tv_nsec (nanoseconds)
# or tv_usec (microseconds) depending on the collector. Prefer nanoseconds
# when available, but gracefully fall back to microseconds to avoid
if hasattr(group.timestamp, 'tv_nsec') and hasattr(group.prevTimestamp, 'tv_nsec'):
n = group.timestamp.tv_nsec - group.prevTimestamp.tv_nsec
return s + n / 1_000_000_000.0
elif hasattr(group.timestamp, 'tv_usec') and hasattr(group.prevTimestamp, 'tv_usec'):
u = group.timestamp.tv_usec - group.prevTimestamp.tv_usec
return s + u / 1_000_000.0
# it should not reach here
return s

def print_machine_info(self,group, context):
timestamp = context.pmLocaltime(group.timestamp.tv_sec)
Expand Down
13 changes: 11 additions & 2 deletions src/pcp/ps/pcp-ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,17 @@ def __init__(self, group=None, options = None):

def timeStampDelta(self):
s = self.group.timestamp.tv_sec - self.group.prevTimestamp.tv_sec
n = self.group.timestamp.tv_nsec - self.group.prevTimestamp.tv_nsec
return s + n / 1000000000.0
# pmapi timestamps may provide sub-second resolution via tv_nsec (nanoseconds)
# or tv_usec (microseconds) depending on the collector. Prefer nanoseconds
# when available, but gracefully fall back to microseconds to avoid
if hasattr(self.group.timestamp, 'tv_nsec') and hasattr(self.group.prevTimestamp, 'tv_nsec'):
n = self.group.timestamp.tv_nsec - self.group.prevTimestamp.tv_nsec
return s + n / 1_000_000_000.0
elif hasattr(self.group.timestamp, 'tv_usec') and hasattr(self.group.prevTimestamp, 'tv_usec'):
u = self.group.timestamp.tv_usec - self.group.prevTimestamp.tv_usec
return s + u / 1_000_000.0
# it should not reach here
return s

def print_machine_info(self,context):
timestamp = context.pmLocaltime(self.group.timestamp.tv_sec)
Expand Down
15 changes: 12 additions & 3 deletions src/pcp/tapestat/pcp-tapestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,18 @@ class TapestatReport(pmcc.MetricGroupPrinter):
Hcount = 0
def timeStampDelta(self, group):
s = group.timestamp.tv_sec - group.prevTimestamp.tv_sec
n = group.timestamp.tv_nsec - group.prevTimestamp.tv_nsec
# n may be negative here, calculation is still correct.
return s + n / 1000000000.0
# pmapi timestamps may provide sub-second resolution via tv_nsec (nanoseconds)
# or tv_usec (microseconds) depending on the collector. Prefer nanoseconds
# when available, but gracefully fall back to microseconds to avoid
if hasattr(group.timestamp, 'tv_nsec') and hasattr(group.prevTimestamp, 'tv_nsec'):
n = group.timestamp.tv_nsec - group.prevTimestamp.tv_nsec
# n may be negative here, calculation is still correct.
return s + n / 1_000_000_000.0
elif hasattr(group.timestamp, 'tv_usec') and hasattr(group.prevTimestamp, 'tv_usec'):
u = group.timestamp.tv_usec - group.prevTimestamp.tv_usec
return s + u / 1_000_000.0
# it should not reach here
return s
def instlist(self, group, name):
return dict(map(lambda x: (x[1], x[2]), group[name].netValues)).keys()

Expand Down
Loading