Find a String version of a GroovyConsole Script in a Heap Dump - groovy

I've accidentally ran a script with an infinite loop in GroovyConsole. :-\
For the sake of Murphy's Law, I haven't save my work during 3 or 4 hours. So, before killing the GroovyConsole Process, I've dumped the heap, with the hope to find a String version of the Script that was running at this moment
Do you have a hint in which Class it can hide, or if it is possible ?

So, it happens that my guess was right. The groovy.ui.Console Object keeps an history of changes of the script. I give you the OQL query that gave me my script back for my greatest pleasure. I ran it in VisualVM with the OQL plugin, but I could have used jhat :
select x.history.elementData[x.history.elementData.length-2].allText.toString() from groovy.ui.Console x
Despaired groovy developers who've lost their code once might be releaved now :-) For sure I am
The string version of the script may exists in another object. I'd love to hear other solutions

Related

How do I make my Rust program communicate to systemd's WatchDog?

I've followed this tutorial:
https://www.linode.com/docs/guides/start-service-at-boot/
and set everything up.
Since my problem is exactly this:
https://unix.stackexchange.com/questions/298027/restart-systemd-service-when-output-is-no-longer-generated
I've also followed the answers here.
The problem with the solution: after 7 hours of runtime, the program stuck. No output generated, systemd didn't restart it.
in my_service.service are both suggested mandatory entries
everything else is correct
WatchdogSec=30
Restart=on-watchdog
Can I manually make my Rust program communicate with systemd? And if yes - how? I'd love to make it notify systemd at particular lines periodically.
The docs couldn't be more minimal:
https://docs.rs/systemd/latest/systemd/daemon/constant.STATE_WATCHDOG.html
I don't understand a single thing..
Another example crate libsystemd, there's 3 search results for WatchDog and this one is the most relevant I guess.
https://docs.rs/libsystemd/latest/libsystemd/daemon/enum.NotifyState.html#variant.Watchdog
IDK how I am able to accomplish anything here. Do I just paste this line anywhere in the program that I want?
libsystemd::daemon::NotifyState
how will it know the PID?
In any case: each of those packages has multiple methods, and my program hangs after anywhere from 1-24 hours, trial and error might take weeks.
How can I make my Rust program communicate to the systemd from inside threads, or if impossible - just manually set it up and ensure the WatchDog receives the signal as I want it? What's the line of code for sending a single notification from Rust program to systemd?
As mentioned above the go-to logic is simple: if no print output, restart the program.
You have to send the message somehow. By looking for functions that use the NotifyState I found both systemd::daemon::notify and libsystemd::daemon::notify either of which will do.
For example:
use systemd::daemon::{notify, STATE_WATCHDOG};
notify(false, [(STATE_WATCHDOG, "1")].iter()).unrwap();

rust performance in IDE and command line

I am a beginner of rust. I wrote a project with one main.rs and two module files. The dev environment is CLion+Intellij Rust plugin on MacOS 11.1. The program is a simple CPU-intensive computation task. To measure its performance, I used following method:
let timer = Instant::now();
task(); // the main function of the task
println!("{:.2?}", timer.elapsed());
When I ran the program in CLion's IDE, it prints a running duration of like 500~700µs.
However, if I ran the program (~project/target/debug/project) from command line in Mac Terminal, it prints 3~7ms. That's a difference one magnitude, which really confused me.
How to explain this difference? And any advice to improve the performance in command line? Thanks for any comments.
run
$cargo build --release
and execute the binary that will be created in
~project/target/release/project
and compare with that instead.
Also, assuming that you're doing this already, but make sure to measure things many times and average the results; your computer is doing a whole lot of other things at the same time, and one task could be interrupted at any time.
I think I got the answer. I have misstated the problem. I was not running the program in MacOS's terminal actually, but in CLion's Terminal window, which I thought it is equivalent to the OS's terminal - but it turns out to be not now. If I run the debug version in real OS's terminal, it prints same performance (500~700µs). And I also tried a release version, it prints like 20~40µs. This is what I expected.

why the multiprocessing stops

I have followed the code in the link multiprocessing.Pool() slower than just using ordinary functions to write a multi process program, but I find when the length of data in mainwordlist is relatively large, the code can't work. (you can try by setting xrange(50) to xrange(1000) in the code)
Actually, the terminal interface shows that the code is still running, however, the process in top command is gone, can anyone tell me why? any comment will be appreciated. thank you!
I find the following link http://eli.thegreenplace.net/2012/01/16/python-parallelizing-cpu-bound-tasks-with-multiprocessing and reorganize my code. Both of them start from same method, but I avoid above problem though I still don't know why. Anyway, it works.

When running a shell script with loops, operation just stops

NOTICE: Feedback on how the question can be improved would be great as I am still learning, I understand there is no code because I am confident it does not need fixing. I have researched online a great deal and cannot seem to find the answer to my question. My script works as it should when I change the parameters to produce less outputs so I know it works just fine. I have debugged the script and got no errors. When my parameters are changed to produce more outputs and the script runs for hours then it stops. My goal for the question below is to determine if linux will timeout a process running over time (or something related) and, if, how it can be resolved.
I am running a shell script that has several for loops which does the following:
- Goes through existing files and copies data into a newly saved/named file
- Makes changes to the data in each file
- Submits these files (which number in the thousands) to another system
The script is very basic (beginner here) but so long as I don't give it too much to generate, it works as it should. However if I want it to loop through all possible cases which means I will generates 10's of thousands of files, then after a certain amount of time the shell script just stops running.
I have more than enough hard drive storage to support all the files being created. One thing to note however is that during the part where files are being submitted, if the machine they are submitted to is full at that moment in time, the shell script I'm running will have to pause where it is and wait for the other machine to clear. This process works for a certain amount of time but eventually the shell script stops running and won't continue.
Is there a way to make it continue or prevent it from stopping? I typed control + Z to suspend the script and then fg to resume but it still does nothing. I check the status by typing ls -la to see if the file size is increasing and it is not although top/ps says the script is still running.
Assuming that you are using 'Bash' for your script - most likely, you are running out of 'system resources' for your shell session. Also most likely, the manner in which your script works is causing the issue. Without seeing your script it will be difficult to provide additional guidance, however, you can check several items at the 'system level' that may assist you, i.e.
review system logs for errors about your process or about 'system resources'
check your docs: man ulimit (or 'man bash' and search for 'ulimit')
consider removing 'deep nesting' (if present); instead, create work sets where step one builds the 'data' needed for the next step, i.e. if possible, instead of:
step 1 (all files) ## guessing this is what you are doing
step 2 (all files)
step 3 (all files
Try each step for each file - Something like:
for MY_FILE in ${FILE_LIST}
do
step_1
step_2
step_3
done
:)
Dale

What could cause an executable, called by a powershell script, to hang when it exits

I'm debugging a particularly strange problem...
As a part of my team's test suite, we run a powershell script that calls an executable I wrote in C#.
Every blue-mooned Tuesday, the executable will hang indefinitely until we kill the process. Most days it works just fine, and I haven't gotten it to repro.
The curious part is that this exe hangs after it's done doing all it's work. It's output the last line of data and the main thread is exiting. There's no multithreading in this process, and CPU is at 0% and thread count is 1.
All I/O (other than console writes) is done earlier in the execution, and there's no exception catching anywhere, so if something throws we should see it.
I don't need a definitive "this is the issue," but I have no idea what could cause this behavior. If you could respond with any theories on why this would be happening (no matter how far fetched) that'd be great.
Version info
OS: Windows 2008 R2
Powershell: v2 (comes with R2)
.NET: v4
Heh, this is worth a shot. Got
Console.ReadLine()
anywhere at the end of some line of logic?
I've got a behaviour like that on one of my "C" console program. It was well working started via "CMD.EXE" but when I use it via "POWERSHELL.EXE" it hang (systematicaly) at the end of exécution.
In this code, there are keyboard pooling loop (while (! _kbhit()), and at the moment I solve the problem by consuming (getch()) the keydown that fired the last loop. I don't understand exactly why.
In the Powershell script the result of the exe file is affected to a var.

Resources