Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.
Open
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
14 changes: 7 additions & 7 deletions rrd_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ def rrd_convert(src_filename, dst_filename, arch_dest):
write_header(arch_dest, ds_cnt, rra_cnt, pdp_step)

### __rrd_read(rrd->ds_def, ds_def_t, rrd->stat_head->ds_cnt);
for ds in range(0, ds_cnt):
for ds in range(ds_cnt):
fd.write(fs.read(40))
for i in range(0, 10):
for _ in range(10):
double_read_write_swap_nan()

row_cnt = 0
### __rrd_read(rrd->rra_def, rra_def_t, rrd->stat_head->rra_cnt);
for rra in range(0, rra_cnt):
for _ in range(rra_cnt):
Comment on lines -126 to +133
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function rrd_convert refactored with the following changes:

fd.write(fs.read(20))
if arch_dest == 'x86_64':
fd.write(b'\x00\x00\x00\x00') # Padding
Expand All @@ -142,7 +142,7 @@ def rrd_convert(src_filename, dst_filename, arch_dest):
fs.read(4) # Padding
if arch_dest == 'armv6l':
fd.write(b'\x00\x00\x00\x00') # Padding
for i in range(0, 10):
for _ in range(10):
double_read_write_swap_nan()
long_rw_func()
long_rw_func()
Expand All @@ -151,16 +151,16 @@ def rrd_convert(src_filename, dst_filename, arch_dest):
fd.write(fs.read(112 * ds_cnt))

### __rrd_read(rrd->cdp_prep, cdp_prep_t, rrd->stat_head->rra_cnt * rrd->stat_head->ds_cnt);
for i in range(0, 10 * ds_cnt * rra_cnt):
for _ in range(10 * ds_cnt * rra_cnt):
double_read_write_swap_nan()

### __rrd_read(rrd->rra_ptr, rra_ptr_t, rrd->stat_head->rra_cnt);
for rra in range(0, rra_cnt):
for rra in range(rra_cnt):
long_rw_func()
length_header_dst = fd.tell()

### __rrd_read(rrd->rrd_value, rrd_value_t, row_cnt * rrd->stat_head->ds_cnt);
for i in range(0, row_cnt * ds_cnt):
for i in range(row_cnt * ds_cnt):
double_read_write_swap_nan()

assert(fd.tell() == length_header_dst + 8 * row_cnt * ds_cnt)
Expand Down
14 changes: 4 additions & 10 deletions rrdinfo-parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _parse_ds(self):
m = re.search(ds_re, line)
if m:
data_source, field, value = m.groups(0)
if not data_source in ds_dict:
if data_source not in ds_dict:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RRDParser._parse_ds refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

ds_dict[data_source] = {}

ds_dict[data_source][field] = value.strip('"').strip()
Expand All @@ -102,7 +102,7 @@ def _parse_rra(self):
m = re.search(rra_re, line)
if m:
rra, field, value = m.groups(0)
if not rra in rra_dict:
if rra not in rra_dict:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RRDParser._parse_rra refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

rra_dict[rra] = {}

rra_dict[rra][field] = value.strip('"').strip()
Expand Down Expand Up @@ -131,10 +131,7 @@ def parse(self):

for key, value in ds.items():
for item in ['max', 'min']:
if value[item] == 'NaN':
value[item] = 'U'
else:
value[item] = float(value[item])
value[item] = 'U' if value[item] == 'NaN' else float(value[item])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RRDParser.parse refactored with the following changes:

ds_str = ' DS:%s:' % key
ds_str += '%s:%s:%s:%s \\' % (
value['type'], value['minimal_heartbeat'],
Expand Down Expand Up @@ -171,10 +168,7 @@ def main():
help="Existing rrdfile to parse")

(options, args) = parser.parse_args()
params = {}
params['debug'] = options.debug
params['file'] = options.file

params = {'debug': options.debug, 'file': options.file}
Comment on lines -174 to +171
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

rrd_parser = RRDParser(params)
rrd_parser.parse()

Expand Down