Is it safe to use performance.now() to measure page load time in GWT? - gwt

I need to measure the time required for my GWT application to load.
I can't use GWT Lightweight Metrics because of external framework usage (I can't modify bootstrap html page).
Navigation Timing doesn't work for GWT because initialization of GWT widgets doesn't depend on window.load.
So, is it safe to use performance.now() method to get the time from PerformanceTiming.navigationStart event?
Specs says that:
The now() method must return a DOMHighResTimeStamp representing the time in milliseconds from the time origin to the occurrence of the call to the Performance.now method.
I can't understand time origin definition. Does it always return the time from the moment when the user requests a page with my application?

I haven't found answer to my original question. It seems like performance.now() isn't suitable for measuring page loading time.
I have used explicit approach described here.
The code is something like this.
public static long getTimeFromPageLoadStart() {
long navigationStart = (long) getNavigationStart();
return new Date().getTime() - navigationStart;
}
private static native double getNavigationStart()/*-{
return performance.timing.navigationStart;
}-*/;

Related

How to find which rule take long time to finish

We have around 15,000 rules running and it takes 2 hours to complete. I would like to figure out which rule takes long time. Its not possible for me to go to each rule and log it. So I implemented the AgendaEventListener and override afterMatchFired() method. I know which rules fired. But how do I know which rule took long time.
If you want the time to execute the match, update your listener to implement the beforeMatchFired method as well. When the beforeMatchFired method triggers, start the timer. When the same rule's afterMatchFired triggers, stop the timer and log it. You'll want to also track match cancelled to discard unnecessary timers.
Remember to track this on a per-rule basis -- you'll need to identify each rule uniquely (package + name should be specific enough). Note that this exercise will get a little complicated if you have rules that extend other rules.
Rather that doing your own profile, you should take a look at the new drools-metric module that solves exactly your problem.
From the manual
Use the drools-metric module to identify the obstruction in your rules
You can use the drools-metric module to identify slow rules especially
when you process many rules. The drools-metric module can also assist
in analyzing the Drools engine performance. Note that the
drools-metric module is not for production environment use. However,
you can perform the analysis in your test environment.
To analyze the Drools engine performance using drools-metric, add
drools-metric to your project dependencies and enable trace logging
for org.drools.metric.util.MetricLogUtils , as shown in the following
example:
Try RulesChronoAgendaEventListener and RulesChronoChartRecorder from da-utils
Both gives you real-time JMX monitoring, showing average and max execution time for each rule. Second gather jfreechart data to show you values in time, which gives you perfect sense of overall performance and 'problematic' cases.
Register session listener
AgendaEventListener rulesChrono = new RulesChronoChartRecorder().withMaxThreshold(500).schedule();
session.addEventListener(rulesChrono);
Print per rule statistic
StringBuilder sb = new StringBuilder();
rulesChrono.getPerfStat().values()
.forEach(s -> sb.append(format("%n%s - min: %.2f avg: %.2f max: %.2f activations: %d", s.getDomain(), s.getMinTimeMs(), s.getAvgTimeMs(), s.getMaxTimeMs(), s.getLeapsCount())));
System.out.println(sb.toString());
Draw charts
Map<String, TimeSeries> rulesMaxChart = rulesChrono.getRulesMaxChart();
Map<String, TimeSeries> rulesMinChart = rulesChrono.getRulesMinChart();
rulesChrono.getRulesAvgChart().entrySet()
.forEach(e -> ChartUtils.pngChart(format("charts/%s.png", e.getKey()), 1024, 500, e.getValue(), Color.black, rulesMaxChart.get(e.getKey()), Color.lightGray, rulesMinChart.get(e.getKey()), Color.lightGray));
For the second you'll need jfreechart dependency

Rest Server with Z1 Websense

Hi Stackover'followers :). I'm very much new to Stackoverflow. Let me put forward a question I have regarding Instant Contiki. Anybody who has idea on Instant Contiki, zolertia motes, REST Server, is welcomed to resolve it out.
I could successfully work on the two different motes by considering 'z1-websense.c' and 'rest-server-example.c'.
But I want to get the result of 'z1-websense.c' which is the
temperature, by executing the 'rest-server-example.c'.
So, regarding this, there is something to be done in the 'rest-server-example.c' code, may be by calling a function for z1-websense.c, which I'm unable to crack it.
Please help me out. Thanks in advance.
the rest-engine app on Contiki let's you set up resources and handlers for methods called on them.
So, if I understood, you want to tweak the resource GET handlers in er-example-server to taylor onto the z1 mote, in particular a resource for the battery sensor and a resource for the temperature one.
If you take a look at z1-websense.c the values are retrieved and simply scaled (lines 66-79).
static int
get_battery(void)
{
return battery_sensor.value(0);
}
static int
get_temp(void)
{
return temperature_sensor.value(0);
}
static float get_mybatt(void){ return (float) ((get_battery()*2.500*2)/4096);}
static float get_mytemp(void){ return (float) (((get_temp()*2.500)/4096)-0.986)*282;}
Take that code and inject it into the battery and temperature resources you can find hereenter link description here and you are done.
So in the end you will have something like
file res-battery.c, line 60
float battery = ( battery_sensor.value(0) *2.500*2) /4096 ;
You should do similarly for the temperature and you are done.
Remember to deactivate all sensors/resources you are not interested in, since they would take precious memory.
I cannot test it right now, but this should work.

condition not working sometimes with gwt

I'm having a rare issue in my code, I have a method that makes a very simple validation based on a string variable:
private void showNextStep(String psCondition,String poStepName){
int liCurrentStep=Integer.valueOf(poStepName);
String lsNextTrueStep=moSteps[liCurrentStep][4];
String liNextFalseStep=moSteps[liCurrentStep][5];
if ("Yes".equals(psCondition)){
moFrmStepsContainer.getField(liNextFalseStep).hide();
moFrmStepsContainer.getField(lsNextTrueStep).show();
}else{
moFrmStepsContainer.getField(liNextFalseStep).show();
moFrmStepsContainer.getField(lsNextTrueStep).hide();
}
}
Now, here is the ticky part: if I execute the application without debugging mode, it does the validation right all the time, how ever if don't it always goes to the else block (or at least I think) I tried to use JS alerts (I have a class that calls JS methods) to debug manually and check the valors of the variables; the valors where all right and the validation was also good. This means that only debugging or putting alerts before at the beggining of the IF block it does the validation right, otherwise it always goes to the ELSE, what do you think it could be?
It might be worth mentioning this is a web application made in netbeans 6.9, using the framework GWT 2.1. This application runs in firefox 25.0.1
Thank you!
UPDATE
Here is the code of the event that calls my method
final ComboBoxItem loYesNo=new ComboBoxItem("cmbYesNo" + moSteps[liStepIndex][0],"");
loYesNo.setValueMap("Yes","No");
loYesNo.setVisible(false);
loYesNo.setAttribute("parent", liStepIndex);
loYesNo.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent poEvent){
String lsStepName=loYesNo.getName();
FormItem loItem=moFrmStepsContainer.getField(lsStepName);
String liStepNumber=String.valueOf(loItem.getAttributeAsInt("parent"));
showNextStep((String)poEvent.getItem().getValue(),liStepNumber);
}
});

Application not detecting input language changes via Text Service Framework DLL

OK, I have been at this for a while ...
I am trying to track when user changes input languages from Language Bar.
I have a Text Service DLL - modeled from MSDN and WinSDK samples - that registers fine, and I can use the interfaces ITfActiveLanguageProfileNotifySink & ITfLanguageProfileNotifySink and see those events just fine.
I also have finally realized that when I change languages these events occur for the application/process that currently has focus.
What I need to do is to simply have these events able to callback to my own application, when it has the focus. I know I am missing something.
Any help here is appreciated.
Thanks.
I did some double-checking, and you should be able to create a thread manager object without implementing ITextStoreACP so long as you don't call ITfThreadMgr::Activate.
So, the code should look like:
HRESULT hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
ITfThreadMgr* pThreadMgr(NULL);
hr = CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, (LPVOID*) &pThreadMgr);
if (SUCCEEDED(hr))
{
ITfSource *pSource;
hr = pThreadMgr->QueryInterface(IID_ITfSource, (LPVOID*)&pSource);
if(SUCCEEDED(hr))
{
hr = pSource->AdviseSink(IID_ITfActiveLanguageProfileNotifySink,
(ITfActiveLanguageProfileNotifySink*)this,
&m_dwCookie);
pSource->Release();
}
}
}
Alternatively, you can use ITfLanguageProfileNotifySink - this interface is driven from the ItfInputProcessorProfiles object instead of ItfThreadMgr. There's a sample of how to set it up on the MSDN page for ItfLanguageProfileNotifySink.
For both objects, you need to keep the source object (ITfThreadMgr or ITfInputProcessorProfiles) as well as the sink object (what you implement) alive until your application exits.
Before your application exits, you need to remove the sink from the source object using ITfSource::UnadviseSink, and then release the source object (using Release). (You don't need to keep the ItfSource interface alive for the life of your application, though.)

How can i get http request and response timings in perl selenium webdriver for performance testing

I am looking for the page loading times in Selenium Remote Driver. I am using perl.
I have tried Firebug with NetExport, but how can i sync these results with selenium tests?
I can get the time for each test case by adding timestamps before and after execution. But I want the client side time.
I don't want to use jmeter here.
There are pros and cons of checking performance at client side & Server side.
Client side: Almost accurate....but it doesn't consider the Page loading time and timing starts once the page is loaded completely.
Server Side: Easy to generate...but timings also include the network latency.
So selection among both criterion is purely on requirement basis.
Coming to the point of Client side notifying the timings...i would suggest you to go JavaScript way along with Selenium (C# & JavaScript code snippet)
IJavaScriptExecutor js = (IJavaScriptExecutor) driver;
js.ExecuteScript("SetTimefunction();");
// Your Automation Code goes Here
js.ExecuteScript("return CalculateTime();");
Here is how your JavaScript code in the page should look like:
//Global variable in your page for start time of execution.
var Start_Global_Time;
//Sets the start time of your execution
function SetTimefunction(){
Start_Global_Time=new Date();
}
//Calculate Difference between the Exec & Start Time
function CalculateTime(){
var Exec_end_time=new Date();
return Exec_end_time-Start_Global_Time;
}