blob: 8d4e7f9ca768f7ca967f7056d142a896f3e7be91 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Project9066cfe2009-03-03 19:31:44 -080029namespace android {
30
Vasu Noric3849202010-03-09 10:47:25 -080031static jfieldID gMemoryUsedField;
Jeff Brown2a293b62012-01-19 14:02:22 -080032static jfieldID gPageCacheOverflowField;
Vasu Noric3849202010-03-09 10:47:25 -080033static jfieldID gLargestMemAllocField;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034
35
36#define USE_MSPACE 0
37
38static void getPagerStats(JNIEnv *env, jobject clazz, jobject statsObj)
39{
Vasu Noric3849202010-03-09 10:47:25 -080040 int memoryUsed;
Jeff Brown2a293b62012-01-19 14:02:22 -080041 int pageCacheOverflow;
Vasu Noric3849202010-03-09 10:47:25 -080042 int largestMemAlloc;
43 int unused;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
Vasu Noric3849202010-03-09 10:47:25 -080045 sqlite3_status(SQLITE_STATUS_MEMORY_USED, &memoryUsed, &unused, 0);
46 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &unused, &largestMemAlloc, 0);
Jeff Brown2a293b62012-01-19 14:02:22 -080047 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &pageCacheOverflow, &unused, 0);
Vasu Noric3849202010-03-09 10:47:25 -080048 env->SetIntField(statsObj, gMemoryUsedField, memoryUsed);
Jeff Brown2a293b62012-01-19 14:02:22 -080049 env->SetIntField(statsObj, gPageCacheOverflowField, pageCacheOverflow);
Vasu Noric3849202010-03-09 10:47:25 -080050 env->SetIntField(statsObj, gLargestMemAllocField, largestMemAlloc);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051}
52
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053/*
54 * JNI registration.
55 */
56
57static JNINativeMethod gMethods[] =
58{
59 { "getPagerStats", "(Landroid/database/sqlite/SQLiteDebug$PagerStats;)V",
60 (void*) getPagerStats },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061};
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) {
Steve Block3762c312012-01-06 19:20:56 +000069 ALOGE("Can't find android/database/sqlite/SQLiteDebug$PagerStats");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 return -1;
71 }
72
Vasu Noric3849202010-03-09 10:47:25 -080073 gMemoryUsedField = env->GetFieldID(clazz, "memoryUsed", "I");
74 if (gMemoryUsedField == NULL) {
Steve Block3762c312012-01-06 19:20:56 +000075 ALOGE("Can't find memoryUsed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 return -1;
77 }
78
Vasu Noric3849202010-03-09 10:47:25 -080079 gLargestMemAllocField = env->GetFieldID(clazz, "largestMemAlloc", "I");
80 if (gLargestMemAllocField == NULL) {
Steve Block3762c312012-01-06 19:20:56 +000081 ALOGE("Can't find largestMemAlloc");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 return -1;
83 }
84
Jeff Brown2a293b62012-01-19 14:02:22 -080085 gPageCacheOverflowField = env->GetFieldID(clazz, "pageCacheOverflow", "I");
86 if (gPageCacheOverflowField == NULL) {
87 ALOGE("Can't find pageCacheOverflow");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 return -1;
89 }
90
91 return jniRegisterNativeMethods(env, "android/database/sqlite/SQLiteDebug",
92 gMethods, NELEM(gMethods));
93}
94
95} // namespace android