Home | History | Annotate | Download | only in android
      1 /*
      2  * Copyright 2010, The Android Open Source Project
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *  * Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  *  * Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #include "config.h"
     27 #include "ClassTracker.h"
     28 
     29 #include "LayerAndroid.h"
     30 #include "TilesManager.h"
     31 
     32 #include <cutils/log.h>
     33 #include <wtf/CurrentTime.h>
     34 #include <wtf/text/CString.h>
     35 
     36 #undef XLOG
     37 #define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "ClassTracker", __VA_ARGS__)
     38 
     39 #define DEBUG_LAYERS
     40 #undef DEBUG_LAYERS
     41 
     42 namespace WebCore {
     43 
     44 ClassTracker* ClassTracker::instance()
     45 {
     46     if (!gInstance)
     47         gInstance = new ClassTracker();
     48     return gInstance;
     49 }
     50 
     51 ClassTracker* ClassTracker::gInstance = 0;
     52 
     53 void ClassTracker::increment(String name)
     54 {
     55    android::Mutex::Autolock lock(m_lock);
     56    int value = 0;
     57    if (m_classes.contains(name))
     58        value = m_classes.get(name);
     59 
     60    m_classes.set(name, value + 1);
     61 }
     62 
     63 void ClassTracker::decrement(String name)
     64 {
     65    android::Mutex::Autolock lock(m_lock);
     66    int value = 0;
     67    if (m_classes.contains(name))
     68        value = m_classes.get(name);
     69 
     70    m_classes.set(name, value - 1);
     71 }
     72 
     73 void ClassTracker::add(LayerAndroid* layer)
     74 {
     75    android::Mutex::Autolock lock(m_lock);
     76    m_layers.append(layer);
     77 }
     78 
     79 void ClassTracker::remove(LayerAndroid* layer)
     80 {
     81    android::Mutex::Autolock lock(m_lock);
     82    m_layers.remove(m_layers.find(layer));
     83 }
     84 
     85 void ClassTracker::show()
     86 {
     87    android::Mutex::Autolock lock(m_lock);
     88    XLOG("*** Tracking %d classes ***", m_classes.size());
     89    for (HashMap<String, int>::iterator iter = m_classes.begin(); iter != m_classes.end(); ++iter) {
     90        XLOG("class %s has %d instances",
     91             iter->first.latin1().data(), iter->second);
     92    }
     93    XLOG("*** %d Layers ***", m_layers.size());
     94    int nbTextures = 0;
     95    int nbAllocatedTextures = 0;
     96    int nbLayerTextures = 0;
     97    int nbAllocatedLayerTextures = 0;
     98    float textureSize = 256 * 256 * 4 / 1024.0 / 1024.0;
     99    TilesManager::instance()->gatherTexturesNumbers(&nbTextures, &nbAllocatedTextures,
    100                                                    &nbLayerTextures, &nbAllocatedLayerTextures);
    101    XLOG("*** textures: %d/%d (%.2f Mb), layer textures: %d/%d (%.2f Mb) : total used %.2f Mb",
    102         nbAllocatedTextures, nbTextures,
    103         nbAllocatedTextures * textureSize,
    104         nbAllocatedLayerTextures, nbLayerTextures,
    105         nbAllocatedLayerTextures * textureSize,
    106         (nbAllocatedTextures + nbAllocatedLayerTextures) * textureSize);
    107 
    108 #ifdef DEBUG_LAYERS
    109    for (unsigned int i = 0; i < m_layers.size(); i++) {
    110        LayerAndroid* layer = m_layers[i];
    111        XLOG("[%d/%d] layer %x (%.2f, %.2f) of type %d, refcount(%d) has texture %x has image ref %x (%x) root: %x parent: %x",
    112             i, m_layers.size(), layer,
    113             layer->getWidth(), layer->getHeight(),
    114             layer->type(), layer->getRefCnt(),
    115             layer->texture(), layer->imageRef(),
    116             layer->imageTexture(), (LayerAndroid*) layer->getRootLayer(),
    117             (LayerAndroid*) layer->getParent());
    118    }
    119 #endif
    120 }
    121 
    122 } // namespace WebCore
    123