diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2015-03-18 09:04:06 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:40:31 +0300 |
commit | 7e8f0172e81bd448c8c2419b66a2881d85a89c62 (patch) | |
tree | fa009ce5da259e0a7ef060abb9d336fe1a079df9 | |
parent | db109e51a06bfad840f725f2aa76e8bceba20239 (diff) |
Fixes after colleagues comments
-rw-r--r-- | android/jni/com/mapswithme/core/logging.cpp | 6 | ||||
-rw-r--r-- | android/jni/com/mapswithme/maps/MapFragment.cpp | 2 | ||||
-rw-r--r-- | android/jni/com/mapswithme/platform/Platform.cpp | 25 | ||||
-rw-r--r-- | android/src/com/mapswithme/util/log/MemLogging.java | 26 | ||||
-rw-r--r-- | iphone/Maps/Classes/MapViewController.mm | 11 | ||||
-rw-r--r-- | iphone/Maps/main.mm | 4 | ||||
-rw-r--r-- | platform/file_logging.cpp | 58 | ||||
-rw-r--r-- | platform/file_logging.hpp | 19 | ||||
-rw-r--r-- | platform/platform.hpp | 4 | ||||
-rw-r--r-- | platform/platform.pro | 24 | ||||
-rw-r--r-- | platform/platform_ios.mm | 13 | ||||
-rw-r--r-- | std/chrono.hpp | 2 |
12 files changed, 107 insertions, 87 deletions
diff --git a/android/jni/com/mapswithme/core/logging.cpp b/android/jni/com/mapswithme/core/logging.cpp index 0539454224..e640cf95c9 100644 --- a/android/jni/com/mapswithme/core/logging.cpp +++ b/android/jni/com/mapswithme/core/logging.cpp @@ -3,11 +3,13 @@ #include <android/log.h> #include <cassert> -#include "../../../../../base/logging.hpp" #include "../../../../../base/exception.hpp" +#include "../../../../../base/logging.hpp" + #include "../../../../../coding/file_writer.hpp" -#include "../../../../../platform/platform.hpp" + #include "../../../../../platform/file_logging.hpp" +#include "../../../../../platform/platform.hpp" namespace jni diff --git a/android/jni/com/mapswithme/maps/MapFragment.cpp b/android/jni/com/mapswithme/maps/MapFragment.cpp index 5e90487ad5..dbe834e1ea 100644 --- a/android/jni/com/mapswithme/maps/MapFragment.cpp +++ b/android/jni/com/mapswithme/maps/MapFragment.cpp @@ -54,7 +54,7 @@ extern "C" if (speed > 0.0) info.m_speed = speed; - LogMemoryInfo(); + LOG_MEMORY_INFO(); g_framework->OnLocationUpdated(info); } diff --git a/android/jni/com/mapswithme/platform/Platform.cpp b/android/jni/com/mapswithme/platform/Platform.cpp index 2e3a891583..0e13f6cc6d 100644 --- a/android/jni/com/mapswithme/platform/Platform.cpp +++ b/android/jni/com/mapswithme/platform/Platform.cpp @@ -19,10 +19,7 @@ string Platform::UniqueClientId() const { JNIEnv * env = jni::GetEnv(); if (!env) - { - LOG(LWARNING, ("Can't get JNIEnv")); - return ""; - } + return string(); jclass uuidClass = env->FindClass("java/util/UUID"); ASSERT(uuidClass, ("Can't find java class java/util/UUID")); @@ -58,31 +55,25 @@ string Platform::UniqueClientId() const string Platform::GetMemoryInfo() const { JNIEnv * env = jni::GetEnv(); - if (!env) - { - LOG(LWARNING, ("Can't get JNIEnv")); - return string(""); - } + if (env == nullptr) + return string(); - jclass memLoggingClass = env->FindClass("com/mapswithme/util/log/MemLogging"); - ASSERT(memLoggingClass, ()); + static shared_ptr<jobject> classMemLogging = jni::make_global_ref(env->FindClass("com/mapswithme/util/log/MemLogging")); + ASSERT(classMemLogging, ()); - jmethodID getMemoryInfoId = env->GetStaticMethodID(memLoggingClass, "GetMemoryInfo", "()Ljava/lang/String;"); + static jmethodID const getMemoryInfoId = env->GetStaticMethodID(static_cast<jclass>(*classMemLogging.get()), "getMemoryInfo", "()Ljava/lang/String;"); ASSERT(getMemoryInfoId, ()); - jstring memInfoString = (jstring)env->CallStaticObjectMethod(memLoggingClass, getMemoryInfoId); + jstring const memInfoString = (jstring)env->CallStaticObjectMethod(static_cast<jclass>(*classMemLogging.get()), getMemoryInfoId); ASSERT(memInfoString, ()); - string res = jni::ToNativeString(env, memInfoString); - - return res; + return jni::ToNativeString(env, memInfoString); } void Platform::RunOnGuiThread(TFunctor const & fn) { android::Platform::RunOnGuiThreadImpl(fn); } - namespace android { void Platform::Initialize(JNIEnv * env, diff --git a/android/src/com/mapswithme/util/log/MemLogging.java b/android/src/com/mapswithme/util/log/MemLogging.java index 1800657150..efc281ecf9 100644 --- a/android/src/com/mapswithme/util/log/MemLogging.java +++ b/android/src/com/mapswithme/util/log/MemLogging.java @@ -11,27 +11,27 @@ import java.util.Date; public class MemLogging { - public static String GetMemoryInfo() + public static String getMemoryInfo() { final Debug.MemoryInfo debugMI = new Debug.MemoryInfo(); Debug.getMemoryInfo(debugMI); final ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); - final Context content = MWMApplication.get().getApplicationContext(); final ActivityManager activityManager = - (ActivityManager) content.getSystemService(content.ACTIVITY_SERVICE); + (ActivityManager) MWMApplication.get().getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); - StringBuilder log = new StringBuilder("Memory info: " + - " Debug.getNativeHeapSize() = " + Debug.getNativeHeapSize() / 1024 + - "KB; Debug.getNativeHeapAllocatedSize() = " + Debug.getNativeHeapAllocatedSize() / 1024 + - "KB; Debug.getNativeHeapFreeSize() = " + Debug.getNativeHeapFreeSize() / 1024 + - "KB; debugMI.getTotalPrivateDirty() = " + debugMI.getTotalPrivateDirty() + - "KB; debugMI.getTotalPss() = " + debugMI.getTotalPss() + - "KB; mi.availMem = " + mi.availMem / 1024 + - "KB; mi.threshold = " + mi.threshold / 1024 + - "KB; mi.lowMemory = " + mi.lowMemory); + + StringBuilder log = new StringBuilder("Memory info: "); + log.append(" Debug.getNativeHeapSize() = ").append(Debug.getNativeHeapSize() / 1024) + .append("KB; Debug.getNativeHeapAllocatedSize() = ").append(Debug.getNativeHeapAllocatedSize() / 1024) + .append("KB; Debug.getNativeHeapFreeSize() = ").append(Debug.getNativeHeapFreeSize() / 1024) + .append("KB; debugMI.getTotalPrivateDirty() = ").append(debugMI.getTotalPrivateDirty()) + .append("KB; debugMI.getTotalPss() = ").append(debugMI.getTotalPss()) + .append("KB; mi.availMem = ").append(mi.availMem / 1024) + .append("KB; mi.threshold = ").append(mi.threshold / 1024) + .append("KB; mi.lowMemory = ").append(mi.lowMemory); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - log.append(" mi.totalMem = " + mi.totalMem / 1024 + "KB."); + log.append(" mi.totalMem = ").append(mi.totalMem / 1024).append("KB;"); } return log.toString(); } diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 06bca27e54..1cea72b7df 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -24,13 +24,16 @@ #include "../../../anim/controller.hpp" #include "../../../gui/controller.hpp" -#include "../../../platform/platform.hpp" #include "../Statistics/Statistics.h" + +#include "../../../map/country_status_display.hpp" #include "../../../map/dialog_settings.hpp" #include "../../../map/user_mark.hpp" -#include "../../../map/country_status_display.hpp" -#include "../../../platform/settings.hpp" + #include "../../../platform/file_logging.hpp" +#include "../../../platform/platform.hpp" +#include "../../../platform/settings.hpp" + #define ALERT_VIEW_FACEBOOK 1 #define ALERT_VIEW_APPSTORE 2 @@ -134,7 +137,7 @@ [m_predictor reset:info]; Framework & frm = GetFramework(); frm.OnLocationUpdate(info); - LogMemoryInfo(); + LOG_MEMORY_INFO(); [self showPopover]; [self updateRoutingInfo]; diff --git a/iphone/Maps/main.mm b/iphone/Maps/main.mm index 779d1979d4..1322db166d 100644 --- a/iphone/Maps/main.mm +++ b/iphone/Maps/main.mm @@ -2,9 +2,9 @@ #import <Foundation/Foundation.h> #import <Foundation/NSThread.h> -#include "../../platform/settings.hpp" -#include "../../platform/platform.hpp" #include "../../platform/file_logging.hpp" +#include "../../platform/platform.hpp" +#include "../../platform/settings.hpp" /// Used to trick iOs and enable multithreading support with non-native pthreads. diff --git a/platform/file_logging.cpp b/platform/file_logging.cpp index edaef6a4af..4bc391bf41 100644 --- a/platform/file_logging.cpp +++ b/platform/file_logging.cpp @@ -1,38 +1,52 @@ #include "file_logging.hpp" -#include "../base/mutex.hpp" - -#include "../std/chrono.hpp" +#include "../std/mutex.hpp" #include "../coding/file_writer.hpp" #include "../platform/platform.hpp" +namespace +{ + tm * GetLocalTime() + { + time_t rawTime; + time(&rawTime); + tm * localTime = localtime(&rawTime); + assert(localTime); + return localTime; + } +} void LogMessageFile(my::LogLevel level, my::SrcPoint const & srcPoint, string const & msg) { - static threads::Mutex mutex; + static mutex mtx; + static unique_ptr<FileWriter> file; - threads::MutexGuard guard(mutex); - UNUSED_VALUE(guard); + string recordType; + switch (level) + { + case LINFO: recordType.assign("INFO "); break; + case LDEBUG: recordType.assign("DEBUG "); break; + case LWARNING: recordType.assign("WARN "); break; + case LERROR: recordType.assign("ERROR "); break; + case LCRITICAL: recordType.assign("FATAL "); break; + } - static unique_ptr<FileWriter> file; + lock_guard<mutex> lock(mtx); if (file == nullptr) { if (GetPlatform().WritableDir().empty()) return; - auto const curTime = system_clock::now(); - time_t const curCTime = system_clock::to_time_t(curTime); - tm * curTimeTM = localtime(&curCTime); - assert(curTimeTM != nullptr); + tm * curTimeTM = GetLocalTime(); stringstream fileName; fileName << "logging_" << curTimeTM->tm_year + 1900 << "_" << curTimeTM->tm_mon + 1 << "_" << curTimeTM->tm_mday << "_" - << curTimeTM->tm_hour << "_" << curTimeTM->tm_min << "_" << curTimeTM->tm_sec << ".txt"; + << curTimeTM->tm_hour << "_" << curTimeTM->tm_min << "_" << curTimeTM->tm_sec << ".log"; file.reset(new FileWriter(GetPlatform().WritablePathForFile(fileName.str()))); } - string srcString = DebugPrint(srcPoint) + " " + msg + "\n"; + string srcString = recordType + DebugPrint(srcPoint) + " " + msg + "\n"; file->Write(srcString.c_str(), srcString.size()); file->Flush(); @@ -40,20 +54,14 @@ void LogMessageFile(my::LogLevel level, my::SrcPoint const & srcPoint, string co void LogMemoryInfo() { -#ifdef DEBUG static unsigned long counter = 0; - const unsigned short writeLogEveryNthLocationUpdate = 3; - if (counter % writeLogEveryNthLocationUpdate == 0) + const unsigned short writeLogEveryNthCall = 3; + if (counter++ % writeLogEveryNthCall == 0) { - auto const curTime = system_clock::now(); - time_t const curCTime = system_clock::to_time_t(curTime); - tm * curTimeTM = localtime(&curCTime); - ASSERT(curTimeTM != nullptr, ()); - stringstream fileName; - fileName << " " << curTimeTM->tm_year + 1900 << "." << curTimeTM->tm_mon + 1 << "." << curTimeTM->tm_mday << " " + tm * curTimeTM = GetLocalTime(); + stringstream timeDate; + timeDate << " " << curTimeTM->tm_year + 1900 << "." << curTimeTM->tm_mon + 1 << "." << curTimeTM->tm_mday << " " << curTimeTM->tm_hour << ":" << curTimeTM->tm_min << ":" << curTimeTM->tm_sec << " "; - LOG(LDEBUG, (fileName.str(), GetPlatform().GetMemoryInfo())); + LOG(LINFO, (timeDate.str(), GetPlatform().GetMemoryInfo())); } - ++counter; -#endif } diff --git a/platform/file_logging.hpp b/platform/file_logging.hpp index 7887a171e8..893342b4ee 100644 --- a/platform/file_logging.hpp +++ b/platform/file_logging.hpp @@ -2,9 +2,26 @@ #include "../base/logging.hpp" + +// @todo this functionality is not located in logging.hpp since file_logging uses FileWriter which depends on coding lib. +// At the same time loging is located in base and I do not want base depens on several more libs. +// Probably it's a good idea to move all logging functionality (logging, file_logging, mem_logging and so on) +// to a special subsystem which depends on base and coding. + // If you uncomment the line bellow the application log will be written to a file. -// You'll fild the file in MapsWithMe directory on Android platform and in Documents on iOS. +// You'll find a log file (logging_<date><time>.log) in the MapsWithMe directory on Android platform and in Documents on iOS. // #define MWM_LOG_TO_FILE +// Writing information about free memory to log file. +#ifdef DEBUG +# define OMIM_ENABLE_LOG_MEMORY_INFO +#endif + void LogMessageFile(my::LogLevel level, my::SrcPoint const & srcPoint, string const & msg); void LogMemoryInfo(); + +#ifdef OMIM_ENABLE_LOG_MEMORY_INFO +# define LOG_MEMORY_INFO() LogMemoryInfo() +#else +# define LOG_MEMORY_INFO() do {} while(false) +#endif diff --git a/platform/platform.hpp b/platform/platform.hpp index c1e6769faf..2e2654068a 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -164,8 +164,8 @@ public: bool IsTablet() const { return m_isTablet; } - /// @return information about kinds of memory which are relevant for a platform - /// This methid is implemented for iOS and Android only + /// @return information about kinds of memory which are relevant for a platform. + /// This methid is implemented for iOS and Android only. string GetMemoryInfo() const; private: diff --git a/platform/platform.pro b/platform/platform.pro index dba33ba767..a43fa7a5be 100644 --- a/platform/platform.pro +++ b/platform/platform.pro @@ -62,24 +62,24 @@ macx-*|iphone* { # common sources for all platforms HEADERS += \ - platform.hpp \ + chunks_download_strategy.hpp \ + constants.hpp \ + file_logging.hpp \ + http_request.hpp \ + http_thread_callback.hpp \ location.hpp \ + platform.hpp \ preferred_languages.hpp \ + servers_list.hpp \ settings.hpp \ video_timer.hpp \ - http_request.hpp \ - http_thread_callback.hpp \ - chunks_download_strategy.hpp \ - servers_list.hpp \ - constants.hpp \ - file_logging.hpp \ SOURCES += \ - preferred_languages.cpp \ - settings.cpp \ - video_timer.cpp \ - http_request.cpp \ chunks_download_strategy.cpp \ + file_logging.cpp \ + http_request.cpp \ platform.cpp \ + preferred_languages.cpp \ servers_list.cpp \ - file_logging.cpp \ + settings.cpp \ + video_timer.cpp \ diff --git a/platform/platform_ios.mm b/platform/platform_ios.mm index b0f9481afa..1a8e99869d 100644 --- a/platform/platform_ios.mm +++ b/platform/platform_ios.mm @@ -4,10 +4,14 @@ #include "../coding/file_reader.hpp" -#include <sys/types.h> +#include <ifaddrs.h> + +#import <mach/mach.h> + #include <sys/socket.h> #include <sys/stat.h> -#include <ifaddrs.h> +#include <sys/types.h> + #include <net/if_dl.h> #include <net/if.h> @@ -15,8 +19,6 @@ #define IFT_ETHER 0x6 /* Ethernet CSMACD */ #endif -#import <mach/mach.h> - #import <Foundation/NSAutoreleasePool.h> #import <Foundation/NSBundle.h> #import <Foundation/NSPathUtilities.h> @@ -161,13 +163,12 @@ string Platform::GetMemoryInfo() const ss << "Memory info: Resident_size = " << info.resident_size / 1024 << "KB; virtual_size = " << info.resident_size / 1024 << "KB; suspend_count = " << info.suspend_count << " policy = " << info.policy; - return ss.str(); } else { ss << "Error with task_info(): " << mach_error_string(kerr); - return ss.str(); } + return ss.str(); } void Platform::RunOnGuiThread(TFunctor const & fn) diff --git a/std/chrono.hpp b/std/chrono.hpp index d93f8ad24f..140a053396 100644 --- a/std/chrono.hpp +++ b/std/chrono.hpp @@ -11,8 +11,6 @@ using std::chrono::duration_cast; using std::chrono::high_resolution_clock; using std::chrono::milliseconds; using std::chrono::nanoseconds; -using std::chrono::duration_cast; -using std::chrono::system_clock; #ifdef DEBUG_NEW #define new DEBUG_NEW |