Need help understanding how Eclipse IProgressMonitor works - eclipse-plugin

I am using Eclipse IProgressMonitor to monitor the progress of a task. There are four steps, and I write the following code.
int totalWork = 100;
String message = "Compiling " + inputFile.getName();
monitor.beginTask(message, totalWork);
monitor.subTask(message + " - first pass");
...// Work
monitor.worked(25);
if (monitor.isCanceled())
return;
monitor.subTask(message + " - invoking");
...// work
monitor.worked(25);
if (monitor.isCanceled())
return;
monitor.subTask(message + " - second pass");
...// Work
monitor.worked(25);
if (monitor.isCanceled())
return;
monitor.subTask(message + " - final pass");
...// Work
monitor.worked(25);
if (monitor.isCanceled())
return;
monitor.done();
As I have total work 100, and each step increase it by 25, I am hoping to see the progress bar show 25% 50% etc. and increase. However the progress bar stops at some number (33%, 38%, 20%, kind of random on different machines) and does not change until the entire job is done. The task name changes though. I read the JavaDoc for this API and follow the way it suggests (I think). Can anyone help tell me where I went wrong?

Related

WorkManger doesn't trigger after manually stopped- Kotlin

I want to use workMager to do some work every 15min,at the same time I want to stop workManger when I clicked on the button "StopThread" below is my Code:
val workManager = WorkManager.getInstance(applicationContext)
val workRequest = PeriodicWorkRequest.Builder(
RandomNumberGeneratorWorker::class.java,
15,
TimeUnit.MINUTES
).addTag("API_Worker")
.build()
binding.buttonThreadStarter.setOnClickListener {
workManager.enqueue(workRequest)
}
binding.buttonStopthread.setOnClickListener {
workManager.cancelAllWorkByTag("API_Worker")
}
And this is the RandomNumberGeneratorWorker
class RandomNumberGeneratorWorker(
context: Context,
params: WorkerParameters
) :
Worker(context, params) {
private val MIN = 0
private val MAX = 100
private var mRandomNumber = 0
override fun doWork(): Result {
Log.d("worker_info","Job Started")
startRandomNumberGenerator();
return Result.success();
}
override fun onStopped() {
super.onStopped()
Log.i("worker_info", "Worker has been cancelled")
}
private fun startRandomNumberGenerator() {
Log.d("worker_info","startRandomNumberGenerator triggered")
var i = 0
while (i < 100 && !isStopped) {
try {
Thread.sleep(1000)
mRandomNumber = (Math.random() * (MAX - MIN + 1)).toInt() + MIN
Log.i(
"worker_info",
"Thread id: " + Thread.currentThread().id + ", Random Number: " + mRandomNumber
)
i++
} catch (e: InterruptedException) {
Log.i("worker_info", "Thread Interrupted")
}
}
}
}
The issue that I'm facing is when I stopped the workManger it didn't work again when I clicked on buttonThreadStarter
I did a little research and I found that I can start-stop-start..etc workManger with the code below :
val workRequest = OneTimeWorkRequest.from(RandomNumberGeneratorWorker::class.java)
binding.buttonThreadStarter.setOnClickListener {
workManager.beginUniqueWork("WorkerName",ExistingWorkPolicy.REPLACE,workRequest)
}
binding.buttonStopthread.setOnClickListener {
workManager.cancelAllWork()
}
but as you can see it's working when I used OneTimeWorkRequest and with that, I can't repeat the work every 15 mins , Any suggestion in how to resolve this issue
WorkManager is not designed for periodic works with exact timing. In reality, the works "are not even periodic".
As you can see here from the logs:
https://developer.android.com/topic/libraries/architecture/workmanager/how-to/debugging#use-alb-shell0dumpsys-jobscheduler
WorkManager delegates to the JobScheduler. JS jobs work in a way that you have a number of explicit(you set them) and implicit(set by the system) constraints and after all of them are satisfied - the job starts.
When you have a period there is an extra constraint - TIMING_DELAY. So if your 15min pass - this doesn't mean in no way that the job will be executed. There might be, and be sure that there will be other constraints. That is the case because WM is designed for resource optimization and it will ensure that the work will finish at some point, even on device restart. But it is not designed to be exact. It is quite the opposite.
And after all the constraints are satisfied - it might take a day, the job is no longer needed and a new job is created with again your 15min constraint - TIMING_DELAY. And the process starts again.
Also - when you say "doesn't trigger" - please, check why. Try to check the debug output from the JS and see if there is work at all. If there is - check what constraints are not satisfied.
But long story short - "every 15min" is not something for WorkManager. Normally you should use AlaramManager for exact timing, but with such a short interval you should try to consider using a Service.
Also, it is dangerous to call: cancelAllWork(). You might break the code of some library in your app. You should better use tags and cancel by tag.

How to work around ImageJ run("HSB stack") error/ bug?

I am working on a macro for ImageJ. The goal is to take colour scans with several seeds on them and crop around the seeds to get several equally sized images with one seed on each.
This is the basic idea for the macro: prompt to select folder with scans (info about the seed is in the name of the image) > threshold to select seeds > crop around each seed on the original image > save all of the cropped images in a folder (name of the cropped images still containing the information of the name of the original image)
When I run the code below, I get an error for line 31: run("HSB stack");
The error informs me about supported conversions and shows that in order to run this command I need to start with an RGB image. However, according to Fiji > Image > Type, my images are RGBs. A coding error in that part also seems unlikely since it was written with the recording function in ImageJ.
Error message
According to what I found for the error, this seems to concern a recurring bug in the software, specific to the commands run("HSB stack") and run("RGB stack") in macros.
We have tried running this on ImageJ 2.3.0/1.53s as well as 1.53q on MacOS and Windows and always got the same problem.
If it is not a software problem, where is the error? Or if it is, do you have any suggestions for workarounds or a different program that could perform the same job?
The images I am working with are colour scans, 600dpi, white background with between 1 and 90 seeds on each scan. They are large tiff images (107.4 MB) but look like this:
Example scan image
I am not sure if it is helpful, but the code is below. There are probably still errors in the latter part that I could not yet get to because I can't get past the problem in line 31.
// Directory
dir=getDirectory("Choose a data folder");
list = getFileList(dir);
processed_dir_name = dir + "Cropped" + File.separator;
print(processed_dir_name);
File.makeDirectory(processed_dir_name);
// Batch
for (i=0; j<list.length; i++) {
print(i + ":" + dir+list[i]};
// Open images
run("Bio-Formats Importer", "open=" + dir+list[i] + "color_mode=Default view =Hyperstack");
// Crop edge, set general cropping parameters, scale
makeRectangle(108, 60, 4908, 6888);
run("Crop");
main = getTitle():
default_crop_width = 350;
default_crop_height = 350;
run("Set Scale...", "distance=600 known=25.4 unit=mm global");
//Thresholding
run("Color Threshold...");
//Color Thresholder 2.3.0/1.53q
// Autogenerated macro, single images only!
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("HSB stack");
run("Convert Stack to images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=0;
max[0]=255;
filter[0]="pass";
min[1]=0;
max[1]=255;
filter[1]="pass";
min[2]=0;
max[2]=193;
filter[2]="pass";
for (i=0;j<3;i++){
selectWindow(""+i);
The problem lies in the fact that your image is a hyperstack, and the color thresholding doesn't know how to work with that.
There are a few options you could try: Open the image as an 8-bit RGB, e.g. via open(dir+list[i]); or split the channels of the hyperstack and threshold each separately. Based on your sample image, I assume the first option makes more sense.
The following is an edited version of your code that works for the sample that you've provided:
// Directory
dir=getDirectory("Choose a data folder");
list = getFileList(dir);
processed_dir_name = dir + "Cropped" + File.separator;
print(processed_dir_name);
File.makeDirectory(processed_dir_name);
// Batch
for (i=0; i<list.length; i++)
{
if (!File.isDirectory(dir+list[i])) // Ignore directories such as processed_dir_name
{
print(i + ":" + dir+list[i]);
// Open images
open(dir+list[i]);
// Crop edge, set general cropping parameters, scale
makeRectangle(108, 60, 4908, 6888);
run("Crop");
main = getTitle();
default_crop_width = 350;
default_crop_height = 350;
run("Set Scale...", "distance=600 known=25.4 unit=mm global");
//Thresholding
//run("Color Threshold...");
//Color Thresholder 2.3.0/1.53q
// Autogenerated macro, single images only!
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=0;
max[0]=255;
filter[0]="pass";
min[1]=0;
max[1]=255;
filter[1]="pass";
min[2]=0;
max[2]=193;
filter[2]="pass";
for (j=0;j<3;j++){
selectWindow(""+j);
}
}
}

Cannot create menu handler from Discord.NET Guide for Menus

So I am trying to get a menu set up for a discord bot I am working on. I am following the example provided in Discord.Net's documentation, but I am having trouble getting it to actually work.
//Command to test the menu functionality found in Discord.NET
[Command("MenuTest")]
public async Task Spawn()
{
var menuBuilder = new SelectMenuBuilder()
.WithPlaceholder("Please select a manufacturer...")
.WithCustomId("menu-1")
.WithMinValues(1)
.WithMaxValues(1)
.AddOption("Alas!", "Alas!", "Increased Damage")
.AddOption("Skuldugger", "Skuldugger", "Overheat + Increased Damage")
.AddOption("Dahlia", "Dahlia", "Additional hit each attack + Increased ACC")
.AddOption("Blackpowder", "Blackpowder", "Increased ACC + Highly Increased Crit Damage")
.AddOption("Malefactor", "Malefactor", "Garunteed Elemental Roll + Reduced Damage at lower rarites")
.AddOption("Hyperius", "Hyperius", "Increased Accuracy + Reduced Overall Damage")
.AddOption("Feriore", "Feriore", "Less Accuracy + Trown/Explosive Reload")
.AddOption("Torgue", "Torgue", "Less Accuracy + Splash Damage")
.AddOption("Stoker", "Stoker", "Less Accuracy + Extra Attack Action");
var builder = new ComponentBuilder()
.WithSelectMenu(menuBuilder);
await ReplyAsync("You rolled high! You get to pick your manufacturer!", components: builder.Build());
client.SelectMenuExecuted += MyMenuHandler;
}
public async Task MyMenuHandler(SocketMessageComponent arg)
{
var text = string.Join(", ", arg.Data.Values);
await arg.RespondAsync($"You have selected {text}");
}
I know that it has something to do with this line specifically
client.SelectMenuExecuted += MyMenuHandler;
I am unsure of what to substitute for client. If someone could help me figure that out, that would be greatly appreciated.

How to trace the data that is going through caches and DRAM memory in gem5?

--exec-flags Cache,DRAM show addresses and sizes, but sometimes I just need to see the actual data being sent.
I know that this might produce large logs, but that is fine as I'm restricting my area of interest well via --debug-start and -m/--debug-break (used a hack here to just finish the simulation at a tick).
https://gem5-users.gem5.narkive.com/VUAhxc7J/how-can-i-trace-data-of-cache mentions using CommMonitor. It is a bit annoying to have to modify the run script, but that's also a valid solution. It would be good to give a minimal example here that patches say se.py to add it and how to view its output.
I also have DPRINTF patch which seems to help and I'll try to publish. Here's a sketch:
## -385,14 +386,17 ## void
Packet::print(std::ostream &o, const int verbosity,
const std::string &prefix) const
{
- ccprintf(o, "%s%s [%x:%x]%s%s%s%s%s%s", prefix, cmdString(),
+ ccprintf(o, "%s%s [%x:%x]%s%s%s%s%s%s D=%llx", prefix, cmdString(),
getAddr(), getAddr() + getSize() - 1,
req->isSecure() ? " (s)" : "",
req->isInstFetch() ? " IF" : "",
req->isUncacheable() ? " UC" : "",
isExpressSnoop() ? " ES" : "",
req->isToPOC() ? " PoC" : "",
- req->isToPOU() ? " PoU" : "");
+ req->isToPOU() ? " PoU" : "",
+ flags.isSet(STATIC_DATA|DYNAMIC_DATA) ?
+ mem2hex_string(getConstPtr<const char>(), getSize())
+ : "");
}
and then implement mem2hex_string as shown at: C++ read binary file and convert to hex
Edit: I managed to add a CommMonitor by hacking se.py, but I could not see any memory value output in any files nor in its code, the only thing I could see was new stats being added, so not sure that can help at all.

noflo 0.5.13 spreadsheet example broken?

I am new to noflo and looking at examples in order to explore it. The spreadsheet example looked interesting but I couldn't make it run. First, it takes some time and manual debugging to identify missing components, not a big deal and I believe will be improved in the future, for now the error message I get is
return process.component.outPorts[port].attach(socket);
^
TypeError: undefined is not a function
Apparently, before this isAddressable() was also undefined. Checked with this SO issue but I don't have any noflo 0.4 as a dependency anywhere. Spent some time to debug it but seemingly stuck at it, decided to post to SO.
The question is, what are the correct steps to run the spreadsheet example?
For reproduction, here is what I have done:
0) install the following components
noflo-adapters
noflo-core
noflo-couchdb
noflo-filesystem
noflo-groups
noflo-objects
noflo-packets
noflo-strings
noflo-tika
noflo-xml
i) edit spreadsheet/parse.fbp, because first error was
throw new Error("No outport '" + port + "' defined in process " + proc
^
Error: No outport 'error' defined in process Read (Read() ERROR -> IN Display())
apparently couchdb ReadDocument component does not provide Error outport. therefore replaced ReadDocument with ReadFile.
18c18
< 'tika-app-0.9.jar' -> TIKA Read(ReadDocument)
---
> 'tika-app-0.9.jar' -> TIKA Read(ReadFile)
ii) at this point, received the following:
if (process.component.outPorts[port].isAddressable()) {
^
TypeError: undefined is not a function
and improvised a stunt by checking if isAddressable is defined at this location of code:
## -259,9 +261,11 ##
throw new Error("No outport '" + port + "' defined in process " + process.id + " (" + (socket.getId()) + ")");
return;
}
- if (process.component.outPorts[port].isAddressable()) {
+ if (process.component.outPorts[port].isAddressable && process.component.outPorts[port].isAddressable()) {
return process.component.outPorts[port].attach(socket, index);
}
return process.component.outPorts[port].attach(socket);
};
and either way fails. Again, the question is What are the correct steps to run the spreadsheet example?
Thanks in advance.