Skip to content

Commit

Permalink
format to google style
Browse files Browse the repository at this point in the history
  • Loading branch information
guanchu.shen committed Aug 20, 2021
1 parent 1096959 commit b335c49
Show file tree
Hide file tree
Showing 18 changed files with 217 additions and 229 deletions.
2 changes: 1 addition & 1 deletion koom-thread-leak/src/main/cpp/src/common/callstack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ std::string CallStack::SymbolizePc(uintptr_t pc, int index) {
}
std::string format;
unwindstack::FrameData data = unwinder->BuildFrameFromPcOnly(pc);
if (data.map_name.find("libkoom-thread") != string::npos) {
if (data.map_name.find("libkoom-thread") != std::string::npos) {
inSymbolize = false;
return "";
}
Expand Down
32 changes: 16 additions & 16 deletions koom-thread-leak/src/main/cpp/src/include/common/callstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@
*
*/

#ifndef APM_CALLSTACK_H
#define APM_CALLSTACK_H
#ifndef KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_CALLSTACK_H_
#define KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_CALLSTACK_H_

#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/ostream"
#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/sstream"
#include "util.h"
#include "constant.h"
#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/unistd.h"
#include "../../../../../../../koom-common/kwai-unwind/src/main/cpp/include/fast_unwind/fast_unwind.h"
#include "../../../../../../../koom-common/kwai-unwind/src/main/cpp/libunwindstack/include/unwindstack/Unwinder.h"
#include <common/constant.h>
#include <common/util.h>
#include <fast_unwind/fast_unwind.h>
#include <unistd.h>
#include <unwindstack/Unwinder.h>

#include <ostream>
#include <sstream>
#include <string>

namespace koom {

using dump_java_stack_above_o_ptr = void (*)(void *, std::ostream &os, bool, bool);
using dump_java_stack_above_o_ptr = void (*)(void *, std::ostream &os, bool,
bool);
using dump_java_stack_ptr = void (*)(void *, std::ostream &os);

class CallStack {

enum Type {
java, native
};
enum Type { java, native };

private:
static dump_java_stack_above_o_ptr dump_java_stack_above_o;
Expand Down Expand Up @@ -67,6 +67,6 @@ class CallStack {
static void *GetCurrentThread();
};

}
} // namespace koom

#endif //APM_CALLSTACK_H
#endif // KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_CALLSTACK_H_
18 changes: 9 additions & 9 deletions koom-thread-leak/src/main/cpp/src/include/common/constant.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
*
*/

#ifndef APM_RESDETECTOR_CONSTANT_H
#define APM_RESDETECTOR_CONSTANT_H
#ifndef KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_CONSTANT_H_
#define KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_CONSTANT_H_

#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/string"
#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/vector"
#include <string>
#include <vector>

namespace koom {

namespace Constant {
#define ALWAYS_INLINE __attribute__((always_inline))

const static int kMaxCallStackDepth = 18;
const static int kDlopenSourceInit = 0;
}
}
#endif //APM_RESDETECTOR_CONSTANT_H
static const int kMaxCallStackDepth = 18;
static const int kDlopenSourceInit = 0;
} // namespace Constant
} // namespace koom
#endif // KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_CONSTANT_H_
12 changes: 6 additions & 6 deletions koom-thread-leak/src/main/cpp/src/include/common/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
*
*/

#ifndef APM_LOG_H
#define APM_LOG_H
#ifndef KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_LOG_H_
#define KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_LOG_H_

#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/stdio.h"
#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/android/log.h"
#include <stdio.h>
#include <android/log.h>

namespace koom {

Expand Down Expand Up @@ -62,6 +62,6 @@ class Log {

static const int kMaxLogLine = 512;
};
}
} // namespace koom

#endif //APM_LOG_H
#endif // KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_LOG_H_
10 changes: 7 additions & 3 deletions koom-thread-leak/src/main/cpp/src/include/common/looper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
* Created by shenvsv on 2021.
*
*/
#ifndef KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_LOOPER_H_
#define KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_LOOPER_H_

#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/pthread.h"
#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/semaphore.h"
#include <pthread.h>
#include <semaphore.h>
struct LooperMessage;
class looper {
public:
Expand All @@ -37,4 +39,6 @@ class looper {
sem_t headWriteProtect;
sem_t headDataAvailable;
bool running;
};
};

#endif // KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_LOOPER_H_
44 changes: 20 additions & 24 deletions koom-thread-leak/src/main/cpp/src/include/common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,38 @@
*
*/

#ifndef APM_UTIL_H
#define APM_UTIL_H
#ifndef KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_UTIL_H_
#define KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_UTIL_H_

#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/string"
#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/set"
#include "log.h"
#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/vector"
#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/map"
#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/fstream"
#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/streambuf"
#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/dirent.h"
#include "../../../../../../../../../../../sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/jni.h"
#include <common/log.h>
#include <dirent.h>
#include <jni.h>

#include <fstream>
#include <map>
#include <set>
#include <streambuf>
#include <string>
#include <vector>

namespace koom {

class Util {

public:
static int android_api;

static void Init() {
android_api = android_get_device_api_level();
}
static void Init() { android_api = android_get_device_api_level(); }

static int AndroidApi() {
return android_api;
}
static int AndroidApi() { return android_api; }

static timespec CurrentClockTime() {
struct timespec now_time{};
struct timespec now_time {};
clock_gettime(CLOCK_MONOTONIC, &now_time);
return now_time;
}

static long long CurrentTimeNs() {
struct timespec now_time{};
static int64_t CurrentTimeNs() {
struct timespec now_time {};
clock_gettime(CLOCK_MONOTONIC, &now_time);
return now_time.tv_sec * 1000000000LL + now_time.tv_nsec;
}
Expand All @@ -67,10 +63,10 @@ class Util {
prev_pos = ++pos;
}

output.push_back(s.substr(prev_pos, pos - prev_pos)); // Last word
output.push_back(s.substr(prev_pos, pos - prev_pos)); // Last word

return output;
}
};
}
#endif //APM_UTIL_H
} // namespace koom
#endif // KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_COMMON_UTIL_H_
8 changes: 4 additions & 4 deletions koom-thread-leak/src/main/cpp/src/include/koom.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*
*/

#ifndef APM_KOOM_H
#define APM_KOOM_H
#ifndef KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_KOOM_H_
#define KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_KOOM_H_

#include <jni.h>
#include "include/thread/hook_looper.h"
Expand Down Expand Up @@ -52,6 +52,6 @@ extern void Refresh();
JNIEnv *GetEnv(bool doAttach = true);

void JavaCallback(const char *value, bool doAttach = true);
}
} // namespace koom

#endif //APM_KOOM_H
#endif // KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_KOOM_H_
13 changes: 7 additions & 6 deletions koom-thread-leak/src/main/cpp/src/include/thread/hook_looper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
*
*/

#ifndef APM_KOOM_THREAD_SRC_MAIN_CPP_SRC_THREAD_HOOK_LOOPER_H_
#define APM_KOOM_THREAD_SRC_MAIN_CPP_SRC_THREAD_HOOK_LOOPER_H_
#ifndef KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_THREAD_HOOK_LOOPER_H_
#define KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_THREAD_HOOK_LOOPER_H_

#include <common/looper.h>
#include <jni.h>
#include <thread/thread_holder.h>

#include <map>
#include "include/common/looper.h"
#include "thread_holder.h"
namespace koom {
class HookLooper : public looper {
public:
Expand All @@ -33,5 +34,5 @@ class HookLooper : public looper {
void handle(int what, void *data);
void post(int what, void *data);
};
}
#endif //APM_KOOM_THREAD_SRC_MAIN_CPP_SRC_THREAD_HOOK_LOOPER_H_
} // namespace koom
#endif // KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_THREAD_HOOK_LOOPER_H_
38 changes: 16 additions & 22 deletions koom-thread-leak/src/main/cpp/src/include/thread/loop_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
*
*/

#ifndef KOOM_KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_THREAD_LOOP_ITEM_H_
#define KOOM_KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_THREAD_LOOP_ITEM_H_
#ifndef KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_THREAD_LOOP_ITEM_H_
#define KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_THREAD_LOOP_ITEM_H_

#include <string>
namespace koom {
enum HookAction {
ACTION_ADD_THREAD,
Expand All @@ -38,31 +40,27 @@ class ThreadCreateArg {
std::ostringstream java_stack;
uintptr_t pc[koom::Constant::kMaxCallStackDepth]{};
ThreadCreateArg() {}
~ThreadCreateArg() {
memset(pc, 0, sizeof(pc));
}
~ThreadCreateArg() { memset(pc, 0, sizeof(pc)); }
};

struct SimpleHookInfo {
long long time;
SimpleHookInfo(long long time) {
this->time = time;
}
int64_t time;
explicit SimpleHookInfo(int64_t time) { this->time = time; }
};
struct HookInfo {
pthread_t thread_id;
long long time;
HookInfo(pthread_t threadId, long long time) {
int64_t time;
HookInfo(pthread_t threadId, int64_t time) {
this->thread_id = threadId;
this->time = time;
}
};
struct HookExitInfo {
pthread_t thread_id;
long long time;
int64_t time;
int tid;
std::string threadName;
HookExitInfo(pthread_t threadId, int tid, char *threadName, long long time) {
HookExitInfo(pthread_t threadId, int tid, char *threadName, int64_t time) {
this->thread_id = threadId;
this->tid = tid;
this->threadName.assign(threadName);
Expand All @@ -78,18 +76,14 @@ struct HookAddInfo {
bool is_thread_detached;
ThreadCreateArg *create_arg;

HookAddInfo(int tid,
long long time,
pthread_t pthread,
bool isThreadDetached,
ThreadCreateArg *thread_create_arg
) {
HookAddInfo(int tid, int64_t time, pthread_t pthread, bool isThreadDetached,
ThreadCreateArg *thread_create_arg) {
this->tid = tid;
this->time = time;
this->pthread = pthread;
this->is_thread_detached = isThreadDetached;
this->create_arg = thread_create_arg;
};
}
};
}
#endif //KOOM_KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_THREAD_LOOP_ITEM_H_
} // namespace koom
#endif // KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_THREAD_LOOP_ITEM_H_
33 changes: 18 additions & 15 deletions koom-thread-leak/src/main/cpp/src/include/thread/thread_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,39 @@
*
*/

#ifndef APM_RESOURCEDATA_H
#define APM_RESOURCEDATA_H
#ifndef KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_THREAD_THREAD_HOLDER_H_
#define KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_THREAD_THREAD_HOLDER_H_

#include <common/callstack.h>
#include <common/log.h>
#include <common/util.h>
#include <rapidjson/writer.h>
#include <thread/loop_item.h>
#include <thread/thread_item.h>

#include "include/common/log.h"
#include "include/common/util.h"
#include "include/common/callstack.h"
#include "thread_item.h"
#include <map>
#include "rapidjson/writer.h"
#include "loop_item.h"
#include <string>

namespace koom {

class ThreadHolder {
public:
void AddThread(int tid, pthread_t pthread, bool isThreadDetached, int64_t start_time,
ThreadCreateArg* create_arg);
void AddThread(int tid, pthread_t pthread, bool isThreadDetached,
int64_t start_time, ThreadCreateArg* create_arg);
void JoinThread(pthread_t threadId);
void ExitThread(pthread_t threadId, std::string& threadName, long long int i);
void ExitThread(pthread_t threadId, std::string& threadName, int64_t time);
void DetachThread(pthread_t threadId);
void ReportThreadLeak(long long time);
void ReportThreadLeak(int64_t time);

private:
std::map<pthread_t, ThreadItem> leakThreadMap;
std::map<pthread_t, ThreadItem> threadMap;
void WriteThreadJson(rapidjson::Writer<rapidjson::StringBuffer> &writer, ThreadItem &thread_item);
void WriteThreadJson(rapidjson::Writer<rapidjson::StringBuffer>& writer,
ThreadItem& thread_item);
void Clear() {
leakThreadMap.clear();
threadMap.clear();
}
};
}
#endif //APM_RESOURCEDATA_H
} // namespace koom
#endif // KOOM_THREAD_LEAK_SRC_MAIN_CPP_SRC_INCLUDE_THREAD_THREAD_HOLDER_H_
Loading

0 comments on commit b335c49

Please sign in to comment.