test_performance.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
32 var count = 0;
33 var t = null;
34 
35 function runTest () {
36 
37  var ITEMS_PER_JOB = 200;
38 
39  var library = createNewLibrary("test_metadatajob_performance");
40 
41  gFileMetadataService = Components.classes["@songbirdnest.com/Songbird/FileMetadataService;1"]
42  .getService(Components.interfaces.sbIFileMetadataService);
43 
44  var scan = Cc["@songbirdnest.com/Songbird/FileScan;1"]
45  .createInstance(Ci.sbIFileScan);
46 
47  var query = Cc["@songbirdnest.com/Songbird/FileScanQuery;1"]
48  .createInstance(Ci.sbIFileScanQuery);
49  query.setDirectory("/media/sdb1/steve/old/steve/fakemp3s");
50  query.setRecurse(true);
51 
52  query.addFileExtension("mp3");
53 
54  scan.submitQuery(query);
55 
56  log("Scanning...");
57 
58  while (query.isScanning()) {
59  sleep(1000);
60  }
61  var urls = query.getResultRangeAsURIStrings(0, query.getFileCount() - 1);
62 
63  fileScan.finalize();
64 
65  log("Creating " + urls.length + " items...");
66  var items = library.batchCreateMediaItems(urls, null, true);
67 
68  t = Date.now();
69 
70  var jobs = items.length / ITEMS_PER_JOB;
71  log("jobs = " + jobs);
72  var index = 0;
73  for (var i = 0; i < jobs; i++) {
74  var a = Cc["@songbirdnest.com/moz/xpcom/threadsafe-array;1"].createInstance(Ci.nsIMutableArray);
75  for (var j = 0; j < ITEMS_PER_JOB; j++) {
76  if (index >= items.length) {
77  break;
78  }
79  a.appendElement(items.queryElementAt(index, Ci.sbIMediaItem), false);
80  index++;
81  }
82 
83  var job = gFileMetadataService.read(a);
84  job.addJobProgressListener(onComplete);
85  count++;
86  log("length = " + a.length + " count = " + count);
87  }
88  testPending();
89 
90 }
91 
92 function onComplete(job) {
93  if (job.status == Components.interfaces.sbIJobProgress.STATUS_RUNNING) {
94  return;
95  }
96 
97  job.removeJobProgressListener(onComplete);
98  log("done = " + count);
99  count--;
100  if (count == 0) {
101  var time = Date.now() - t;
102  log("Metadata scan finished in " + (time / 1000) + "s");
103  testFinished(); // Complete the testing
104  }
105 }
function sleep(ms, suppressOutput)
const Cc
var gFileMetadataService
Test file.
function log(s)
function testFinished()
function createNewLibrary(databaseGuid, databaseLocation)
var count
function onComplete(job)
var t
function runTest()
Advanced DataRemote unit tests.
return null
Definition: FeedWriter.js:1143
const Ci
_getSelectedPageStyle s i
function testPending()