Externalize log print

This commit is contained in:
Victor Shcherb 2012-04-30 11:30:04 +02:00
parent fc69ccdbf6
commit 272d52f0a0
11 changed files with 107 additions and 56 deletions

View file

@ -28,22 +28,20 @@
<tool id="cdt.managedbuild.tool.gnu.archiver.base.2094589046" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="com.android.tool.compiler.g++.1543637239" name="Android G++" superClass="com.android.tool.compiler.g++">
<option id="gnu.cpp.compiler.option.include.paths.757537552" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="/home/victor/projects/android-ndk-r6b/sources/cxx-stl/gnu-libstdc++/include"/>
<listOptionValue builtIn="false" value="/home/victor/projects/android/external/skia/include/core"/>
<listOptionValue builtIn="false" value="/home/victor/projects/android/frameworks/base/include"/>
<listOptionValue builtIn="false" value="/home/victor/projects/android/external/skia/include/effects"/>
<listOptionValue builtIn="false" value="/home/victor/projects/android-ndk-r6b/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include"/>
<listOptionValue builtIn="false" value="/home/victor/projects/android-ndk-r6b/platforms/android-8/arch-arm/usr/include/linux/"/>
<listOptionValue builtIn="false" value="/home/victor/projects/android-ndk-r6b/sources/cxx-stl/system/include"/>
<listOptionValue builtIn="false" value="/home/victor/projects/android-ndk-r6b/sources/cxx-stl/stlport/stlport"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/OsmAnd/jni/protobuf}&quot;"/>
<listOptionValue builtIn="false" value="/usr/include"/>
<listOptionValue builtIn="false" value="/home/victor/projects/android-ndk-r7c/sources/cxx-stl/stlport/stlport"/>
<listOptionValue builtIn="false" value="/usr/lib/jvm/java-6-sun-1.6.0.26/include"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Osmand-kernel/protobuf/}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Osmand-kernel/cpufeatures_proxy}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Osmand-kernel/jpeg/jpeg_library}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Osmand-kernel/skia/skia_library}&quot;"/>
<listOptionValue builtIn="false" value="/home/victor/projects/android-ndk-r7c/platforms/android-3/arch-arm/usr/include"/>
<listOptionValue builtIn="false" value="/usr/lib/jvm/java-6-sun-1.6.0.26/include/linux"/>
</option>
<inputType id="com.android.tool.compiler.g++.input.478508689" superClass="com.android.tool.compiler.g++.input"/>
</tool>
<tool id="com.android.tool.compiler.c.1571517563" name="Android GCC" superClass="com.android.tool.compiler.c">
<option id="gnu.c.compiler.option.include.paths.741601891" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="/home/victor/projects/android-ndk-r6b/sources/cxx-stl/gnu-libstdc++/include"/>
</option>
<option id="gnu.c.compiler.option.include.paths.741601891" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath"/>
<inputType id="com.android.tool.compiler.c.input.1589735828" superClass="com.android.tool.compiler.c.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.1072970274" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>

View file

@ -1,4 +1,6 @@
_ANDROID_BUILD := true
OSMAND_MAKEFILES := $(all-subdir-makefiles)
# By default, include makefiles only once
include $(OSMAND_MAKEFILES)

View file

@ -33,6 +33,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) \
$(OSMAND_SKIA_ABS)/src/core
LOCAL_SRC_FILES := \
osmand_log.cpp \
common.cpp \
mapObjects.cpp \
renderRules.cpp \

View file

@ -2,7 +2,8 @@
#define _OSMAND_BINARY_READ
#include <math.h>
#include <android/log.h>
#include <osmand_log.h>
#include <stdio.h>
#include <fstream>
#include <algorithm>
@ -435,11 +436,11 @@ bool initMapStructure(io::CodedInputStream* input, BinaryMapFile* file) {
}
}
if (version != versionConfirm) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Corrupted file. It should be ended as it starts with version");
osmand_log_print(LOG_ERROR, "Corrupted file. It should be ended as it starts with version");
return false;
}
if (version != MAP_VERSION) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Version of the file is not supported.");
osmand_log_print(LOG_ERROR, "Version of the file is not supported.");
return false;
}
return true;
@ -898,7 +899,7 @@ extern "C" JNIEXPORT jint JNICALL Java_net_osmand_plus_render_NativeOsmandLibrar
if (mapLevel->minZoom <= zoom && mapLevel->maxZoom >= zoom) {
if (mapLevel->right >= q.left && q.right >= mapLevel->left && mapLevel->bottom >= q.top
&& q.bottom >= mapLevel->top) {
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Search map %s", mapIndex->name.c_str());
osmand_log_print(LOG_INFO, "Search map %s", mapIndex->name.c_str());
searchMapData(&cis, mapLevel, mapIndex, &q);
}
}
@ -988,7 +989,7 @@ extern "C" JNIEXPORT jint JNICALL Java_net_osmand_plus_render_NativeOsmandLibrar
tempResult.insert(tempResult.end(), basemapResult.begin(), basemapResult.end());
}
searchRes->result.insert(searchRes->result.end(), tempResult.begin(), tempResult.end());
__android_log_print(ANDROID_LOG_INFO, LOG_TAG,
osmand_log_print(LOG_INFO,
"Search : tree - read( %d), accept( %d), objs - visit( %d), accept(%d), in result(%d) ",
q.numberOfReadSubtrees, q.numberOfAcceptedSubtrees, q.numberOfVisitedObjects, q.numberOfAcceptedObjects,
searchRes->result.size());
@ -1025,7 +1026,7 @@ extern "C" JNIEXPORT jboolean JNICALL Java_net_osmand_plus_render_NativeOsmandLi
FILE* file = fopen(inputName.c_str(), "r");
if (file == NULL) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "File could not be open to read from C : %s", inputName.c_str());
osmand_log_print(LOG_ERROR, "File could not be open to read from C : %s", inputName.c_str());
return false;
}
BinaryMapFile* mapFile = new BinaryMapFile();
@ -1035,7 +1036,7 @@ extern "C" JNIEXPORT jboolean JNICALL Java_net_osmand_plus_render_NativeOsmandLi
io::CodedInputStream cis(&input);
cis.SetTotalBytesLimit(INT_MAX, INT_MAX >> 2);
if (!initMapStructure(&cis, mapFile)) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "File not initialised : %s", inputName.c_str());
osmand_log_print(LOG_ERROR, "File not initialised : %s", inputName.c_str());
delete mapFile;
return false;
}

View file

@ -1,15 +1,14 @@
#include <android/log.h>
#include <string>
#include <vector>
#include <hash_map>
#include <SkPath.h>
#include <SkBitmap.h>
#include <SkImageDecoder.h>
#include <jni.h>
#include "common.h"
#include "osmand_log.h"
const char* const LOG_TAG = "net.osmand:native";
JavaVM* globalJVM = NULL;
// Forward declarations
@ -27,14 +26,14 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
loadJniCommon(globalJniEnv);
loadJniRendering(globalJniEnv);
loadJniRenderingRules(globalJniEnv);
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "JNI_OnLoad completed");
osmand_log_print(LOG_INFO, "JNI_OnLoad completed");
return JNI_VERSION_1_6;
}
void throwNewException(JNIEnv* env, const char* msg)
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, msg);
osmand_log_print(LOG_ERROR, msg);
env->ThrowNew(env->FindClass("java/lang/Exception"), msg);
}
@ -194,9 +193,9 @@ void pullFromJavaRenderingContext(JNIEnv* env, jobject jrc, RenderingContext* rc
void pushToJavaRenderingContext(JNIEnv* env, jobject jrc, RenderingContext* rc)
{
env->SetIntField( jrc, jfield_RenderingContext_pointCount, rc->pointCount);
env->SetIntField( jrc, jfield_RenderingContext_pointInsideCount, rc->pointInsideCount);
env->SetIntField( jrc, jfield_RenderingContext_visible, rc->visible);
env->SetIntField( jrc, jfield_RenderingContext_pointCount, (jint) rc->pointCount);
env->SetIntField( jrc, jfield_RenderingContext_pointInsideCount, (jint)rc->pointInsideCount);
env->SetIntField( jrc, jfield_RenderingContext_visible, (jint)rc->visible);
env->SetIntField( jrc, jfield_RenderingContext_allObjects, rc->allObjects);
env->SetIntField( jrc, jfield_RenderingContext_textRenderingTime, rc->textRendering.getElapsedTime());
env->SetIntField( jrc, jfield_RenderingContext_lastRenderedKey, rc->lastRenderedKey);

View file

@ -1,5 +1,4 @@
#include <android/log.h>
#include <stdio.h>
#include <map>
#include <set>
@ -104,7 +103,7 @@ void processCoastlines(std::vector<MapDataObject*>& coastLines, int leftX, int
o->points.push_back(int_pair(leftX, topY));
o->id = dbId;
o->types.push_back(tag_value("natural", "coastline"));
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "!!! Isolated islands !!!");
osmand_log_print(LOG_ERROR, "!!! Isolated islands !!!");
res.push_back(o);
}
@ -270,7 +269,7 @@ void unifyIncompletedRings(std::vector<std::vector<int_pair> >& toProccess, std:
// However this situation could happen because of broken multipolygons (so it should data causes app error)
// that's why these exceptions could be replaced with return; statement.
if (!end || !st) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Error processing multipolygon");
osmand_log_print(LOG_ERROR, "Error processing multipolygon");
toProccess.push_back(*ir);
} else {
nonvisitedRings.insert(j);

View file

@ -0,0 +1,37 @@
#ifndef _OSMAND_LOG_CPP
#define _OSMAND_LOG_CPP
#ifdef _ANDROID_BUILD
#include <android/log.h>
const char* const LOG_TAG = "net.osmand:native";
void osmand_log_print(int type, const char* msg) {
if(type == LOG_ERROR) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, msg);
} else if(type == LOG_INFO) {
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, msg);
} else {
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, msg);
}
}
#else
#include <stdio.h>
#include <stdarg.h>
const char* const LOG_TAG = "net.osmand:native";
void osmand_log_print(int type, const char* msg, ...) {
va_list args;
va_start( args, msg);
// TODO by type
printf(msg, msg, args);
va_end(args);
}
#endif
#endif

View file

@ -0,0 +1,14 @@
#ifndef _OSMAND_LOG_H
#define _OSMAND_LOG_H
typedef enum osmand_LogPriority {
LOG_ERROR = 1,
LOG_WARN,
LOG_DEBUG,
LOG_INFO
} osmand_LogPriority;
//#define _ANDROID_BUILD
void osmand_log_print(int type, const char* msg, ...);
#endif

View file

@ -2,7 +2,7 @@
#define _OSMAND_RENDER_RULES
#include <jni.h>
#include <android/log.h>
#include "osmand_log.h"
#include <iterator>
#include <string>
#include <vector>

View file

@ -1,5 +1,5 @@
#include <jni.h>
#include <android/log.h>
#include "osmand_log.h"
#include <android/bitmap.h>
#include <dlfcn.h>
@ -621,16 +621,16 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
{
module_libjnigraphics = dlopen("jnigraphics", /*RTLD_NOLOAD*/0x0004);
if(!module_libjnigraphics) {
__android_log_print(ANDROID_LOG_WARN, LOG_TAG, "jnigraphics was not found in loaded libraries");
osmand_log_print(LOG_WARN, "jnigraphics was not found in loaded libraries");
module_libjnigraphics = dlopen("jnigraphics", RTLD_NOW);
}
if(!module_libjnigraphics) {
__android_log_print(ANDROID_LOG_WARN, LOG_TAG, "jnigraphics was not loaded in default location");
osmand_log_print(LOG_WARN, "jnigraphics was not loaded in default location");
module_libjnigraphics = dlopen("/system/lib/libjnigraphics.so", RTLD_NOW);
}
if(!module_libjnigraphics)
{
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to load jnigraphics via dlopen, will going to crash");
osmand_log_print(LOG_ERROR, "Failed to load jnigraphics via dlopen, will going to crash");
return NULL;
}
dl_AndroidBitmap_getInfo = (PTR_AndroidBitmap_getInfo)dlsym(module_libjnigraphics, "AndroidBitmap_getInfo");
@ -642,28 +642,28 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
// Gain information about bitmap
AndroidBitmapInfo bitmapInfo;
if(dl_AndroidBitmap_getInfo(ienv, targetBitmap, &bitmapInfo) != ANDROID_BITMAP_RESUT_SUCCESS)
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to execute AndroidBitmap_getInfo");
osmand_log_print(LOG_ERROR, "Failed to execute AndroidBitmap_getInfo");
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Creating SkBitmap in native w:%d h:%d s:%d f:%d!", bitmapInfo.width, bitmapInfo.height, bitmapInfo.stride, bitmapInfo.format);
osmand_log_print(LOG_INFO, "Creating SkBitmap in native w:%d h:%d s:%d f:%d!", bitmapInfo.width, bitmapInfo.height, bitmapInfo.stride, bitmapInfo.format);
SkBitmap* bitmap = new SkBitmap();
if(bitmapInfo.format == ANDROID_BITMAP_FORMAT_RGBA_8888) {
int rowBytes = bitmapInfo.stride;
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Row bytes for RGBA_8888 is %d", rowBytes);
osmand_log_print(LOG_INFO, "Row bytes for RGBA_8888 is %d", rowBytes);
bitmap->setConfig(SkBitmap::kARGB_8888_Config, bitmapInfo.width, bitmapInfo.height, rowBytes);
} else if(bitmapInfo.format == ANDROID_BITMAP_FORMAT_RGB_565) {
int rowBytes = bitmapInfo.stride;
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Row bytes for RGB_565 is %d", rowBytes);
osmand_log_print(LOG_INFO, "Row bytes for RGB_565 is %d", rowBytes);
bitmap->setConfig(SkBitmap::kRGB_565_Config, bitmapInfo.width, bitmapInfo.height, rowBytes);
} else {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Unknown target bitmap format");
osmand_log_print(LOG_ERROR, "Unknown target bitmap format");
}
void* lockedBitmapData = NULL;
if(dl_AndroidBitmap_lockPixels(ienv, targetBitmap, &lockedBitmapData) != ANDROID_BITMAP_RESUT_SUCCESS || !lockedBitmapData) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to execute AndroidBitmap_lockPixels");
osmand_log_print(LOG_ERROR, "Failed to execute AndroidBitmap_lockPixels");
}
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Locked %d bytes at %p", bitmap->getSize(), lockedBitmapData);
osmand_log_print(LOG_INFO, "Locked %d bytes at %p", bitmap->getSize(), lockedBitmapData);
bitmap->setPixels(lockedBitmapData);
@ -672,7 +672,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
SkPaint* paint = new SkPaint;
paint->setAntiAlias(true);
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Initializing rendering");
osmand_log_print(LOG_INFO, "Initializing rendering");
ElapsedTimer initObjects;
initObjects.start();
@ -683,7 +683,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
SearchResult* result = ((SearchResult*) searchResult);
// std::vector <BaseMapDataObject* > mapDataObjects = marshalObjects(binaryMapDataObjects);
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Rendering image");
osmand_log_print(LOG_INFO, "Rendering image");
initObjects.pause();
@ -695,9 +695,9 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
rc.nativeOperations.pause();
pushToJavaRenderingContext(ienv, renderingContext, &rc);
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "End Rendering image");
osmand_log_print(LOG_INFO, "End Rendering image");
if(dl_AndroidBitmap_unlockPixels(ienv, targetBitmap) != ANDROID_BITMAP_RESUT_SUCCESS) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to execute AndroidBitmap_unlockPixels");
osmand_log_print(LOG_ERROR, "Failed to execute AndroidBitmap_unlockPixels");
}
// delete variables
@ -712,9 +712,9 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
jmethodID resultClassCtorId = ienv->GetMethodID(resultClass, "<init>", "(Ljava/nio/ByteBuffer;)V");
#ifdef DEBUG_NAT_OPERATIONS
__android_log_print(ANDROID_LOG_INFO, LOG_TAG,"Native ok (init %d, native op %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime());
osmand_log_print(LOG_INFO, LOG_TAG,"Native ok (init %d, native op %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime());
#else
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime());
osmand_log_print(LOG_INFO, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime());
#endif
/* Construct a result object */
@ -730,7 +730,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
jint requestedBitmapWidth, jint requestedBitmapHeight, jint rowBytes, jboolean isTransparent,
jboolean useEnglishNames, jobject renderingRuleSearchRequest, jint defaultColor) {
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Creating SkBitmap in native w:%d h:%d!", requestedBitmapWidth, requestedBitmapHeight);
osmand_log_print(LOG_INFO, "Creating SkBitmap in native w:%d h:%d!", requestedBitmapWidth, requestedBitmapHeight);
SkBitmap* bitmap = new SkBitmap();
if(isTransparent == JNI_TRUE)
@ -747,7 +747,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
bitmapDataSize = bitmap->getSize();
bitmapData = malloc(bitmapDataSize);
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Allocated %d bytes at %p", bitmapDataSize, bitmapData);
osmand_log_print(LOG_INFO, "Allocated %d bytes at %p", bitmapDataSize, bitmapData);
}
bitmap->setPixels(bitmapData);
@ -757,7 +757,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
SkPaint* paint = new SkPaint;
paint->setAntiAlias(true);
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Initializing rendering");
osmand_log_print(LOG_INFO, "Initializing rendering");
ElapsedTimer initObjects;
initObjects.start();
@ -768,7 +768,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
SearchResult* result = ((SearchResult*) searchResult);
// std::vector <BaseMapDataObject* > mapDataObjects = marshalObjects(binaryMapDataObjects);
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Rendering image");
osmand_log_print(LOG_INFO, "Rendering image");
initObjects.pause();
@ -780,7 +780,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
rc.nativeOperations.pause();
pushToJavaRenderingContext(ienv, renderingContext, &rc);
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "End Rendering image");
osmand_log_print(LOG_INFO, "End Rendering image");
// delete variables
delete paint;
@ -794,9 +794,9 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
jmethodID resultClassCtorId = ienv->GetMethodID(resultClass, "<init>", "(Ljava/nio/ByteBuffer;)V");
#ifdef DEBUG_NAT_OPERATIONS
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Native ok (init %d, native op %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime());
osmand_log_print(LOG_INFO, "Native ok (init %d, native op %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime());
#else
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime());
osmand_log_print(LOG_INFO, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime());
#endif
// Allocate ctor paramters

View file

@ -6,7 +6,7 @@ function download {
cd ~/wiki/src;
download en English;
download de German;
download nl Netherlands;
download nl Dutch;
download fr French;
download ru Russian;
download es Spanish;