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 | |
Jeff Brown | 254fba8 | 2012-01-19 17:06:44 -0800 | [diff] [blame] | 17 | #define LOG_TAG "SQLiteDebug" |
| 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | #include <jni.h> |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 20 | #include <nativehelper/JNIHelp.h> |
Jeff Brown | 254fba8 | 2012-01-19 17:06:44 -0800 | [diff] [blame] | 21 | #include <android_runtime/AndroidRuntime.h> |
| 22 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <unistd.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | #include <utils/Log.h> |
| 28 | |
| 29 | #include <sqlite3.h> |
| 30 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 31 | #include "core_jni_helpers.h" |
| 32 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | namespace android { |
| 34 | |
Jeff Brown | 254fba8 | 2012-01-19 17:06:44 -0800 | [diff] [blame] | 35 | static struct { |
| 36 | jfieldID memoryUsed; |
| 37 | jfieldID pageCacheOverflow; |
| 38 | jfieldID largestMemAlloc; |
| 39 | } gSQLiteDebugPagerStatsClassInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
Jeff Brown | 254fba8 | 2012-01-19 17:06:44 -0800 | [diff] [blame] | 41 | static void nativeGetPagerStats(JNIEnv *env, jobject clazz, jobject statsObj) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | { |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 43 | int memoryUsed; |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 44 | int pageCacheOverflow; |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 45 | int largestMemAlloc; |
| 46 | int unused; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
Vasu Nori | c384920 | 2010-03-09 10:47:25 -0800 | [diff] [blame] | 48 | sqlite3_status(SQLITE_STATUS_MEMORY_USED, &memoryUsed, &unused, 0); |
| 49 | sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &unused, &largestMemAlloc, 0); |
Jeff Brown | 2a293b6 | 2012-01-19 14:02:22 -0800 | [diff] [blame] | 50 | sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &pageCacheOverflow, &unused, 0); |
Jeff Brown | 254fba8 | 2012-01-19 17:06:44 -0800 | [diff] [blame] | 51 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | } |
| 56 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | /* |
| 58 | * JNI registration. |
| 59 | */ |
| 60 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 61 | static const JNINativeMethod gMethods[] = |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | { |
Jeff Brown | 254fba8 | 2012-01-19 17:06:44 -0800 | [diff] [blame] | 63 | { "nativeGetPagerStats", "(Landroid/database/sqlite/SQLiteDebug$PagerStats;)V", |
| 64 | (void*) nativeGetPagerStats }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | int register_android_database_SQLiteDebug(JNIEnv *env) |
| 68 | { |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 69 | jclass clazz = FindClassOrDie(env, "android/database/sqlite/SQLiteDebug$PagerStats"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 71 | gSQLiteDebugPagerStatsClassInfo.memoryUsed = GetFieldIDOrDie(env, clazz, "memoryUsed", "I"); |
| 72 | gSQLiteDebugPagerStatsClassInfo.largestMemAlloc = GetFieldIDOrDie(env, clazz, |
Jeff Brown | 254fba8 | 2012-01-19 17:06:44 -0800 | [diff] [blame] | 73 | "largestMemAlloc", "I"); |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 74 | gSQLiteDebugPagerStatsClassInfo.pageCacheOverflow = GetFieldIDOrDie(env, clazz, |
Jeff Brown | 254fba8 | 2012-01-19 17:06:44 -0800 | [diff] [blame] | 75 | "pageCacheOverflow", "I"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 77 | return RegisterMethodsOrDie(env, "android/database/sqlite/SQLiteDebug", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | gMethods, NELEM(gMethods)); |
| 79 | } |
| 80 | |
| 81 | } // namespace android |