Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Use logging instead of printed statements #65

Merged
merged 3 commits into from
Apr 7, 2021
Merged
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
65 changes: 33 additions & 32 deletions rapidtide/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# $Id: tide_funcs.py,v 1.4 2016/07/12 13:50:29 frederic Exp $
#
import bisect
import logging
import os
import resource
import sys
Expand All @@ -28,13 +29,16 @@
import matplotlib.pyplot as plt
import numpy as np
import pyfftw
import pyfftw.interfaces.scipy_fftpack as fftpack
from numba import jit
from scipy import fftpack

import rapidtide._version as tide_versioneer
import rapidtide.io as tide_io

fftpack = pyfftw.interfaces.scipy_fftpack
bbfrederick marked this conversation as resolved.
Show resolved Hide resolved
LGR = logging.getLogger(__name__)
TimingLGR = logging.getLogger("TIMING")
MemoryLGR = logging.getLogger("MEMORY")
bbfrederick marked this conversation as resolved.
Show resolved Hide resolved

pyfftw.interfaces.cache.enable()

# ---------------------------------------- Global constants -------------------------------------------
Expand Down Expand Up @@ -103,39 +107,39 @@ def disablenumba():


# --------------------------- Utility functions -------------------------------------------------
def logmem(msg, file=None):
"""
def logmem(msg=None):
"""Log memory usage with a logging object.

Parameters
----------
msg
file

Returns
-------

msg : str or None, optional
A message to include in the first column.
If None, the column headers are logged.
Default is None.
"""
global lastmaxrss_parent, lastmaxrss_child
if msg is None:
outvals = [
"",
"Self Max RSS",
"Self Diff RSS",
"Self Shared Mem",
"Self Unshared Mem",
"Self Unshared Stack",
"Self Non IO Page Fault",
"Self IO Page Fault",
"Self Swap Out",
"Children Max RSS",
"Children Diff RSS",
"Children Shared Mem",
"Children Unshared Mem",
"Children Unshared Stack",
"Children Non IO Page Fault",
"Children IO Page Fault",
"Children Swap Out",
]
lastmaxrss_parent = 0
lastmaxrss_child = 0
logline = ",".join(
[
"",
"Self Max RSS",
"Self Diff RSS",
"Self Shared Mem",
"Self Unshared Mem",
"Self Unshared Stack",
"Self Non IO Page Fault" "Self IO Page Fault" "Self Swap Out",
"Children Max RSS",
"Children Diff RSS",
"Children Shared Mem",
"Children Unshared Mem",
"Children Unshared Stack",
"Children Non IO Page Fault" "Children IO Page Fault" "Children Swap Out",
]
)
else:
rcusage = resource.getrusage(resource.RUSAGE_SELF)
outvals = [msg]
Expand All @@ -158,11 +162,8 @@ def logmem(msg, file=None):
outvals.append(str(rcusage.ru_minflt))
outvals.append(str(rcusage.ru_majflt))
outvals.append(str(rcusage.ru_nswap))
logline = ",".join(outvals)
if file is None:
return logline
else:
file.writelines(logline + "\n")

MemoryLGR.info("\t".join(outvals))


def findexecutable(command):
Expand Down
Loading