Merge pull request #7252 from Ebola16/Log

Android: Add Log Configuration to UI
This commit is contained in:
JosJuice 2020-08-02 22:00:48 +02:00 committed by GitHub
commit 234eaa0ff9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 222 additions and 6 deletions

View File

@ -15,6 +15,7 @@ import org.dolphinemu.dolphinemu.utils.Log;
import org.dolphinemu.dolphinemu.utils.Rumble;
import java.lang.ref.WeakReference;
import java.util.LinkedHashMap;
/**
* Class which contains methods that interact
@ -370,6 +371,8 @@ public final class NativeLibrary
public static native int DefaultCPUCore();
public static native int GetMaxLogLevel();
public static native void ReloadConfig();
/**
@ -452,6 +455,10 @@ public final class NativeLibrary
public static native void ReloadWiimoteConfig();
public static native LinkedHashMap<String, String> GetLogTypeNames();
public static native void ReloadLoggerConfig();
public static native boolean InstallWAD(String file);
public static native String FormatSize(long bytes, int decimals);

View File

@ -39,7 +39,6 @@ public abstract class Setting
return mSection;
}
/**
* @return A representation of this Setting's backing value converted to a String (e.g. for serialization).
*/

View File

@ -23,6 +23,9 @@ public class Settings
public static final String SECTION_INI_INTERFACE = "Interface";
public static final String SECTION_INI_DSP = "DSP";
public static final String SECTION_LOGGER_LOGS = "Logs";
public static final String SECTION_LOGGER_OPTIONS = "Options";
public static final String SECTION_GFX_SETTINGS = "Settings";
public static final String SECTION_GFX_ENHANCEMENTS = "Enhancements";
public static final String SECTION_GFX_HACKS = "Hacks";
@ -57,6 +60,8 @@ public class Settings
configFileSectionsMap.put(SettingsFile.FILE_NAME_GFX,
Arrays.asList(SECTION_GFX_SETTINGS, SECTION_GFX_ENHANCEMENTS, SECTION_GFX_HACKS,
SECTION_STEREOSCOPY));
configFileSectionsMap.put(SettingsFile.FILE_NAME_LOGGER,
Arrays.asList(SECTION_LOGGER_LOGS, SECTION_LOGGER_OPTIONS));
configFileSectionsMap.put(SettingsFile.FILE_NAME_WIIMOTE,
Arrays.asList(SECTION_WIIMOTE + 1, SECTION_WIIMOTE + 2, SECTION_WIIMOTE + 3,
SECTION_WIIMOTE + 4));
@ -226,6 +231,7 @@ public class Settings
// Notify the native code of the changes
NativeLibrary.ReloadConfig();
NativeLibrary.ReloadWiimoteConfig();
NativeLibrary.ReloadLoggerConfig();
if (modifiedSettings.contains(SettingsFile.KEY_RECURSIVE_ISO_PATHS))
{

View File

@ -10,6 +10,7 @@ public enum MenuTag
CONFIG_GAME_CUBE("config_gamecube"),
CONFIG_WII("config_wii"),
CONFIG_ADVANCED("config_advanced"),
CONFIG_LOG("config_log"),
WIIMOTE("wiimote"),
WIIMOTE_EXTENSION("wiimote_extension"),
GCPAD_TYPE("gc_pad_type"),

View File

@ -50,6 +50,7 @@ import org.dolphinemu.dolphinemu.utils.Log;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolder>
implements DialogInterface.OnClickListener, SeekBar.OnSeekBarChangeListener
@ -369,6 +370,15 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
sView.onSettingChanged(null);
}
public static void setAllLogTypes(String value)
{
for (Map.Entry<String, String> entry : SettingsFragmentPresenter.LOG_TYPE_NAMES.entrySet())
{
sView.putSetting(new StringSetting(entry.getKey(), Settings.SECTION_LOGGER_LOGS, value));
}
sView.onSettingChanged(null);
}
private void handleMenuTag(MenuTag menuTag, int value)
{
if (menuTag != null)

View File

@ -48,6 +48,7 @@ public final class SettingsFragment extends Fragment implements SettingsFragment
titles.put(MenuTag.GCPAD_TYPE, R.string.grid_menu_gcpad_settings);
titles.put(MenuTag.GRAPHICS, R.string.grid_menu_graphics_settings);
titles.put(MenuTag.HACKS, R.string.hacks_submenu);
titles.put(MenuTag.CONFIG_LOG, R.string.log_submenu);
titles.put(MenuTag.DEBUG, R.string.debug_submenu);
titles.put(MenuTag.ENHANCEMENTS, R.string.enhancements_submenu);
titles.put(MenuTag.STEREOSCOPY, R.string.stereoscopy_submenu);

View File

@ -31,11 +31,16 @@ import org.dolphinemu.dolphinemu.utils.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
public final class SettingsFragmentPresenter
{
private SettingsFragmentView mView;
public static final LinkedHashMap<String, String> LOG_TYPE_NAMES =
NativeLibrary.GetLogTypeNames();
public static final String ARG_CONTROLLER_TYPE = "controller_type";
private MenuTag mMenuTag;
private String mGameID;
@ -176,6 +181,10 @@ public final class SettingsFragmentPresenter
addHackSettings(sl);
break;
case CONFIG_LOG:
addLogConfigurationSettings(sl);
break;
case DEBUG:
addDebugSettings(sl);
break;
@ -223,6 +232,7 @@ public final class SettingsFragmentPresenter
sl.add(new SubmenuSetting(null, null, R.string.gamecube_submenu, MenuTag.CONFIG_GAME_CUBE));
sl.add(new SubmenuSetting(null, null, R.string.wii_submenu, MenuTag.CONFIG_WII));
sl.add(new SubmenuSetting(null, null, R.string.advanced_submenu, MenuTag.CONFIG_ADVANCED));
sl.add(new SubmenuSetting(null, null, R.string.log_submenu, MenuTag.CONFIG_LOG));
sl.add(new SubmenuSetting(null, null, R.string.debug_submenu, MenuTag.DEBUG));
sl.add(new HeaderSetting(null, null, R.string.gametdb_thanks, 0));
}
@ -729,6 +739,36 @@ public final class SettingsFragmentPresenter
fastDepth));
}
private void addLogConfigurationSettings(ArrayList<SettingsItem> sl)
{
SettingSection logsSection = mSettings.getSection(Settings.SECTION_LOGGER_LOGS);
SettingSection optionsSection = mSettings.getSection(Settings.SECTION_LOGGER_OPTIONS);
Setting enableLogging = optionsSection.getSetting(SettingsFile.KEY_ENABLE_LOGGING);
Setting logVerbosity = optionsSection.getSetting(SettingsFile.KEY_LOG_VERBOSITY);
sl.add(new CheckBoxSetting(SettingsFile.KEY_ENABLE_LOGGING, Settings.SECTION_LOGGER_OPTIONS,
R.string.enable_logging, R.string.enable_logging_description, false, enableLogging));
sl.add(new SingleChoiceSetting(SettingsFile.KEY_LOG_VERBOSITY, Settings.SECTION_LOGGER_OPTIONS,
R.string.log_verbosity, 0, getLogVerbosityEntries(), getLogVerbosityValues(), 1,
logVerbosity));
sl.add(new ConfirmRunnable(R.string.log_enable_all, 0, R.string.log_enable_all_confirmation, 0,
() -> SettingsAdapter.setAllLogTypes("True")));
sl.add(
new ConfirmRunnable(R.string.log_disable_all, 0, R.string.log_disable_all_confirmation,
0,
() -> SettingsAdapter.setAllLogTypes("False")));
sl.add(new HeaderSetting(null, null, R.string.log_types, 0));
for (Map.Entry<String, String> entry : LOG_TYPE_NAMES.entrySet())
{
Setting setting = logsSection.getSetting(entry.getKey());
// TitleID is handled by special case in CheckBoxSettingViewHolder.
sl.add(
new CheckBoxSetting(entry.getKey(), Settings.SECTION_LOGGER_LOGS, 0, 0, false,
setting));
}
}
private void addDebugSettings(ArrayList<SettingsItem> sl)
{
SettingSection debugSection = mSettings.getSection(Settings.SECTION_DEBUG);
@ -1599,4 +1639,30 @@ public final class SettingsFragmentPresenter
{
return DirectoryInitialization.getUserDirectory() + "/Wii/sd.raw";
}
private static int getLogVerbosityEntries()
{
// Value obtained from LOG_LEVELS in Common/Logging/Log.h
if (NativeLibrary.GetMaxLogLevel() == 5)
{
return R.array.logVerbosityEntriesMaxLevelDebug;
}
else
{
return R.array.logVerbosityEntriesMaxLevelInfo;
}
}
private static int getLogVerbosityValues()
{
// Value obtained from LOG_LEVELS in Common/Logging/Log.h
if (NativeLibrary.GetMaxLogLevel() == 5)
{
return R.array.logVerbosityValuesMaxLevelDebug;
}
else
{
return R.array.logVerbosityValuesMaxLevelInfo;
}
}
}

View File

@ -5,9 +5,11 @@ import android.widget.CheckBox;
import android.widget.TextView;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.model.view.CheckBoxSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsFragmentPresenter;
public final class CheckBoxSettingViewHolder extends SettingViewHolder
{
@ -36,7 +38,15 @@ public final class CheckBoxSettingViewHolder extends SettingViewHolder
{
mItem = (CheckBoxSetting) item;
mTextSettingName.setText(item.getNameId());
// Special case for LogTypes retrieved via JNI since those aren't string references.
if (item.getNameId() == 0 && item.getSection().equals(Settings.SECTION_LOGGER_LOGS))
{
mTextSettingName.setText(SettingsFragmentPresenter.LOG_TYPE_NAMES.get(item.getKey()));
}
else
{
mTextSettingName.setText(item.getNameId());
}
if (item.getDescriptionId() > 0)
{

View File

@ -36,6 +36,7 @@ public final class SettingsFile
{
public static final String FILE_NAME_DOLPHIN = "Dolphin";
public static final String FILE_NAME_GFX = "GFX";
public static final String FILE_NAME_LOGGER = "Logger";
public static final String FILE_NAME_GCPAD = "GCPadNew";
public static final String FILE_NAME_WIIMOTE = "WiimoteNew";
@ -286,6 +287,9 @@ public final class SettingsFile
public static final String KEY_WIIMOTE_SCAN = "WiimoteContinuousScanning";
public static final String KEY_WIIMOTE_SPEAKER = "WiimoteEnableSpeaker";
public static final String KEY_ENABLE_LOGGING = "WriteToFile";
public static final String KEY_LOG_VERBOSITY = "Verbosity";
private static BiMap<String, String> sectionsMap = new BiMap<>();
static

View File

@ -71,7 +71,7 @@
<item>5</item>
</integer-array>
<!-- Slot A Device Selection -->
<!-- Slot A & B Device selection -->
<string-array name="slotDeviceEntries" translatable="false">
<item>Nothing</item>
<item>Dummy</item>
@ -85,6 +85,34 @@
<item>8</item>
</integer-array>
<!-- Log Verbosity selection based on LOG_LEVELS in Common/Logging/Log.h -->
<string-array name="logVerbosityEntriesMaxLevelInfo" translatable="false">
<item>Notice</item>
<item>Error</item>
<item>Warning</item>
<item>Info</item>
</string-array>
<integer-array name="logVerbosityValuesMaxLevelInfo" translatable="false">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</integer-array>
<string-array name="logVerbosityEntriesMaxLevelDebug" translatable="false">
<item>Notice</item>
<item>Error</item>
<item>Warning</item>
<item>Info</item>
<item>Debug</item>
</string-array>
<integer-array name="logVerbosityValuesMaxLevelDebug" translatable="false">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
</integer-array>
<!-- Video backend selection -->
<string-array name="videoBackendEntries">
<item>OpenGL</item>

View File

@ -265,6 +265,17 @@
<string name="overclock_title">Emulated CPU Clock Speed</string>
<string name="overclock_title_description">Adjusts the emulated CPU\'s clock rate if \"Override Emulated CPU Clock Speed\" is enabled.</string>
<!-- Log Configuration -->
<string name="log_submenu">Log</string>
<string name="enable_logging">Enable Logging</string>
<string name="enable_logging_description">Log messages from enabled log types to dolphin-emu/Logs/. Will decrease performance.</string>
<string name="log_verbosity">Verbosity</string>
<string name="log_enable_all">Enable all Log Types</string>
<string name="log_enable_all_confirmation">Are you sure you want to enable all log types?</string>
<string name="log_disable_all">Disable all Log Types</string>
<string name="log_disable_all_confirmation">Are you sure you want to disable all log types?</string>
<string name="log_types">Log Types</string>
<!-- Debug -->
<string name="debug_submenu">Debug</string>
<string name="debug_warning">Warning: These settings will slow emulation</string>

View File

@ -12,6 +12,7 @@ static JavaVM* s_java_vm;
static jclass s_native_library_class;
static jmethodID s_display_alert_msg;
static jmethodID s_do_rumble;
static jmethodID s_get_update_touch_pointer;
static jclass s_game_file_class;
@ -25,7 +26,9 @@ static jclass s_analytics_class;
static jmethodID s_send_analytics_report;
static jmethodID s_get_analytics_value;
static jmethodID s_do_rumble;
static jclass s_linked_hash_map_class;
static jmethodID s_linked_hash_map_init;
static jmethodID s_linked_hash_map_put;
namespace IDCache
{
@ -62,6 +65,11 @@ jmethodID GetDisplayAlertMsg()
return s_display_alert_msg;
}
jmethodID GetDoRumble()
{
return s_do_rumble;
}
jmethodID GetUpdateTouchPointer()
{
return s_get_update_touch_pointer;
@ -106,9 +114,19 @@ jfieldID GetGameFileCachePointer()
return s_game_file_cache_pointer;
}
jmethodID GetDoRumble()
jclass GetLinkedHashMapClass()
{
return s_do_rumble;
return s_linked_hash_map_class;
}
jmethodID GetLinkedHashMapInit()
{
return s_linked_hash_map_init;
}
jmethodID GetLinkedHashMapPut()
{
return s_linked_hash_map_put;
}
} // namespace IDCache
@ -150,6 +168,12 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
s_get_analytics_value = env->GetStaticMethodID(s_analytics_class, "getValue",
"(Ljava/lang/String;)Ljava/lang/String;");
const jclass map_class = env->FindClass("java/util/LinkedHashMap");
s_linked_hash_map_class = reinterpret_cast<jclass>(env->NewGlobalRef(map_class));
s_linked_hash_map_init = env->GetMethodID(s_linked_hash_map_class, "<init>", "(I)V");
s_linked_hash_map_put = env->GetMethodID(
s_linked_hash_map_class, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
return JNI_VERSION;
}
@ -163,6 +187,7 @@ void JNI_OnUnload(JavaVM* vm, void* reserved)
env->DeleteGlobalRef(s_game_file_class);
env->DeleteGlobalRef(s_game_file_cache_class);
env->DeleteGlobalRef(s_analytics_class);
env->DeleteGlobalRef(s_linked_hash_map_class);
}
#ifdef __cplusplus

View File

@ -28,4 +28,8 @@ jmethodID GetGameFileConstructor();
jclass GetGameFileCacheClass();
jfieldID GetGameFileCachePointer();
jclass GetLinkedHashMapClass();
jmethodID GetLinkedHashMapInit();
jmethodID GetLinkedHashMapPut();
} // namespace IDCache

View File

@ -244,6 +244,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetCacheDire
JNIEnv* env, jobject obj, jstring jDirectory);
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCore(JNIEnv* env,
jobject obj);
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetMaxLogLevel(JNIEnv* env,
jobject obj);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv* env,
jobject obj,
jboolean enable);
@ -549,6 +551,12 @@ JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCo
return static_cast<jint>(PowerPC::DefaultCPUCore());
}
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetMaxLogLevel(JNIEnv* env,
jobject obj)
{
return static_cast<jint>(MAX_LOGLEVEL);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv* env,
jobject obj,
jboolean enable)
@ -753,6 +761,28 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(J
Core::RunAsCPUThread([&path] { DVDInterface::ChangeDisc(path); });
}
JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetLogTypeNames(JNIEnv* env,
jobject obj)
{
std::map<std::string, std::string> map = Common::Log::LogManager::GetInstance()->GetLogTypes();
auto map_size = static_cast<jsize>(map.size());
jobject linked_hash_map =
env->NewObject(IDCache::GetLinkedHashMapClass(), IDCache::GetLinkedHashMapInit(), map_size);
for (const auto& entry : map)
{
env->CallObjectMethod(linked_hash_map, IDCache::GetLinkedHashMapPut(),
ToJString(env, entry.first), ToJString(env, entry.second));
}
return linked_hash_map;
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadLoggerConfig(JNIEnv* env,
jobject obj)
{
Common::Log::LogManager::Init();
}
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_InstallWAD(JNIEnv* env,
jobject obj,
jstring jFile)

View File

@ -239,6 +239,17 @@ bool LogManager::IsEnabled(LOG_TYPE type, LOG_LEVELS level) const
return m_log[type].m_enable && GetLogLevel() >= level;
}
std::map<std::string, std::string> LogManager::GetLogTypes()
{
std::map<std::string, std::string> log_types;
for (const auto& container : m_log)
{
log_types.emplace(container.m_short_name, container.m_full_name);
}
return log_types;
}
const char* LogManager::GetShortName(LOG_TYPE type) const
{
return m_log[type].m_short_name;

View File

@ -6,6 +6,7 @@
#include <array>
#include <cstdarg>
#include <map>
#include "Common/BitSet.h"
#include "Common/Logging/Log.h"
@ -47,6 +48,8 @@ public:
void SetEnable(LOG_TYPE type, bool enable);
bool IsEnabled(LOG_TYPE type, LOG_LEVELS level = LNOTICE) const;
std::map<std::string, std::string> GetLogTypes();
const char* GetShortName(LOG_TYPE type) const;
const char* GetFullName(LOG_TYPE type) const;