Skip to content

Commit

Permalink
Rolling files working
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Tyler committed Oct 12, 2022
1 parent 54a67e2 commit 5622678
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ cpu.png
mem.png
*.csv
.vscode/settings.json
running
done
25 changes: 15 additions & 10 deletions bin/pagurus
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ except ImportError:
class FileWriter:
compressed = False

def __init__(self, outfile, header: List[str] = [""], write_header: bool = True) -> None:
def __init__(self, outfile,
header: List[str] = [""],
write_header: bool = True,
rolling: bool = False) -> None:
self.extensions = {
'gz': 'csv.gz',
'bz2': 'csv.bz2',
Expand All @@ -33,6 +36,7 @@ class FileWriter:
self.header: List[str] = header
self.number: int = 0
self.write_header: bool = write_header
self.rolling: bool = rolling

# Make formater based on number of metrics in header
fmt = ",".join(["{}" for _ in range(len(header))])
Expand Down Expand Up @@ -76,15 +80,16 @@ class FileWriter:
if self.number != 0:
self.close()

# Split name into it's parts
name_split = self.outfile.as_posix().split('.')
# Get the right extention
ext = self.extensions[name_split[-1]]
if self.rolling:
# Split name into it's parts
name_split = self.outfile.as_posix().split('.')
# Get the right extention
ext = self.extensions[name_split[-1]]
# Add in the file number into the name
new_outfile_name = f"{name_split[0]}.{self.number}.{ext}"
# Replace the path
self.outfile = Path(new_outfile_name)

# Add in the file number into the name
new_outfile_name = f"{name_split[0]}.{self.number}.{ext}"
# Replace the path
self.outfile = Path(new_outfile_name)
self._open_file()
if self.write_header:
self._write_header()
Expand Down Expand Up @@ -266,7 +271,7 @@ def runner(
"write_chars", "cmdline", "current_dir"]

stats_file = FileWriter(
outfile=outfile, header=header, write_header=write_header)
outfile=outfile, header=header, write_header=write_header, rolling=True if rolling > 0 else False)
itteration = 0
# Keep pulling data from the process while it's running
while not killer.kill_now:
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
matplotlib
pandas
numpy
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
with open(f"{_dir}/README.md") as f:
long_desc = f.read()

#with open(f"{_dir}/VERSION") as f:
# with open(f"{_dir}/VERSION") as f:
# version = f.read()
# __version__ = version

Expand All @@ -22,7 +22,7 @@
url="https://github.com/tylern4/pagurus",
author="Nick Tyler",
author_email="[email protected]",
version='1.0.2',
version='1.1',
scripts=glob('bin/*'),
install_requires=[
'psutil==5.8.0',
Expand Down

0 comments on commit 5622678

Please sign in to comment.