~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit/blackberry/WebKitSupport/AboutData.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010, 2011 Research In Motion Limited. All rights reserved.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
#include "AboutData.h"
 
21
 
 
22
#include "AboutTemplate.html.cpp"
 
23
#include "CacheHelper.h"
 
24
#include "CookieManager.h"
 
25
#include "JSDOMWindow.h"
 
26
#include "MemoryCache.h"
 
27
#include "MemoryStatistics.h"
 
28
#include "SurfacePool.h"
 
29
#include "WebKitVersion.h"
 
30
 
 
31
#include <BlackBerryPlatformLog.h>
 
32
#include <BlackBerryPlatformMemory.h>
 
33
#include <BlackBerryPlatformSettings.h>
 
34
#include <BlackBerryPlatformWebKitCredits.h>
 
35
#include <BuildInformation.h>
 
36
#include <heap/Heap.h>
 
37
#include <process.h>
 
38
#include <runtime/JSGlobalData.h>
 
39
#include <sys/stat.h>
 
40
#include <sys/utsname.h>
 
41
#include <wtf/text/CString.h>
 
42
 
 
43
using namespace WebCore;
 
44
 
 
45
namespace BlackBerry {
 
46
namespace WebKit {
 
47
 
 
48
static String writeFeatures(const Vector<String>& trueList, const Vector<String>& falseList)
 
49
{
 
50
    String ret;
 
51
    for (unsigned int i = 0, j = 0; i < trueList.size() || j < falseList.size();) {
 
52
        bool pickFromFalse = ((i >= trueList.size()) || (j < falseList.size() && strcmp(falseList[j].ascii().data(), trueList[i].ascii().data()) < 0));
 
53
        const String& item = (pickFromFalse ? falseList : trueList)[ (pickFromFalse ? j : i)++ ];
 
54
        ret += String("<tr><td><div class='" + String(pickFromFalse ? "false" : "true") + "'" + (item.length() >= 30 ? " style='font-size:10px;' " : "") + ">" + item + "</div></td></tr>");
 
55
    }
 
56
    return ret;
 
57
}
 
58
 
 
59
template<class T> static String numberToHTMLTr(const String& description, T number)
 
60
{
 
61
    return String("<tr><td>") + description + "</td><td>" + String::number(number) + "</td></tr>";
 
62
}
 
63
 
 
64
template<> String numberToHTMLTr<bool>(const String& description, bool truth)
 
65
{
 
66
    return String("<tr><td>") + description + "</td><td>" + (truth?"true":"false") + "</td></tr>";
 
67
}
 
68
 
 
69
static String configPage()
 
70
{
 
71
    String page;
 
72
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
 
73
    page = writeHeader("Configuration")
 
74
    + "<div class=\"box\"><div class=\"box-title\">Compiler Information</div><table class='fixed-table'><col width=75%><col width=25%>"
 
75
#if COMPILER(MSVC)
 
76
    + "<tr><td>Microsoft Visual C++</td><td>MSVC</td></tr>"
 
77
    + "<tr><td>_MSC_VER</td><td>" + String::number(_MSC_VER) + "</td></tr>"
 
78
    + "<tr><td>_MSC_FULL_VER</td><td>" + String::number(_MSC_FULL_VER) + "</td></tr>"
 
79
    + "<tr><td>_MSC_BUILD</td><td>" + String::number(_MSC_BUILD) + "</td></tr>"
 
80
#elif COMPILER(RVCT)
 
81
    + "<tr><td>ARM RealView Compiler Toolkit</td><td>RVCT</td></tr>"
 
82
    + "<tr><td>__ARMCC_VERSION</td><td>" + String::number(__ARMCC_VERSION) + "</td></tr>"
 
83
#if COMPILER(RVCT4GNU)
 
84
    + "<tr><td>RVCT 4+ in --gnu mode</td><td>1</td></tr>"
 
85
#endif
 
86
#elif COMPILER(GCC)
 
87
    + "<tr><td>GCC</td><td>" + String::number(__GNUC__) + "." + String::number(__GNUC_MINOR__) + "." + String::number(__GNUC_PATCHLEVEL__) + "</td></tr>"
 
88
#endif
 
89
 
 
90
    // Add "" to satisfy check-webkit-style.
 
91
    + "";
 
92
 
 
93
    page += String("</table></div><br><div class='box'><div class='box-title'>CPU Information</div><table class='fixed-table'><col width=75%><col width=25%>")
 
94
#if CPU(X86)
 
95
    + "<tr><td>X86</td><td></td></tr>"
 
96
#elif CPU(ARM)
 
97
    + "<tr><td>ARM</td><td></td></tr>"
 
98
    + "<tr><td>ARM_ARCH_VERSION</td><td>" + String::number(WTF_ARM_ARCH_VERSION) + "</td></tr>"
 
99
    + "<tr><td>THUMB_ARCH_VERSION</td><td>" + String::number(WTF_THUMB_ARCH_VERSION) + "</td></tr>"
 
100
    + "<tr><td>THUMB2</td><td>" + String::number(WTF_CPU_ARM_THUMB2) + "</td></tr>"
 
101
#endif
 
102
    + "<tr><td>Endianness</td><td>"
 
103
#if CPU(BIG_ENDIAN)
 
104
    + "big"
 
105
#elif CPU(MIDDLE_ENDIAN)
 
106
    + "middle"
 
107
#else
 
108
    + "little"
 
109
#endif
 
110
    + "</td></tr>";
 
111
 
 
112
    page += String("</table></div><br><div class='box'><div class='box-title'>Platform Information</div><table class='fixed-table'><col width=75%><col width=25%>")
 
113
    + "<tr><td>WebKit Version</td><td>" + String::number(WEBKIT_MAJOR_VERSION) + "." + String::number(WEBKIT_MINOR_VERSION) + "</td></tr>"
 
114
    + "<tr><td>BlackBerry</td><td>"
 
115
#if PLATFORM(BLACKBERRY)
 
116
    + "1"
 
117
#else
 
118
    + "0"
 
119
#endif
 
120
    + "</td></tr>"
 
121
    + "<tr><td>__STDC_ISO_10646__</td><td>"
 
122
#ifdef __STDC_ISO_10646__
 
123
    + "1"
 
124
#else
 
125
    + "0"
 
126
#endif
 
127
    + "</td></tr>";
 
128
 
 
129
    BlackBerry::Platform::Settings* settings = BlackBerry::Platform::Settings::instance();
 
130
    page += String("</table></div><br><div class='box'><div class='box-title'>Platform Settings</div><table style='font-size:11px;' class='fixed-table'><col width=75%><col width=25%>");
 
131
    page += numberToHTMLTr("isRSSFilteringEnabled", settings->isRSSFilteringEnabled());
 
132
    page += numberToHTMLTr("secondaryThreadStackSize", settings->secondaryThreadStackSize());
 
133
    page += numberToHTMLTr("maxPixelsPerDecodedImage", settings->maxPixelsPerDecodedImage());
 
134
    page += numberToHTMLTr("shouldReportLowMemoryToUser", settings->shouldReportLowMemoryToUser());
 
135
    page += numberToHTMLTr("numberOfBackingStoreTiles", settings->numberOfBackingStoreTiles());
 
136
    page += numberToHTMLTr("maximumNumberOfBacking...AcrossProcesses", settings->maximumNumberOfBackingStoreTilesAcrossProcesses());
 
137
    page += numberToHTMLTr("tabsSupportedByClient", settings->tabsSupportedByClient());
 
138
    page += numberToHTMLTr("contextMenuEnabled", settings->contextMenuEnabled());
 
139
    page += numberToHTMLTr("selectionEnabled", settings->selectionEnabled());
 
140
    page += numberToHTMLTr("fineCursorControlEnabled", settings->fineCursorControlEnabled());
 
141
    page += numberToHTMLTr("alwaysShowKeyboardOnFocus", settings->alwaysShowKeyboardOnFocus());
 
142
    page += numberToHTMLTr("allowedScrollAdjustmentForInputFields", settings->allowedScrollAdjustmentForInputFields());
 
143
    page += numberToHTMLTr("unrestrictedResizeEvents", settings->unrestrictedResizeEvents());
 
144
    page += numberToHTMLTr("isBridgeBrowser", settings->isBridgeBrowser());
 
145
    page += numberToHTMLTr("showImageLocationOptionsInGCM", settings->showImageLocationOptionsInGCM());
 
146
    page += numberToHTMLTr("forceGLES2WindowUsage", settings->forceGLES2WindowUsage());
 
147
    page += numberToHTMLTr("maxClickableSpeed", settings->maxClickableSpeed());
 
148
    page += numberToHTMLTr("maxJitterRadiusClick", settings->maxJitterRadiusClick());
 
149
    page += numberToHTMLTr("maxJitterRadiusTap", settings->maxJitterRadiusTap());
 
150
    page += numberToHTMLTr("maxJitterRadiusSingleTouchMove", settings->maxJitterRadiusSingleTouchMove());
 
151
    page += numberToHTMLTr("maxJitterRadiusTouchHold", settings->maxJitterRadiusTouchHold());
 
152
    page += numberToHTMLTr("maxJitterRadiusHandleDrag", settings->maxJitterRadiusHandleDrag());
 
153
    page += numberToHTMLTr("maxJitterRadiusTapHighlight", settings->maxJitterRadiusTapHighlight());
 
154
    page += numberToHTMLTr("maxJitterDistanceClick", settings->maxJitterDistanceClick());
 
155
    page += numberToHTMLTr("maxJitterDistanceTap", settings->maxJitterDistanceTap());
 
156
    page += numberToHTMLTr("maxJitterDistanceSingleTouchMove", settings->maxJitterDistanceSingleTouchMove());
 
157
    page += numberToHTMLTr("maxJitterDistanceTouchHold", settings->maxJitterDistanceTouchHold());
 
158
    page += numberToHTMLTr("maxJitterDistanceTapHighlight", settings->maxJitterDistanceTapHighlight());
 
159
    page += numberToHTMLTr("maxJitterDistanceHandleDrag", settings->maxJitterDistanceHandleDrag());
 
160
    page += numberToHTMLTr("topFatFingerPadding", settings->topFatFingerPadding());
 
161
    page += numberToHTMLTr("rightFatFingerPadding", settings->rightFatFingerPadding());
 
162
    page += numberToHTMLTr("bottomFatFingerPadding", settings->bottomFatFingerPadding());
 
163
    page += numberToHTMLTr("maxSelectionNeckHeight", settings->maxSelectionNeckHeight());
 
164
    page += numberToHTMLTr("leftFatFingerPadding", settings->leftFatFingerPadding());
 
165
 
 
166
    Vector<String> trueList, falseList;
 
167
    #include "AboutDataEnableFeatures.cpp"
 
168
    page += String("</table></div><br><div class='box'><div class='box-title'>WebKit Features (ENABLE_)</div><table class='fixed-table'>");
 
169
 
 
170
    page += writeFeatures(trueList, falseList);
 
171
 
 
172
    trueList.clear();
 
173
    falseList.clear();
 
174
    #include "AboutDataHaveFeatures.cpp"
 
175
    page += String("</table></div><br><div class='box'><div class='box-title'>WebKit Features (HAVE_)</div><table class='fixed-table'>");
 
176
 
 
177
    page += writeFeatures(trueList, falseList);
 
178
 
 
179
    trueList.clear();
 
180
    falseList.clear();
 
181
    #include "AboutDataUseFeatures.cpp"
 
182
    page += String("</table></div><br><div class='box'><div class='box-title'>WebKit Features (USE_)</div><table class='fixed-table'>");
 
183
    page += writeFeatures(trueList, falseList);
 
184
    page += String("</table></div></body></html>");
 
185
#endif
 
186
 
 
187
    return page;
 
188
}
 
189
 
 
190
static String cacheTypeStatisticToHTMLTr(const String& description, const MemoryCache::TypeStatistic& statistic)
 
191
{
 
192
    const int s_kiloByte = 1024;
 
193
    return String("<tr><td>") + description + "</td>"
 
194
        + "<td>" + String::number(statistic.count) + "</td>"
 
195
        + "<td>" + String::number(statistic.size / s_kiloByte) + "</td>"
 
196
        + "<td>" + String::number(statistic.liveSize / s_kiloByte) + "</td>"
 
197
        + "<td>" + String::number(statistic.decodedSize / s_kiloByte) + "</td>"
 
198
        + "</tr>";
 
199
}
 
200
 
 
201
static void dumpJSCTypeCountSetToTableHTML(String& tableHTML, JSC::TypeCountSet* typeCountSet)
 
202
{
 
203
    if (!typeCountSet)
 
204
        return;
 
205
 
 
206
    for (JSC::TypeCountSet::const_iterator iter = typeCountSet->begin(); iter != typeCountSet->end(); ++iter)
 
207
        tableHTML += numberToHTMLTr(iter->key, iter->value);
 
208
}
 
209
 
 
210
static String memoryPage()
 
211
{
 
212
    String page;
 
213
 
 
214
    page = writeHeader("Memory")
 
215
    + "<div class=\"box\"><div class=\"box-title\">Cache Information<br><div style='font-size:11px;color:#A8A8A8'>Size, Living, and Decoded are expressed in KB.</div><br></div><table class='fixed-table'><col width=75%><col width=25%>";
 
216
 
 
217
    // generate cache information
 
218
    MemoryCache* cacheInc = memoryCache();
 
219
    MemoryCache::Statistics cacheStat = cacheInc->getStatistics();
 
220
 
 
221
    page += "<tr> <th align=left>Item</th> <th align=left>Count</th> <th align=left>Size</th> <th align=left>Living</th> <th align=left>Decoded</th></tr>";
 
222
 
 
223
    MemoryCache::TypeStatistic total;
 
224
    total.count = cacheStat.images.count + cacheStat.cssStyleSheets.count
 
225
            + cacheStat.scripts.count + cacheStat.xslStyleSheets.count + cacheStat.fonts.count;
 
226
    total.size = cacheInc->totalSize();
 
227
    total.liveSize = cacheStat.images.liveSize + cacheStat.cssStyleSheets.liveSize
 
228
            + cacheStat.scripts.liveSize + cacheStat.xslStyleSheets.liveSize + cacheStat.fonts.liveSize;
 
229
    total.decodedSize = cacheStat.images.decodedSize
 
230
            + cacheStat.cssStyleSheets.decodedSize + cacheStat.scripts.decodedSize
 
231
            + cacheStat.xslStyleSheets.decodedSize + cacheStat.fonts.decodedSize;
 
232
 
 
233
    page += cacheTypeStatisticToHTMLTr("Total", total);
 
234
    page += cacheTypeStatisticToHTMLTr("Images", cacheStat.images);
 
235
    page += cacheTypeStatisticToHTMLTr("CSS Style Sheets", cacheStat.cssStyleSheets);
 
236
    page += cacheTypeStatisticToHTMLTr("Scripts", cacheStat.scripts);
 
237
#if ENABLE(XSLT)
 
238
    page += cacheTypeStatisticToHTMLTr("XSL Style Sheets", cacheStat.xslStyleSheets);
 
239
#endif
 
240
    page += cacheTypeStatisticToHTMLTr("Fonts", cacheStat.fonts);
 
241
 
 
242
    page += "</table></div><br>";
 
243
 
 
244
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
 
245
 
 
246
    // JS engine memory usage.
 
247
    JSC::GlobalMemoryStatistics jscMemoryStat = JSC::globalMemoryStatistics();
 
248
    JSC::Heap& mainHeap = JSDOMWindow::commonJSGlobalData()->heap;
 
249
    OwnPtr<JSC::TypeCountSet> objectTypeCounts = mainHeap.objectTypeCounts();
 
250
    OwnPtr<JSC::TypeCountSet> protectedObjectTypeCounts = mainHeap.protectedObjectTypeCounts();
 
251
 
 
252
    // Malloc info.
 
253
    struct mallinfo mallocInfo = mallinfo();
 
254
 
 
255
    page += "<div class='box'><div class='box-title'>Process memory usage summary</div><table class='fixed-table'><col width=75%><col width=25%>";
 
256
 
 
257
    page += numberToHTMLTr("Total used memory (malloc + JSC)", mallocInfo.usmblks + mallocInfo.uordblks + jscMemoryStat.stackBytes + jscMemoryStat.JITBytes + mainHeap.capacity());
 
258
 
 
259
    if (unsigned totalCommittedMemoryOfChromeProcess = BlackBerry::Platform::totalCommittedMemoryOfChromeProcess()) {
 
260
        page += numberToHTMLTr("Total committed memory of tab process", BlackBerry::Platform::totalCommittedMemoryOfCurrentProcess());
 
261
        page += numberToHTMLTr("Total committed memory of chrome process", totalCommittedMemoryOfChromeProcess);
 
262
    } else
 
263
        page += numberToHTMLTr("Total committed memory", BlackBerry::Platform::totalCommittedMemoryOfCurrentProcess());
 
264
 
 
265
    struct stat processInfo;
 
266
    if (!stat(String::format("/proc/%u/as", getpid()).latin1().data(), &processInfo))
 
267
        page += numberToHTMLTr("Total mapped memory", processInfo.st_size);
 
268
 
 
269
    page += numberToHTMLTr("System free memory", BlackBerry::Platform::systemFreeMemory());
 
270
 
 
271
    page += "</table></div><br>";
 
272
 
 
273
    page += "<div class='box'><div class='box-title'>JS engine memory usage</div><table class='fixed-table'><col width=75%><col width=25%>";
 
274
 
 
275
    page += numberToHTMLTr("Stack size", jscMemoryStat.stackBytes);
 
276
    page += numberToHTMLTr("JIT memory usage", jscMemoryStat.JITBytes);
 
277
    page += numberToHTMLTr("Main heap capacity", mainHeap.capacity());
 
278
    page += numberToHTMLTr("Main heap size", mainHeap.size());
 
279
    page += numberToHTMLTr("Object count", mainHeap.objectCount());
 
280
    page += numberToHTMLTr("Global object count", mainHeap.globalObjectCount());
 
281
    page += numberToHTMLTr("Protected object count", mainHeap.protectedObjectCount());
 
282
    page += numberToHTMLTr("Protected global object count", mainHeap.protectedGlobalObjectCount());
 
283
 
 
284
    page += "</table></div><br>";
 
285
 
 
286
    page += "<div class='box'><div class='box-title'>JS object type counts</div><table class='fixed-table'><col width=75%><col width=25%>";
 
287
    dumpJSCTypeCountSetToTableHTML(page, objectTypeCounts.get());
 
288
    page += "</table></div><br>";
 
289
 
 
290
    page += "<div class='box'><div class='box-title'>JS protected object type counts</div><table class='fixed-table'><col width=75%><col width=25%>";
 
291
    dumpJSCTypeCountSetToTableHTML(page, protectedObjectTypeCounts.get());
 
292
    page += "</table></div><br>";
 
293
 
 
294
    page += "<div class='box'><div class='box-title'>Malloc Information</div><table class='fixed-table'><col width=75%><col width=25%>";
 
295
 
 
296
    page += numberToHTMLTr("Total space in use", mallocInfo.usmblks + mallocInfo.uordblks);
 
297
    page += numberToHTMLTr("Total space in free blocks", mallocInfo.fsmblks + mallocInfo.fordblks);
 
298
    page += numberToHTMLTr("Size of the arena", mallocInfo.arena);
 
299
    page += numberToHTMLTr("Number of big blocks in use", mallocInfo.ordblks);
 
300
    page += numberToHTMLTr("Number of small blocks in use", mallocInfo.smblks);
 
301
    page += numberToHTMLTr("Number of header blocks in use", mallocInfo.hblks);
 
302
    page += numberToHTMLTr("Space in header block headers", mallocInfo.hblkhd);
 
303
    page += numberToHTMLTr("Space in small blocks in use", mallocInfo.usmblks);
 
304
    page += numberToHTMLTr("Memory in free small blocks", mallocInfo.fsmblks);
 
305
    page += numberToHTMLTr("Space in big blocks in use", mallocInfo.uordblks);
 
306
    page += numberToHTMLTr("Memory in free big blocks", mallocInfo.fordblks);
 
307
 
 
308
    page += "</table></div>";
 
309
#endif
 
310
 
 
311
    page += "</body></html>";
 
312
    return page;
 
313
}
 
314
 
 
315
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
 
316
class MemoryTracker {
 
317
public:
 
318
    static MemoryTracker& instance();
 
319
    void start();
 
320
    void stop();
 
321
    bool isActive() const { return m_memoryTrackingTimer.isActive(); }
 
322
    void clear()
 
323
    {
 
324
        m_peakTotalUsedMemory = 0;
 
325
        m_peakTotalCommittedMemoryOfCurrentProcess = 0;
 
326
        m_peakTotalCommittedMemoryOfChromeProcess = 0;
 
327
        m_peakTotalMappedMemory = 0;
 
328
    }
 
329
 
 
330
    void updateMemoryPeaks(Timer<MemoryTracker>*);
 
331
    unsigned peakTotalUsedMemory() const { return m_peakTotalUsedMemory; }
 
332
    unsigned peakTotalCommittedMemoryOfCurrentProcess() const { return m_peakTotalCommittedMemoryOfCurrentProcess; }
 
333
    unsigned peakTotalCommittedMemoryOfChromeProcess() const { return m_peakTotalCommittedMemoryOfChromeProcess; }
 
334
    unsigned peakTotalMappedMemory() const { return m_peakTotalMappedMemory; }
 
335
 
 
336
private:
 
337
    MemoryTracker();
 
338
    Timer<MemoryTracker> m_memoryTrackingTimer;
 
339
    unsigned m_peakTotalUsedMemory;
 
340
    unsigned m_peakTotalCommittedMemoryOfCurrentProcess;
 
341
    unsigned m_peakTotalCommittedMemoryOfChromeProcess;
 
342
    unsigned m_peakTotalMappedMemory;
 
343
};
 
344
 
 
345
MemoryTracker::MemoryTracker()
 
346
    : m_memoryTrackingTimer(this, &MemoryTracker::updateMemoryPeaks)
 
347
    , m_peakTotalUsedMemory(0)
 
348
    , m_peakTotalCommittedMemoryOfCurrentProcess(0)
 
349
    , m_peakTotalCommittedMemoryOfChromeProcess(0)
 
350
    , m_peakTotalMappedMemory(0)
 
351
{
 
352
}
 
353
 
 
354
MemoryTracker& MemoryTracker::instance()
 
355
{
 
356
    DEFINE_STATIC_LOCAL(MemoryTracker, s_memoryTracker, ());
 
357
    return s_memoryTracker;
 
358
}
 
359
 
 
360
void MemoryTracker::start()
 
361
{
 
362
    clear();
 
363
    if (!m_memoryTrackingTimer.isActive())
 
364
        m_memoryTrackingTimer.start(0, 0.01);
 
365
}
 
366
 
 
367
void MemoryTracker::stop()
 
368
{
 
369
    m_memoryTrackingTimer.stop();
 
370
}
 
371
 
 
372
void MemoryTracker::updateMemoryPeaks(Timer<MemoryTracker>*)
 
373
{
 
374
    // JS engine memory usage.
 
375
    JSC::GlobalMemoryStatistics jscMemoryStat = JSC::globalMemoryStatistics();
 
376
    JSC::Heap& mainHeap = JSDOMWindow::commonJSGlobalData()->heap;
 
377
 
 
378
    // Malloc info.
 
379
    struct mallinfo mallocInfo = mallinfo();
 
380
 
 
381
    // Malloc and JSC memory.
 
382
    unsigned totalUsedMemory = static_cast<unsigned>(mallocInfo.usmblks + mallocInfo.uordblks + jscMemoryStat.stackBytes + jscMemoryStat.JITBytes + mainHeap.capacity());
 
383
    if (totalUsedMemory > m_peakTotalUsedMemory)
 
384
        m_peakTotalUsedMemory = totalUsedMemory;
 
385
 
 
386
    unsigned totalCommittedMemoryOfCurrentProcess = BlackBerry::Platform::totalCommittedMemoryOfCurrentProcess();
 
387
    if (totalCommittedMemoryOfCurrentProcess > m_peakTotalCommittedMemoryOfCurrentProcess)
 
388
        m_peakTotalCommittedMemoryOfCurrentProcess = totalCommittedMemoryOfCurrentProcess;
 
389
 
 
390
    unsigned totalCommittedMemoryOfChromeProcess = BlackBerry::Platform::totalCommittedMemoryOfChromeProcess();
 
391
    if (totalCommittedMemoryOfChromeProcess > m_peakTotalCommittedMemoryOfChromeProcess)
 
392
        m_peakTotalCommittedMemoryOfChromeProcess = totalCommittedMemoryOfChromeProcess;
 
393
 
 
394
    struct stat processInfo;
 
395
    if (!stat(String::format("/proc/%u/as", getpid()).latin1().data(), &processInfo)) {
 
396
        unsigned totalMappedMemory = static_cast<unsigned>(processInfo.st_size);
 
397
        if (totalMappedMemory > m_peakTotalMappedMemory)
 
398
            m_peakTotalMappedMemory = totalMappedMemory;
 
399
    }
 
400
}
 
401
 
 
402
static String memoryPeaksToHtmlTable(MemoryTracker& memoryTracker)
 
403
{
 
404
    String htmlTable = String("<table class='fixed-table'><col width=75%><col width=25%>")
 
405
        + numberToHTMLTr("Total used memory(malloc + JSC):", memoryTracker.peakTotalUsedMemory());
 
406
 
 
407
    if (unsigned peakTotalCommittedMemoryOfChromeProcess = memoryTracker.peakTotalCommittedMemoryOfChromeProcess()) {
 
408
        htmlTable += numberToHTMLTr("Total committed memory of tab process:", memoryTracker.peakTotalCommittedMemoryOfCurrentProcess());
 
409
        htmlTable += numberToHTMLTr("Total committed memory of chrome process:", peakTotalCommittedMemoryOfChromeProcess);
 
410
    } else
 
411
        htmlTable += numberToHTMLTr("Total committed memory:", memoryTracker.peakTotalCommittedMemoryOfCurrentProcess());
 
412
 
 
413
    htmlTable += numberToHTMLTr("Total mapped memory:", memoryTracker.peakTotalMappedMemory()) + "</table>";
 
414
    return htmlTable;
 
415
}
 
416
 
 
417
static String memoryLivePage(String memoryLiveCommand)
 
418
{
 
419
    String page;
 
420
 
 
421
    page = writeHeader("Memory Live Page")
 
422
        + "<div class='box'><div class='box-title'>Memory Peaks</div>"
 
423
        + "<div style='font-size:12px;color:#1BE0C9'>\"about:memory-live/start\": start tracking memory peaks.</div>"
 
424
        + "<div style='font-size:12px;color:#1BE0C9'>\"about:memory-live\": show memory peaks every 30ms.</div>"
 
425
        + "<div style='font-size:12px;color:#1BE0C9'>\"about:memory-live/stop\": stop tracking and show memory peaks.</div><br>";
 
426
 
 
427
    MemoryTracker& memoryTracker = MemoryTracker::instance();
 
428
    if (memoryLiveCommand.isEmpty()) {
 
429
        if (!memoryTracker.isActive())
 
430
            page += "<div style='font-size:15px;color:#E6F032'>Memory tracker isn't running, please use \"about:memory-live/start\" to start the tracker.</div>";
 
431
        else {
 
432
            page += memoryPeaksToHtmlTable(memoryTracker);
 
433
            page += "<script type=\"text/javascript\">setInterval(function(){window.location.reload()},30);</script>";
 
434
        }
 
435
    } else if (equalIgnoringCase(memoryLiveCommand, "/start")) {
 
436
        memoryTracker.start();
 
437
        page += "<div style='font-size:15px;color:#E6F032'>Memory tracker is running.</div>";
 
438
    } else if (equalIgnoringCase(memoryLiveCommand, "/stop")) {
 
439
        if (!memoryTracker.isActive())
 
440
            page += "<div style='font-size:15px;color:#E6F032'>Memory tracker isn't running.</div>";
 
441
        else {
 
442
            memoryTracker.stop();
 
443
            page += memoryPeaksToHtmlTable(memoryTracker);
 
444
            page += "<div style='font-size:15px;color:#E6F032'>Memory tracker is stopped.</div>";
 
445
        }
 
446
    } else
 
447
        page += "<div style='font-size:15spx;color:#E6F032'>Unknown command! Please input a correct command!</div>";
 
448
 
 
449
    page += "</div><br></div></body></html>";
 
450
    return page;
 
451
}
 
452
#endif
 
453
 
 
454
static String cachePage(String cacheCommand)
 
455
{
 
456
    String result;
 
457
 
 
458
    result.append(String("<html><head><title>BlackBerry Browser Disk Cache</title></head><body>"));
 
459
 
 
460
    if (cacheCommand.isEmpty())
 
461
        result.append(String(BlackBerry::Platform::generateHtmlFragmentForCacheKeys().data()));
 
462
    else if (cacheCommand.startsWith("?query=", false)) {
 
463
        String key(cacheCommand.substring(7).utf8().data()); // 7 is length of "query=".
 
464
        result.append(key);
 
465
        result.append(String("<hr>"));
 
466
        result.append(String(BlackBerry::Platform::generateHtmlFragmentForCacheHeaders(key).data()));
 
467
    } else {
 
468
        // Unknown cache command.
 
469
        return String();
 
470
    }
 
471
 
 
472
    result.append(String("</body></html>"));
 
473
 
 
474
    return result;
 
475
}
 
476
 
 
477
static String buildPage()
 
478
{
 
479
    String result;
 
480
 
 
481
    result.append(writeHeader("Build"));
 
482
    result.append(String("<div class='box'><div class='box-title'>Basic</div><table>"));
 
483
    result.append(String("<tr><td>Built On:  </td><td>"));
 
484
    result.append(String(BlackBerry::Platform::BUILDCOMPUTER));
 
485
    result.append(String("</td></tr>"));
 
486
    result.append(String("<tr><td>Build User:  </td><td>"));
 
487
    result.append(String(BlackBerry::Platform::BUILDUSER));
 
488
    result.append(String("</td></tr>"));
 
489
    result.append(String("<tr><td>Build Time:  </td><td>"));
 
490
    result.append(String(BlackBerry::Platform::BUILDTIME));
 
491
    result.append(String("</table></div><br>"));
 
492
    result.append(String(BlackBerry::Platform::BUILDINFO_WEBKIT));
 
493
    result.append(String(BlackBerry::Platform::BUILDINFO_PLATFORM));
 
494
    result.append(String(BlackBerry::Platform::BUILDINFO_LIBWEBVIEW));
 
495
    result.append(String(BlackBerry::Platform::BUILDINFO_WEBPLATFORM));
 
496
    result.append(String("</body></html>"));
 
497
 
 
498
    return result;
 
499
}
 
500
 
 
501
static String creditsPage()
 
502
{
 
503
    String result;
 
504
 
 
505
    result.append(writeHeader("Credits"));
 
506
    result.append(String("<style> .about {padding:14px;} </style>"));
 
507
    result.append(String(BlackBerry::Platform::WEBKITCREDITS));
 
508
    result.append(String("</body></html>"));
 
509
 
 
510
    return result;
 
511
}
 
512
 
 
513
static String cookiePage()
 
514
{
 
515
    String result;
 
516
 
 
517
    result.append(String("<html><head><title>BlackBerry Browser cookie information</title></head><body>"));
 
518
    result.append(cookieManager().generateHtmlFragmentForCookies());
 
519
    result.append(String("</body></html>"));
 
520
 
 
521
    return result;
 
522
}
 
523
 
 
524
String aboutData(String aboutWhat)
 
525
{
 
526
    if (equalIgnoringCase(aboutWhat, "credits"))
 
527
        return creditsPage();
 
528
 
 
529
    if (aboutWhat.startsWith("cache"))
 
530
        return cachePage(aboutWhat.substring(5));
 
531
 
 
532
    if (equalIgnoringCase(aboutWhat, "memory"))
 
533
        return memoryPage();
 
534
 
 
535
#if !defined(PUBLIC_BUILD) || !PUBLIC_BUILD
 
536
    if (equalIgnoringCase(aboutWhat, "cookie"))
 
537
        return cookiePage();
 
538
 
 
539
    if (BlackBerry::Platform::debugSetting() > 0 && equalIgnoringCase(aboutWhat, "build"))
 
540
        return buildPage();
 
541
 
 
542
    if (BlackBerry::Platform::debugSetting() > 0 && equalIgnoringCase(aboutWhat, "config"))
 
543
        return configPage();
 
544
 
 
545
    if (aboutWhat.startsWith("memory-live"))
 
546
        return memoryLivePage(aboutWhat.substring(11));
 
547
#endif
 
548
 
 
549
    return String();
 
550
}
 
551
 
 
552
} // namespace WebKit
 
553
} // namespace BlackBerry