Skip to content

Commit

Permalink
read compressed log files according to file ext
Browse files Browse the repository at this point in the history
  • Loading branch information
bd4 committed Jun 28, 2022
1 parent c48691a commit bcabe23
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cublas_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from tabulate import tabulate
from mvt.display import cuBLASApothecary
from mvt.open import open_compressed
from tqdm import tqdm

def parse_iter_blask(f, time_thr = 1e-6):
Expand Down Expand Up @@ -60,7 +61,7 @@ def parse_and_display(f,count):

args = parser.parse_args()
if args.filename:
f = open(args.filename, 'r')
f = open_compressed(args.filename, 'rt')
elif not sys.stdin.isatty():
f = sys.stdin
else:
Expand Down
3 changes: 2 additions & 1 deletion mkl_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from tabulate import tabulate
from mvt.display import BLASApothecary, FFTApothecary
from mvt.parse import parse_iter
from mvt.open import open_compressed
import greenlet
from tqdm import tqdm

Expand Down Expand Up @@ -89,7 +90,7 @@ def parse_and_display(f,count):

args = parser.parse_args()
if args.filename:
f = open(args.filename, 'r')
f = open_compressed(args.filename, 'rt')
elif not sys.stdin.isatty():
f = sys.stdin
else:
Expand Down
18 changes: 18 additions & 0 deletions mvt/open.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
File open helpers.
"""

def open_compressed(file_path, mode='r'):
"""Open file path and decompress on the fly using built in standard
library modules if it has the appropriate extension."""
if file_path.endswith('.xz'):
import lzma
return lzma.open(file_path, mode)
elif file_path.endswith('.bz2'):
import bz2
return bz2.open(file_path, mode)
elif file_path.endswith('.gz'):
import gzip
return gzip.open(file_path, mode)
else:
return open(file_path, mode)

0 comments on commit bcabe23

Please sign in to comment.