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

How to run on windows? #66

Open
jfseneca opened this issue Nov 21, 2021 · 3 comments
Open

How to run on windows? #66

jfseneca opened this issue Nov 21, 2021 · 3 comments

Comments

@jfseneca
Copy link

Installed PSrecord successfully, but can't invoke it from command prompt. Was using it in this manner on Linux, would like the same functionality for Windows:

[[Some Linux Command]] & psrecord $! --interval 0.1 --plot plot1.png

Thanks,

@ansonnn07
Copy link

ansonnn07 commented Feb 18, 2022

I just copied the main function out of the library, then run it as a python file. For example, for a script named "run_psrecord.py" as below, just run the command python run_psrecord.py <PID> --plot plot.png --log activity.txt to start it.

# USAGE: python run_psrecord.py <PID> --plot plot.png --log activity.txt

from psrecord.main import monitor
import argparse


def main():
    # copied from C:\Users\user\anaconda3\envs\tfod\Lib\site-packages\psrecord\main.py
    parser = argparse.ArgumentParser(
        description='Record CPU and memory usage for a process')

    parser.add_argument('process_id_or_command', type=str,
                        help='the process id or command')

    parser.add_argument('--log', type=str,
                        help='output the statistics to a file')

    parser.add_argument('--plot', type=str,
                        help='output the statistics to a plot')

    parser.add_argument('--duration', type=float,
                        help='how long to record for (in seconds). If not '
                             'specified, the recording is continuous until '
                             'the job exits.')

    parser.add_argument('--interval', type=float,
                        help='how long to wait between each sample (in '
                             'seconds). By default the process is sampled '
                             'as often as possible.')

    parser.add_argument('--include-children',
                        help='include sub-processes in statistics (results '
                             'in a slower maximum sampling rate).',
                        action='store_true')

    args = parser.parse_args()

    # Attach to process
    try:
        pid = int(args.process_id_or_command)
        print("Attaching to process {0}".format(pid))
        sprocess = None
    except Exception:
        import subprocess
        command = args.process_id_or_command
        print("Starting up command '{0}' and attaching to process"
              .format(command))
        sprocess = subprocess.Popen(command, shell=True)
        pid = sprocess.pid

    monitor(pid, logfile=args.log, plot=args.plot, duration=args.duration,
            interval=args.interval, include_children=args.include_children)

    if sprocess is not None:
        sprocess.kill()

if __name__ == '__main__':
    main()

@SolomidHero
Copy link

python module use is not possible too

(base) PS C:\Users\Administrator\models> python -m psrecord
C:\Users\Administrator\miniconda3\python.exe: No module named psrecord.__main__; 'psreco
rd' is a package and cannot be directly executed

@BramVanroy
Copy link

I also can't get it to run on Windows. The example commands just immediately exit and a system pop-up appears asking me how to open the file. When I open it, it is actually a shell script.

#!.venv\Scripts\python.exe

import sys
import psrecord

if __name__ == '__main__':
    sys.exit(psrecord.main())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants