/Tests/Manual/LoadTimeTest/AppController.j

http://github.com/cacaodev/cappuccino · Unknown · 83 lines · 63 code · 20 blank · 0 comment · 0 complexity · b90ad1146b672ee19d9364301c3c9a49 MD5 · raw file

  1. /*
  2. * AppController.j
  3. * LoadTimeTest
  4. *
  5. * Created by You on February 23, 2010.
  6. * Copyright 2010, Your Company All rights reserved.
  7. */
  8. @import <Foundation/CPObject.j>
  9. @implementation AppController : CPObject
  10. {
  11. }
  12. - (void)applicationDidFinishLaunching:(CPNotification)aNotification
  13. {
  14. var endLaunch = new Date();
  15. var data;
  16. if (window.location.search.length > 1)
  17. data = JSON.parse(decodeURIComponent(window.location.search.slice(1)))
  18. else
  19. data = [];
  20. data.push([endLoad - startLoad, endLaunch - endLoad]);
  21. if (data.length < 10)
  22. {
  23. // reload with data in the query string
  24. window.location.href = [window.location.protocol, "//", window.location.host, window.location.pathname, "?", encodeURIComponent(JSON.stringify(data))].join("");
  25. }
  26. else
  27. {
  28. var loadAvg = 0, loadStdev = 0, launchAvg = 0, launchStdev = 0;
  29. for (var i = 0; i < data.length; i++) {
  30. loadAvg += data[i][0];
  31. launchAvg += data[i][1];
  32. }
  33. loadAvg /= data.length;
  34. launchAvg /= data.length;
  35. for (var i = 0; i < data.length; i++) {
  36. loadStdev += POW(data[i][0] - loadAvg, 2);
  37. launchStdev += POW(data[i][1] - launchAvg, 2);
  38. }
  39. loadStdev = SQRT(loadStdev / data.length);
  40. launchStdev = SQRT(launchStdev / data.length);
  41. if (window.parent.BCOMM) {
  42. window.parent.BCOMM.finishTest({
  43. loadAvg : loadAvg,
  44. launchAvg : launchAvg,
  45. loadStdev : loadStdev,
  46. launchStdev : launchStdev
  47. });
  48. }
  49. var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
  50. contentView = [theWindow contentView];
  51. var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
  52. [label setStringValue:"load avg="+ROUND(loadAvg)+" (stdev="+ROUND(loadStdev)+"); launch avg="+ROUND(launchAvg)+" (stdev="+ROUND(launchStdev)+")"];
  53. [label setFont:[CPFont boldSystemFontOfSize:24.0]];
  54. [label sizeToFit];
  55. [label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
  56. [label setCenter:[contentView center]];
  57. [contentView addSubview:label];
  58. [theWindow orderFront:self];
  59. // Uncomment the following line to turn on the standard menu bar.
  60. //[CPMenu setMenuBarVisible:YES];
  61. }
  62. }
  63. @end