blob: 26e13cf10e719b9455d37094fa117fc1bab9abf5 [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
Jeff Brown254fba82012-01-19 17:06:44 -080017#define LOG_TAG "SQLiteDebug"
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019#include <jni.h>
Jeff Brown254fba82012-01-19 17:06:44 -080020#include <JNIHelp.h>
21#include <android_runtime/AndroidRuntime.h>
22
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <unistd.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <utils/Log.h>
28
29#include <sqlite3.h>
30
Andreas Gampe987f79f2014-11-18 17:29:46 -080031#include "core_jni_helpers.h"
32
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033namespace android {
34
Jeff Brown254fba82012-01-19 17:06:44 -080035static struct {
36 jfieldID memoryUsed;
37 jfieldID pageCacheOverflow;
38 jfieldID largestMemAlloc;
39} gSQLiteDebugPagerStatsClassInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
Jeff Brown254fba82012-01-19 17:06:44 -080041static void nativeGetPagerStats(JNIEnv *env, jobject clazz, jobject statsObj)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042{
Vasu Noric3849202010-03-09 10:47:25 -080043 int memoryUsed;
Jeff Brown2a293b62012-01-19 14:02:22 -080044 int pageCacheOverflow;
Vasu Noric3849202010-03-09 10:47:25 -080045 int largestMemAlloc;
46 int unused;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047
Vasu Noric3849202010-03-09 10:47:25 -080048 sqlite3_status(SQLITE_STATUS_MEMORY_USED, &memoryUsed, &unused, 0);
49 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &unused, &largestMemAlloc, 0);
Jeff Brown2a293b62012-01-19 14:02:22 -080050 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &pageCacheOverflow, &unused, 0);
Jeff Brown254fba82012-01-19 17:06:44 -080051 env->SetIntField(statsObj, gSQLiteDebugPagerStatsClassInfo.memoryUsed, memoryUsed);
52 env->SetIntField(statsObj, gSQLiteDebugPagerStatsClassInfo.pageCacheOverflow,
53 pageCacheOverflow);
54 env->SetIntField(statsObj, gSQLiteDebugPagerStatsClassInfo.largestMemAlloc, largestMemAlloc);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055}
56
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057/*
58 * JNI registration.
59 */
60
61static JNINativeMethod gMethods[] =
62{
Jeff Brown254fba82012-01-19 17:06:44 -080063 { "nativeGetPagerStats", "(Landroid/database/sqlite/SQLiteDebug$PagerStats;)V",
64 (void*) nativeGetPagerStats },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065};
66
67int register_android_database_SQLiteDebug(JNIEnv *env)
68{
Andreas Gampe987f79f2014-11-18 17:29:46 -080069 jclass clazz = FindClassOrDie(env, "android/database/sqlite/SQLiteDebug$PagerStats");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070
Andreas Gampe987f79f2014-11-18 17:29:46 -080071 gSQLiteDebugPagerStatsClassInfo.memoryUsed = GetFieldIDOrDie(env, clazz, "memoryUsed", "I");
72 gSQLiteDebugPagerStatsClassInfo.largestMemAlloc = GetFieldIDOrDie(env, clazz,
Jeff Brown254fba82012-01-19 17:06:44 -080073 "largestMemAlloc", "I");
Andreas Gampe987f79f2014-11-18 17:29:46 -080074 gSQLiteDebugPagerStatsClassInfo.pageCacheOverflow = GetFieldIDOrDie(env, clazz,
Jeff Brown254fba82012-01-19 17:06:44 -080075 "pageCacheOverflow", "I");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076
Andreas Gampe987f79f2014-11-18 17:29:46 -080077 return RegisterMethodsOrDie(env, "android/database/sqlite/SQLiteDebug",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 gMethods, NELEM(gMethods));
79}
80
81} // namespace android