Home | History | Annotate | Download | only in lightsymbols
      1 #include <stdlib.h>
      2 #define CANVAS_PATH "CANVAS_PATH"
      3 
      4 class SkFile {
      5   FILE* file;
      6   bool busted;
      7   char* sz;
      8   mutable int i;
      9 
     10 public:
     11   SkFile(unsigned long id) {
     12     file = NULL;
     13     busted = false;
     14     sz = new char[100000];
     15     set(id);
     16     i = 100;
     17   }
     18 
     19   ~SkFile() {
     20     delete sz;
     21     if (file) {
     22       fclose(file);
     23     }
     24   }
     25 
     26   void set(unsigned long id) {
     27     if (busted) {
     28       return;
     29     }
     30 
     31     if (file == NULL) {
     32       char sz[10000];
     33       sprintf(sz, "%s\\%ul.callstacks.txt", getenv(CANVAS_PATH), id);
     34       file = fopen(sz, "a");
     35       if (file == NULL) {
     36         busted = true;
     37       }
     38       fprintf(file, "\n\n\nNEW SESSION, just coliding ids ... should generate a new file ideally ...  \n\n\n");
     39     }
     40   }
     41 
     42   void appendLine(const char* sz) const {
     43     if (busted) {
     44       return;
     45     }
     46 
     47     fprintf(file, "%s\n", sz);
     48   }
     49 
     50   void dump(bool flush = false) const {
     51     if (busted) {
     52       return;
     53     }
     54 
     55     LightSymbol::GetCallStack(sz, 100000, " >- ");
     56     appendLine(sz);
     57 
     58     i--;
     59 
     60     if (i < 0 || flush) {
     61       i = 100;
     62       fflush(file);
     63     }
     64   }
     65 };
     66