The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | namespace android { |
| 30 | |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 31 | static jfieldID gMemoryUsedField; |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame^] | 32 | static jfieldID gPageCacheOverflowField; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 33 | static jfieldID gLargestMemAllocField; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
| 35 | |
| 36 | #define USE_MSPACE 0 |
| 37 | |
| 38 | static void getPagerStats(JNIEnv *env, jobject clazz, jobject statsObj) |
| 39 | { |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 40 | int memoryUsed; |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame^] | 41 | int pageCacheOverflow; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 42 | int largestMemAlloc; |
| 43 | int unused; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 45 | sqlite3_status(SQLITE_STATUS_MEMORY_USED, &memoryUsed, &unused, 0); |
| 46 | sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &unused, &largestMemAlloc, 0); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame^] | 47 | sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &pageCacheOverflow, &unused, 0); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 48 | env->SetIntField(statsObj, gMemoryUsedField, memoryUsed); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame^] | 49 | env->SetIntField(statsObj, gPageCacheOverflowField, pageCacheOverflow); |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 50 | env->SetIntField(statsObj, gLargestMemAllocField, largestMemAlloc); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | } |
| 52 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | /* |
| 54 | * JNI registration. |
| 55 | */ |
| 56 | |
| 57 | static JNINativeMethod gMethods[] = |
| 58 | { |
| 59 | { "getPagerStats", "(Landroid/database/sqlite/SQLiteDebug$PagerStats;)V", |
| 60 | (void*) getPagerStats }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | int register_android_database_SQLiteDebug(JNIEnv *env) |
| 64 | { |
| 65 | jclass clazz; |
| 66 | |
| 67 | clazz = env->FindClass("android/database/sqlite/SQLiteDebug$PagerStats"); |
| 68 | if (clazz == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 69 | ALOGE("Can't find android/database/sqlite/SQLiteDebug$PagerStats"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | return -1; |
| 71 | } |
| 72 | |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 73 | gMemoryUsedField = env->GetFieldID(clazz, "memoryUsed", "I"); |
| 74 | if (gMemoryUsedField == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 75 | ALOGE("Can't find memoryUsed"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | return -1; |
| 77 | } |
| 78 | |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 79 | gLargestMemAllocField = env->GetFieldID(clazz, "largestMemAlloc", "I"); |
| 80 | if (gLargestMemAllocField == NULL) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 81 | ALOGE("Can't find largestMemAlloc"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | return -1; |
| 83 | } |
| 84 | |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame^] | 85 | gPageCacheOverflowField = env->GetFieldID(clazz, "pageCacheOverflow", "I"); |
| 86 | if (gPageCacheOverflowField == NULL) { |
| 87 | ALOGE("Can't find pageCacheOverflow"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | return -1; |
| 89 | } |
| 90 | |
| 91 | return jniRegisterNativeMethods(env, "android/database/sqlite/SQLiteDebug", |
| 92 | gMethods, NELEM(gMethods)); |
| 93 | } |
| 94 | |
| 95 | } // namespace android |