-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #642 from lukemartinlogan/dev
Python binding converter for Metadata Snapshot
- Loading branch information
Showing
3 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
wrapper/python/py_hermes_mdm/py_hermes_mdm/py_hermes_mdm.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
import sys | ||
import os | ||
print(os.getenv('PYTHONPATH')) | ||
from py_hermes import Hermes, TRANSPARENT_HERMES | ||
class MetadataSnapshot: | ||
def __init__(self): | ||
TRANSPARENT_HERMES() | ||
self.hermes = Hermes() | ||
self.blob_info = [] | ||
self.target_info = [] | ||
self.tag_info = [] | ||
|
||
@staticmethod | ||
def unique(id): | ||
return f'{id.unique}.{id.node_id}' | ||
|
||
def collect(self): | ||
mdm = self.hermes.CollectMetadataSnapshot() | ||
for blob in mdm.blob_info: | ||
blob_info = { | ||
'name': str(blob.get_name()), | ||
'id': self.unique(blob.blob_id), | ||
'score': float(blob.score), | ||
'access_frequency': 0, | ||
'buffer_info': [] | ||
} | ||
for buf in blob.buffers: | ||
buf_info = { | ||
'target_id': self.unique(buf.tid), | ||
'size': int(buf.t_size) | ||
} | ||
blob_info['buffer_info'].append(buf_info) | ||
self.blob_info.append(blob_info) | ||
for tag in mdm.bkt_info: | ||
tag_info = { | ||
'id': self.unique(tag.tag_id), | ||
'name': str(tag.get_name()), | ||
'blobs': [self.unique(blob.blob_id) for blob in tag.blobs] | ||
} | ||
self.tag_info.append(tag_info) | ||
for target in mdm.target_info: | ||
target_info = { | ||
'name': None, | ||
'id': self.unique(target.tgt_id), | ||
'rem_cap': target.rem_cap, | ||
'max_cap': target.max_cap, | ||
'bandwidth': target.bandwidth, | ||
'latency': target.latency, | ||
'score': target.score, | ||
} | ||
self.target_info.append(target_info) | ||
self.target_info.sort(reverse=True, key=lambda x: x['bandwidth']) | ||
for i, target in enumerate(self.target_info): | ||
target['name'] = f'Tier {i}' | ||
|
||
# mdm = MetadataSnapshot() | ||
# mdm.collect() | ||
# print('Done') |