Mani
Mani

Reputation: 231

How to calculate the time taken to load module in gwt?

I am using a custom gridview widget and large amount of data(say 1000 rows) assigned to it.I know that it will take more time.And I want to know how much time it exactly taking to load the grid.

<!doctype html>
<html>
  <head>
  <link rel="stylesheet" href="Custom.css">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>CustomWidget</title>
    <script type="text/javascript" language="javascript" src="mywidget/mywidget.nocache.js">
    function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout(function(){startTime()},500);
}

function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}
    </script>
  </head>

  <body onload="startTime()">
    <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
<div id="txt"></div>
  </body>
</html>

But not able display time..and its working when executing as single html page.

Upvotes: 2

Views: 217

Answers (3)

Mani
Mani

Reputation: 231

Another two ways along with @Braj answer

1.Using Speed Tracer you are able to get a better picture of where time is being spent in your application. This includes problems caused by:

  • Javascript parsing and execution
  • Layout
  • CSS style recalculation and selector matching
  • DOM Event handling
  • Network resource loading
  • Timer fires
  • XMLHttpRequest callbacks
  • Painting

Fallow this link Speed Tracer and to Crome(click on free) ,works with Crome only

2.You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page With this we can get how much time each function taken , how many times is called and % of total time

but its works with fire fox only.

Fallow this link FireBug.Click on Console and enable Profile to see the performance of each function.

Sometimes you may get obfuscated function names.To avoid this project>Google>GWT Compile>Select output style as Pretty

Upvotes: 2

Andrei Volgin
Andrei Volgin

Reputation: 41089

Open console in your browser. Click on the Network tab. Reload the page. See how long it takes to load each resource.

Upvotes: 1

Braj
Braj

Reputation: 46841

Try this one

Steps to follow:

  • create a hidden div that have a information about current time before downloading nocache.js
  • Once nocache.js is loaded it will call EntryPoint#onModuleLoad() method of your entry point class.
  • Compare the time to get the time taken

HTML/JSP:

<body>
    <div id="timeinfo" style="visibility: hidden;"></div>

    <script type="text/javascript">
        var today = new Date();

        document.getElementById("timeinfo").innerHTML = today.getTime();
    </script>

    <script type="text/javascript" src="mywidget/mywidget.nocache.js"></script>
</body>

Entry point class:

public class MyWidget implements EntryPoint {

    public void onModuleLoad() {
        RootPanel timeinfo = RootPanel.get("timeinfo");

        long startTime = Long.valueOf(timeinfo.getElement().getInnerHTML());
        long endTime = System.currentTimeMillis();
        System.out.println(new Date(startTime));
        System.out.println(new Date(endTime));
        System.out.println("Total time taken=" + (endTime - startTime) + " ms.");

        RootPanel.getBodyElement().removeChild(timeinfo.getElement());
        ...
    }
}

output:

    Tue Apr 22 16:55:49 IST 2014
    Tue Apr 22 16:56:03 IST 2014
    Total time taken=14479 ms.

Upvotes: 1

Related Questions