android_database_SQLiteDebug.cpp revision 2a293b61cb0efbf24994d74ed980f58b820bb35a
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include <JNIHelp.h> 18#include <jni.h> 19#include <utils/misc.h> 20#include <stdio.h> 21#include <stdlib.h> 22#include <string.h> 23#include <unistd.h> 24#include <cutils/mspace.h> 25#include <utils/Log.h> 26 27#include <sqlite3.h> 28 29namespace android { 30 31static jfieldID gMemoryUsedField; 32static jfieldID gPageCacheOverflowField; 33static jfieldID gLargestMemAllocField; 34 35 36#define USE_MSPACE 0 37 38static void getPagerStats(JNIEnv *env, jobject clazz, jobject statsObj) 39{ 40 int memoryUsed; 41 int pageCacheOverflow; 42 int largestMemAlloc; 43 int unused; 44 45 sqlite3_status(SQLITE_STATUS_MEMORY_USED, &memoryUsed, &unused, 0); 46 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &unused, &largestMemAlloc, 0); 47 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &pageCacheOverflow, &unused, 0); 48 env->SetIntField(statsObj, gMemoryUsedField, memoryUsed); 49 env->SetIntField(statsObj, gPageCacheOverflowField, pageCacheOverflow); 50 env->SetIntField(statsObj, gLargestMemAllocField, largestMemAlloc); 51} 52 53/* 54 * JNI registration. 55 */ 56 57static JNINativeMethod gMethods[] = 58{ 59 { "getPagerStats", "(Landroid/database/sqlite/SQLiteDebug$PagerStats;)V", 60 (void*) getPagerStats }, 61}; 62 63int register_android_database_SQLiteDebug(JNIEnv *env) 64{ 65 jclass clazz; 66 67 clazz = env->FindClass("android/database/sqlite/SQLiteDebug$PagerStats"); 68 if (clazz == NULL) { 69 ALOGE("Can't find android/database/sqlite/SQLiteDebug$PagerStats"); 70 return -1; 71 } 72 73 gMemoryUsedField = env->GetFieldID(clazz, "memoryUsed", "I"); 74 if (gMemoryUsedField == NULL) { 75 ALOGE("Can't find memoryUsed"); 76 return -1; 77 } 78 79 gLargestMemAllocField = env->GetFieldID(clazz, "largestMemAlloc", "I"); 80 if (gLargestMemAllocField == NULL) { 81 ALOGE("Can't find largestMemAlloc"); 82 return -1; 83 } 84 85 gPageCacheOverflowField = env->GetFieldID(clazz, "pageCacheOverflow", "I"); 86 if (gPageCacheOverflowField == NULL) { 87 ALOGE("Can't find pageCacheOverflow"); 88 return -1; 89 } 90 91 return jniRegisterNativeMethods(env, "android/database/sqlite/SQLiteDebug", 92 gMethods, NELEM(gMethods)); 93} 94 95} // namespace android 96