diff options
author | edisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-12-21 19:19:10 +0000 |
---|---|---|
committer | edisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-12-21 19:19:10 +0000 |
commit | 635c331b29ae9c9be8e0e4059881558acd660cc9 (patch) | |
tree | 0878d9f621c95a0ac62a70a3e9d5af8fc9e9cfc8 /experimental/LightSymbolsUtil/lightsymbols | |
parent | 5595af1b2ebe6590e98641464d43d22281a7f295 (diff) |
Experimental code to track what methos have been called: Callstacker is used inject LS_TRACE(...) as first thing in a function definition. lightsymbols must be added to the project too.
A experimental/LightSymbolsUtil
A experimental/LightSymbolsUtil/lightsymbols
A experimental/LightSymbolsUtil/lightsymbols/lightsymbols.cc
A experimental/LightSymbolsUtil/lightsymbols/helper.h
A experimental/LightSymbolsUtil/lightsymbols/lightsymbols.h
A experimental/LightSymbolsUtil/Callstacker
A experimental/LightSymbolsUtil/Callstacker/Callstacker.sln
A experimental/LightSymbolsUtil/Callstacker/Callstacker
A experimental/LightSymbolsUtil/Callstacker/Callstacker/Callstacker.vcxproj
A experimental/LightSymbolsUtil/Callstacker/Callstacker/Callstacker.cpp
A experimental/LightSymbolsUtil/Callstacker/Callstacker/Callstacker.vcxproj.filters
A experimental/LightSymbolsUtil/Callstacker/Callstacker/targetver.h
A experimental/LightSymbolsUtil/Callstacker/Callstacker/stdafx.cpp
A experimental/LightSymbolsUtil/Callstacker/Callstacker/ReadMe.txt
A experimental/LightSymbolsUtil/Callstacker/Callstacker/Callstacker.vcxproj.user
A experimental/LightSymbolsUtil/Callstacker/Callstacker/stdafx.h
git-svn-id: http://skia.googlecode.com/svn/trunk@6928 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental/LightSymbolsUtil/lightsymbols')
3 files changed, 284 insertions, 0 deletions
diff --git a/experimental/LightSymbolsUtil/lightsymbols/helper.h b/experimental/LightSymbolsUtil/lightsymbols/helper.h new file mode 100644 index 0000000000..29258675cc --- /dev/null +++ b/experimental/LightSymbolsUtil/lightsymbols/helper.h @@ -0,0 +1,65 @@ +#include <stdlib.h>
+#define CANVAS_PATH "CANVAS_PATH"
+
+class SkFile {
+ FILE* file;
+ bool busted;
+ char* sz;
+ mutable int i;
+
+public:
+ SkFile(unsigned long id) {
+ file = NULL;
+ busted = false;
+ sz = new char[100000];
+ set(id);
+ i = 100;
+ }
+
+ ~SkFile() {
+ delete sz;
+ if (file) {
+ fclose(file);
+ }
+ }
+
+ void set(unsigned long id) {
+ if (busted) {
+ return;
+ }
+
+ if (file == NULL) {
+ char sz[10000];
+ sprintf(sz, "%s\\%ul.callstacks.txt", getenv(CANVAS_PATH), id);
+ file = fopen(sz, "a");
+ if (file == NULL) {
+ busted = true;
+ }
+ fprintf(file, "\n\n\nNEW SESSION, just coliding ids ... should generate a new file ideally ... \n\n\n");
+ }
+ }
+
+ void appendLine(const char* sz) const {
+ if (busted) {
+ return;
+ }
+
+ fprintf(file, "%s\n", sz);
+ }
+
+ void dump(bool flush = false) const {
+ if (busted) {
+ return;
+ }
+
+ LightSymbol::GetCallStack(sz, 100000, " >- ");
+ appendLine(sz);
+
+ i--;
+
+ if (i < 0 || flush) {
+ i = 100;
+ fflush(file);
+ }
+ }
+};
diff --git a/experimental/LightSymbolsUtil/lightsymbols/lightsymbols.cc b/experimental/LightSymbolsUtil/lightsymbols/lightsymbols.cc new file mode 100644 index 0000000000..230faf587f --- /dev/null +++ b/experimental/LightSymbolsUtil/lightsymbols/lightsymbols.cc @@ -0,0 +1,169 @@ +#include "lightsymbols.h"
+
+LightSymbol::PLightSymbol LightSymbol::lsFrames[1000];
+HANDLE LightSymbol::handleFrames[1000];
+SZ* LightSymbol::fileNames;
+bool LightSymbol::busted = false;
+
+
+LightSymbol::LightSymbol(const char* sym, int fileId, int lineNumber) {
+ while (busted) {
+ busted = busted;
+ }
+ this->sym = sym;
+ this->fileId = fileId;
+ this->lineNumber = lineNumber;
+
+ LightSymbol** container = getThreadFrameContainer();
+
+ parentFrame = *container;
+ *container = this; // shortcut for get+set current frame
+}
+
+LightSymbol::~LightSymbol() {
+
+// assert if (GetCurrentFrame() != this) {
+
+ SetCurrentFrame(parentFrame);
+}
+
+bool LightSymbol::GetCallStack(char* sz, int len, const char* separator) {
+ LightSymbol* ls = GetCurrentFrame();
+ if (ls == 0) {
+ return false;
+ } else {
+ return ls->GetCallStackCore(sz, len, separator);
+ }
+}
+
+LightSymbol** LightSymbol::getThreadFrameContainer() {
+ //pthread_t t = pthread_self();
+ HANDLE h = (HANDLE)GetCurrentThreadId(); // f, keep handle so I don't have to recompie tyhe whole app; update toi DWORD one I really need changes in header file
+ int i = 0;
+ while (handleFrames[i] != h && handleFrames[i] != NULL && i < 1000 - 1) {
+ i++;
+ }
+ if (handleFrames[i] == h) {
+ return &lsFrames[i];
+ }
+ handleFrames[i] = h;
+ return &lsFrames[i];
+}
+
+bool LightSymbol::GetCallStackCore(char* sz, int len, const char* separator) const {
+ if (busted) {
+ return false;
+ }
+ if (fileNames == NULL) { // f multithreading synchr
+ FILE* log = fopen("d:\\edisonn\\log.txt", "wt");
+
+ if (log) { fprintf(log, "build\n");fflush(log); }
+
+ char szLine[10000];
+ FILE* file = fopen(getenv(LIGHT_SYMBOLS_FILE), "rt");
+ if (file == NULL) {
+ busted = true;
+ return false;
+ }
+
+ const char* trimed;
+
+ // count number of lines
+ int id;
+ int entries = 0;
+ while (true) {
+ id = -1;
+ if (fscanf(file, "%i", &id) == 0) break;
+ if (id == -1) break;
+ if (entries <= id + 1) {
+ entries = id + 1;
+ }
+ *szLine = '\0';
+ fgets(szLine, 10000, file);
+ trimed = trim(szLine);
+ }
+
+ fclose(file);
+ file = fopen(getenv(LIGHT_SYMBOLS_FILE), "rt");
+ if (file == NULL) {
+ busted = true;
+ return false; // f this
+ }
+
+ if (log) { fprintf(log, "entries: %i\n", entries);fflush(log); }
+
+ SZ* __fileNames = new SZ[entries];
+
+ while (true) {
+ id = -1;
+ if (fscanf(file, "%i", &id) == 0) break;
+ if (id == -1) break;
+ *szLine = '\0';
+ fgets(szLine, 10000, file);
+ trimed = trim(szLine);
+
+ if (log) { fprintf(log, "%i, %s", id, trimed); }
+
+ // ass u me the file is correct
+
+ __fileNames[id] = new char[strlen(trimed) + 1];
+ if (log) { fprintf(log, " - ");fflush(log); }
+ strcpy(__fileNames[id], trimed);
+ if (log) { fprintf(log, " _ \n");fflush(log); }
+ }
+ fclose(file);
+ fileNames = __fileNames;
+ if (log) { fclose(log); }
+ }
+
+ const LightSymbol* ls = this;
+ char* szOut = sz;
+ // f security
+ while (ls != NULL && len > 1000) {
+ sprintf(szOut, "%s, %s:%i%s", ls->sym, fileNames[ls->fileId], ls->lineNumber, separator);
+ while (*szOut && len > 0) {
+ szOut++;
+ len--;
+ }
+ ls = ls->parentFrame;
+ }
+
+ int more = 0;
+ while (ls != NULL) {
+ ls = ls->parentFrame;
+ }
+
+ if (more > 0) {
+ sprintf(szOut, " ... %i more frames. allocate more memory!", more);
+ }
+
+ return true;
+}
+
+LightSymbol* LightSymbol::GetCurrentFrame() {
+ return *getThreadFrameContainer();
+}
+
+void LightSymbol::SetCurrentFrame(LightSymbol* ls) {
+ *getThreadFrameContainer() = ls;
+}
+
+const char* LightSymbol::trim(char* sz) {
+ if (sz == NULL) return NULL;
+
+ while (*sz == ' ' || *sz == '\t' || *sz == '\r' || *sz == '\n' || *sz == ',')
+ sz++;
+
+ if (*sz == '\0') return sz;
+
+ int len = strlen(sz);
+ char* start = sz;
+ sz = sz + (len - 1);
+
+ while (sz >= start && (*sz == ' ' || *sz == '\t' || *sz == '\r' || *sz == '\n' || *sz == ',')) {
+ *sz = '\0';
+ sz--;
+ }
+
+ return start;
+}
diff --git a/experimental/LightSymbolsUtil/lightsymbols/lightsymbols.h b/experimental/LightSymbolsUtil/lightsymbols/lightsymbols.h new file mode 100644 index 0000000000..1dc6e85049 --- /dev/null +++ b/experimental/LightSymbolsUtil/lightsymbols/lightsymbols.h @@ -0,0 +1,50 @@ +#ifndef __LIGHT_SYMBOLS__
+#define __LIGHT_SYMBOLS__
+#define LS_TRACE(functionName,fileId,lineNumber) LightSymbol __lstr(functionName,fileId,lineNumber);
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+//#include <pthread.h>
+#include <Windows.h>
+
+typedef char* SZ;
+
+#define LIGHT_SYMBOLS_FILE "LIGHT_SYMBOLS_FILE"
+
+class LightSymbol {
+ const char* sym;
+ int fileId;
+ int lineNumber;
+
+ LightSymbol* parentFrame;
+
+ typedef LightSymbol* PLightSymbol;
+
+ static PLightSymbol lsFrames[1000];
+ static HANDLE handleFrames[1000];
+ static SZ* fileNames;
+ static bool busted;
+
+public:
+ LightSymbol(const char* sym, int fileId, int lineNumber);
+
+ ~LightSymbol();
+
+ static bool GetCallStack(char* sz, int len, const char* separator);
+
+private:
+
+ static LightSymbol** getThreadFrameContainer();
+
+ bool GetCallStackCore(char* sz, int len, const char* separator) const ;
+
+ static LightSymbol* GetCurrentFrame() ;
+
+ static void SetCurrentFrame(LightSymbol* ls) ;
+
+ static const char* trim(char* sz) ;
+};
+
+#endif
\ No newline at end of file |