Statistics collection related values do not increase in OMNeT++ - omnet++

In order to measure the packet transmission/reception count, I declared a scalar variable and wrote a function related to record. It looks like this:
A.h
class VEINS_API A : public DemoBaseApplLayer
{
private:
long StaticsFrsaPacketCount;
cOutVector frsaPacketCountVector;
...
}
A.cc
void A::initialize(int stage)
{
DemoBaseApplLayer::initialize(stage);
if(stage == 0)
{
StaticsFrsaPacketCount = 0;
frsaPacketCountVector.setName("fR_SA packet count");
...
}
}
void A::finish()
{
recordScalar("fR_SA Packet", StaticsFrsaPacketCount);
...
}
void A::handleSelfMsg(cMessage* msg)
{
switch(msg -> getKind())
{
case SEND_FRSA_EVT:
{
...
StaticsFrsaPacketCount++;
frsaPacketCountVector.record(StaticsFrsaPacketCount);
...
sendDelayedDown(wsm, uniform(0.01, 0.50));
}
...
}
}
I wrote the code by referring to the statistics written in the official OMNeT++ Tictoc tutorial. However, the result of the scalar value through the generated .anf file after the simulation is finished is as shown in the image below.
In other words, it seems that the value is incremented 1 time and not incremented after that. What is the cause?

(this part) of your code looks fine. The most likely reason why you have 1 in the result because really just one packet was sent. The statistics are showing what is actually happening. If you expect several packets to be sent, I suggest to start the app in Qtenv and step over the simulation and make sure that it works as you expect.

Related

Proteus always error at certain time (in this case 1.75 sec)

I recently using FreeRTOS for college project, but somehow my proteus always had this fatal error (every time its difference error but always fatal error, sometime violation module DSIM.dll, sometime other .dll(s)). At first I thought it has something to do with my code, so I try to use another example code (simple template from the internet that does blinking LED, nothing complex) but its still error at the exact 1.75 sec even though at that guy's demo works splendidly. I think it has to do with xTaskDelay cause when I commented the delay line the tasks (its singular task I suppose cause the only running task is only the one with the higher priority) the program works. Thanks in advance
#include <Arduino_FreeRTOS.h>
void setup()
//Initialize the Serial Monitor with 9600 baud rate
{
Serial.begin(9600);
Serial.println(F("In Setup function"));
//Set the digital pins 8 to 11 as digital output pins
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
//Create three tasks with labels Task1, Task2 and Task3 and assign the priority as 1, 2 and 3 respectively.
//We also create the fourth task labeled as IdelTask when there is no task in
//operation and it has the highest priority.
xTaskCreate(MyTask1, "Task1", 100, NULL, 1, NULL);
xTaskCreate(MyTask2, "Task2", 100, NULL, 2, NULL);
xTaskCreate(MyTask3, "Task3", 100, NULL, 3, NULL);
xTaskCreate(MyIdleTask, "IdleTask", 100, NULL, 0, NULL);}
//We can change the priority of task according to our desire by changing the numeric’s //between NULL texts.
void loop()
{
//There is no instruction in the loop section of the code.
// Because each task executes on interrupt after specified time
}
//The following function is Task1. We display the task label on Serial monitor.
static void MyTask1(void* pvParameters)
{
while(1)
{
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
Serial.println(F("Task1"));
vTaskDelay(100/portTICK_PERIOD_MS);
}
}
//Similarly this is task 2
static void MyTask2(void* pvParameters)
{
while(1)
{ digitalWrite(8,LOW);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
Serial.println(F("Task2"));
vTaskDelay(110/portTICK_PERIOD_MS);
}
}
//Similarly this is task 3
static void MyTask3(void* pvParameters)
{
while(1)
{
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
Serial.println(F("Task3"));
vTaskDelay(120/portTICK_PERIOD_MS);
}
}
//This is the idle task which has the lowest priority and calls when no task is running.
static void MyIdleTask(void* pvParameters)
{
while(1)
{
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
Serial.println(F("Idle state"));
delay(50);
}
}
Source for the code
it turns out the Proteus app is kinda corrupted so I went to google to download those .dll(s) files

Spring batch reader - How to avoid returning a list of objects

So I have a spring batch app that I have getting a list of ids that it then uses 'read()' on to get 1 to many results back. The issue is, I have no control over how many results I get back for each id meaning that my chunking is spotty at best. Is there a suggested way to avoid spikes in memory/cpu? An example is below:
#Before
public void getIds() {
*getListOfIds* //Usually around 10,000 or so
}
#Override
public AccountObject read() {
if(list of ids havent all been used) {
List<AccountObject> myAccounts = myService.getAccounts(id);
return myAccounts; //This could be anywhere from 1 result to 100,000 results.
} else {
return null;
}
}
So the myAccounts object above could be small or huge. This causes chunking to basically be useless because at the moment I am chunking by List. I'd really rather chunk by straight AccountObject but don't see an easy way to do this.
Is there a class, strategy, etc. that I am missing here?

RadiusNetworks iBeacon didRangeBeaconsInRegion return 0 beacons

I am trying to detect iBeacons with a specific UUID and Major. The didRangeBeaconsInRegion is being called but the Beacon collection it returns has 0 entries.
The below is my code (abridged a bit)
private static final String BEACON_UUID = "F8AD3E82-0D91-4D9B-B5C7-7324744B2026";
private static final int BEACON_MAJOR = 36582;
#Override
public void onIBeaconServiceConnect() {
iBeaconManager.setRangeNotifier(new RangeNotifier() {
#Override
public void didRangeBeaconsInRegion(Collection<IBeacon> iBeacons, Region region) {
if (iBeacons.size() > 0) {
IBeacon thisBeacon = iBeacons.iterator().next();
}
}
});
try {
iBeaconManager.startRangingBeaconsInRegion(new Region("myUniqueID", BEACON_UUID, BEACON_MAJOR ,null));
} catch (RemoteException e) {
e.printStackTrace();
}
}
I am assuming I am doing my binding correctly as the didRangeBeaconsInRegion(..) is being called successfully.
I have used RadiusNetwork's own application to detected the beacons and that works fine and I can see them all so it is not seem to be an issue with Bluetooth on my device
A couple of tips:
Double check that your BEACON_UUID and BEACON_MAJOR are correct for the beacon that is transmitting. For testing, try setting both of these to null temporarily until you get it working, then you can set them back to the values you have.
It is normal for the iBeacons.size() to be zero sometimes if a beacon did not happen to be detected in a given cycle. But it should not always be of size zero. I'm not sure how you are testing, but try adding a Log.d(TAG, "Number of beacons detected: "+iBeacons.size()); and let it run to see if you ever get a non-zero number.
I suggest to check the uuid , major and minor values of your beacons and make them match with the region u want.
didRangeBeaconsInRegion should return an array af beacons.
You can use the "beecon" app to update easily the values.
Hope this can help you.
Regards.

(Twitter) Storm's Window On Aggregation

I'm playing around with Storm, and I'm wondering where Storm specifies (if possible) the (tumbling/sliding) window size upon an aggregation. E.g. If we want to find the trending topics for the previous hour on Twitter. How do we specify that a bolt should return results for every hour? Is this done programatically inside each bolt? Or is it some way to specify a "window" ?
Disclaimer: I wrote the Trending Topics with Storm article referenced by gakhov in his answer above.
I'd say the best practice is to use the so-called tick tuples in Storm 0.8+. With these you can configure your own spouts/bolts to be notified at certain time intervals (say, every ten seconds or every minute).
Here's a simple example that configures the component in question to receive tick tuples every ten seconds:
// in your spout/bolt
#Override
public Map<String, Object> getComponentConfiguration() {
Config conf = new Config();
int tickFrequencyInSeconds = 10;
conf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, tickFrequencyInSeconds);
return conf;
}
You can then use a conditional switch in your spout/bolt's execute() method to distinguish "normal" incoming tuples from the special tick tuples. For instance:
// in your spout/bolt
#Override
public void execute(Tuple tuple) {
if (isTickTuple(tuple)) {
// now you can trigger e.g. a periodic activity
}
else {
// do something with the normal tuple
}
}
private static boolean isTickTuple(Tuple tuple) {
return tuple.getSourceComponent().equals(Constants.SYSTEM_COMPONENT_ID)
&& tuple.getSourceStreamId().equals(Constants.SYSTEM_TICK_STREAM_ID);
}
Again, I wrote a pretty detailed blog post about doing this in Storm a few days ago as gakhov pointed out (shameless plug!).
Add a new spout with parallelism degree of 1, and have it emit an empty signal and then Utils.sleep until next time (all done in nextTuple). Then, link all relevant bolts to that spout using all-grouping, so all of their instances will receive that same signal.

Does GCC LTO perform cross-file dead code elimination?

Say I have a function
void do_something() {
//....
#ifdef FEATURE_X
feature_x();
#endif
//....
}
I can compile and run this with no problems; if I want the feature I can pass -D FEATURE_X and it works.
However, what if I would like to put do_something into another file (And not have to recompile that file as well each time I decide to change the option). If it was in the same file, I assume that
const int FEATURE_X=0;
void do_something() {
//....
if(FEATURE_X) {
feature_x();
}
//....
}
will use dead code elimination properly, eliminating the call. If I put this in another file, without LTO,
extern const int FEATURE_X;
void do_something() {
//....
if(FEATURE_X) {
feature_x();
}
//....
}
It will not remove the code (It has no way of knowing). So, with link time optimization enabled, can the compiler detect the value of FEATURE_X at link time, determine if the code is used or not, and remove it if appropriate?
GCC does cross module unreachable function removal, but it will not be able to determine the code is dead in your last testcase, because the constant value of FEATURE_X will be determined too late.
If you will use -D way or put your const int FEATURE_X=0; into every module then yes, the code will be eliminated.

Resources