Skip to content

Commit

Permalink
pushing what I have
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Powers committed Nov 23, 2019
1 parent 020b580 commit 4383849
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
14 changes: 12 additions & 2 deletions whatsthis/probes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Initialize probes."""

import glob
import math
import os
import platform

Expand All @@ -28,8 +29,17 @@ def _get_index(path, pattern):
def _human_units(value):
"""TODO."""
if value.endswith('kB'):
value = str(int(int(value.rstrip('kB')) / 1000 / 1000)) + 'GB'
return value
return str(int(int(value.rstrip('kB')) / 1000 / 1000)) + 'GB'
if value.endswith('K'):
value = int(value.rstrip('K'))
if value == 0:
return "0B"
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
i = int(math.floor(math.log(value, 1024)))
p = math.pow(1024, i)
s = round(value / p, 2)
return "%s %s" % (s, size_name[i])


@staticmethod
def _sysfs_search(pattern):
Expand Down
48 changes: 27 additions & 21 deletions whatsthis/probes/processor/cpu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is part of whatsthis. See LICENSE file for license information.
"""Read cpu data."""

from whatsthis.probes.processor.cache import Cache
from whatsthis.probes import Probe


Expand All @@ -11,34 +12,39 @@ def __init__(self, node_index, path):
"""TODO."""
super().__init__()

self.node_index = node_index
self.index = self._get_index(path, 'cpu')
self.path = path
self.topology = {
'node': node_index,
'socket': self._sysfs_read(
'%s/topology/physical_package_id' % self.path
),
'core': self._sysfs_read(
'%s/topology/core_id' % self.path
),
'thread': self._sysfs_read(
'%s/topology/thread_siblings_list' % self.path
).split(',').index(self.index)
}

cache_glob = '%s/cache/index*[0-9]' % self.path
self.cache = [
Cache(self.index, path) for path in sorted(
self._sysfs_search(cache_glob)
)
]

def __lt__(self, other):
"""TODO."""
return self.index < other.index
return int(self.index) < int(other.index)

def __str__(self):
"""TODO."""
return 'cpu %s: %s/%s/%s' % (
self.index, self.socket_index, self.core_index, self.thread_index
)

@property
def socket_index(self):
"""TODO."""
return self._sysfs_read('%s/topology/physical_package_id' % self.path)
cache = ''
for level in self.cache:
cache += ' %s' % level

@property
def core_index(self):
"""TODO."""
return self._sysfs_read('%s/topology/core_id' % self.path)

@property
def thread_index(self):
"""TODO."""
siblings = self._sysfs_read(
'%s/topology/thread_siblings_list' % self.path
return 'cpu %s: %s/%s/%s%s' % (
self.index, self.topology['socket'], self.topology['core'],
self.topology['thread'], cache
)
return siblings.split(',').index(self.index)

0 comments on commit 4383849

Please sign in to comment.