mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
more flexible --stackmon
This commit is contained in:
parent
0f37718671
commit
868103a9c5
|
@ -749,7 +749,7 @@ def run_argparse(argv: list[str], formatter: Any, retry: bool) -> argparse.Names
|
||||||
ap2.add_argument("--no-scandir", action="store_true", help="disable scandir; instead using listdir + stat on each file")
|
ap2.add_argument("--no-scandir", action="store_true", help="disable scandir; instead using listdir + stat on each file")
|
||||||
ap2.add_argument("--no-fastboot", action="store_true", help="wait for up2k indexing before starting the httpd")
|
ap2.add_argument("--no-fastboot", action="store_true", help="wait for up2k indexing before starting the httpd")
|
||||||
ap2.add_argument("--no-htp", action="store_true", help="disable httpserver threadpool, create threads as-needed instead")
|
ap2.add_argument("--no-htp", action="store_true", help="disable httpserver threadpool, create threads as-needed instead")
|
||||||
ap2.add_argument("--stackmon", metavar="P,S", type=u, help="write stacktrace to Path every S second")
|
ap2.add_argument("--stackmon", metavar="P,S", type=u, help="write stacktrace to Path every S second, for example --stackmon=./st/%Y-%m/%d/%H%M.xz,60")
|
||||||
ap2.add_argument("--log-thrs", metavar="SEC", type=float, help="list active threads every SEC")
|
ap2.add_argument("--log-thrs", metavar="SEC", type=float, help="list active threads every SEC")
|
||||||
ap2.add_argument("--log-fk", metavar="REGEX", type=u, default="", help="log filekey params for files where path matches REGEX; '.' (a single dot) = all files")
|
ap2.add_argument("--log-fk", metavar="REGEX", type=u, default="", help="log filekey params for files where path matches REGEX; '.' (a single dot) = all files")
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
|
@ -707,12 +707,43 @@ def start_stackmon(arg_str: str, nid: int) -> None:
|
||||||
|
|
||||||
def stackmon(fp: str, ival: float, suffix: str) -> None:
|
def stackmon(fp: str, ival: float, suffix: str) -> None:
|
||||||
ctr = 0
|
ctr = 0
|
||||||
|
fp0 = fp
|
||||||
while True:
|
while True:
|
||||||
ctr += 1
|
ctr += 1
|
||||||
|
fp = fp0
|
||||||
time.sleep(ival)
|
time.sleep(ival)
|
||||||
st = "{}, {}\n{}".format(ctr, time.time(), alltrace())
|
st = "{}, {}\n{}".format(ctr, time.time(), alltrace())
|
||||||
|
buf = st.encode("utf-8", "replace")
|
||||||
|
|
||||||
|
if fp.endswith(".gz"):
|
||||||
|
import gzip
|
||||||
|
|
||||||
|
# 2459b 2304b 2241b 2202b 2194b 2191b lv3..8
|
||||||
|
# 0.06s 0.08s 0.11s 0.13s 0.16s 0.19s
|
||||||
|
buf = gzip.compress(buf, compresslevel=6)
|
||||||
|
|
||||||
|
elif fp.endswith(".xz"):
|
||||||
|
import lzma
|
||||||
|
|
||||||
|
# 2276b 2216b 2200b 2192b 2168b lv0..4
|
||||||
|
# 0.04s 0.10s 0.22s 0.41s 0.70s
|
||||||
|
buf = lzma.compress(buf, preset=0)
|
||||||
|
|
||||||
|
if "%" in fp:
|
||||||
|
dt = datetime.utcnow()
|
||||||
|
for fs in "YmdHMS":
|
||||||
|
fs = "%" + fs
|
||||||
|
if fs in fp:
|
||||||
|
fp = fp.replace(fs, dt.strftime(fs))
|
||||||
|
|
||||||
|
if "/" in fp:
|
||||||
|
try:
|
||||||
|
os.makedirs(fp.rsplit("/", 1)[0])
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
with open(fp + suffix, "wb") as f:
|
with open(fp + suffix, "wb") as f:
|
||||||
f.write(st.encode("utf-8", "replace"))
|
f.write(buf)
|
||||||
|
|
||||||
|
|
||||||
def start_log_thrs(
|
def start_log_thrs(
|
||||||
|
|
Loading…
Reference in a new issue