/[gxemul]/trunk/experiments/ic_statistics.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/experiments/ic_statistics.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 27 by dpavlin, Mon Oct 8 16:19:56 2007 UTC revision 28 by dpavlin, Mon Oct 8 16:20:26 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: ic_statistics.c,v 1.3 2006/03/30 19:36:03 debug Exp $   *  $Id: ic_statistics.c,v 1.4 2006/07/15 09:44:13 debug Exp $
29   *   *
30   *  This program is not optimized for speed, but it should work.   *  This program is not optimized for speed, but it should work.
31   *   *
32     *  Run  gxemul -s i:log.txt blahblahblah, and then
33     *
34   *  for a in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do \   *  for a in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do \
35   *      ./ic_statistics $a |sort -n > statistics.$a.txt; done   *      ./ic_statistics log.txt $a |sort -n > statistics.$a.txt; done
36   */   */
37    
38  #include <stdio.h>  #include <stdio.h>
# Line 41  Line 43 
43    
44    
45  struct entry {  struct entry {
46          void            **ptrs;          uint64_t        *ptrs;
47          long long       count;          long long       count;
48  };  };
49    
# Line 55  char **cache_symbol = NULL; Line 57  char **cache_symbol = NULL;
57  int n_cached_symbols = 0;  int n_cached_symbols = 0;
58    
59    
60  char *cached_size_t_to_symbol(size_t s)  char *cached_size_t_to_symbol(uint64_t s)
61  {  {
62          int i = 0;          int i = 0;
63          FILE *q;          FILE *q;
# Line 73  char *cached_size_t_to_symbol(size_t s) Line 75  char *cached_size_t_to_symbol(size_t s)
75          cache_symbol = realloc(cache_symbol, sizeof(char *) * n_cached_symbols);          cache_symbol = realloc(cache_symbol, sizeof(char *) * n_cached_symbols);
76          cache_s[n_cached_symbols - 1] = s;          cache_s[n_cached_symbols - 1] = s;
77    
78          snprintf(tmp, sizeof(tmp), "nm ../gxemul | grep "          snprintf(tmp, sizeof(tmp), "nm ../gxemul | grep %"PRIx64, s);
             "%"PRIx64, (uint64_t)s);  
79          q = popen(tmp, "r");          q = popen(tmp, "r");
80          if (q == NULL) {          if (q == NULL) {
81                  perror("popen()");                  perror("popen()");
# Line 105  void print_all(int n) Line 106  void print_all(int n)
106  {  {
107          int i = 0;          int i = 0;
108          while (i < n_entries) {          while (i < n_entries) {
109                  void **pp = entries[i].ptrs;                  uint64_t *pp = entries[i].ptrs;
110                  int j = 0;                  int j = 0;
111    
112                  printf("%lli\t", (long long)entries[i].count);                  printf("%lli\t", (long long)entries[i].count);
113                  while (j < n) {                  while (j < n) {
114                          size_t s = (size_t)pp[j];                          uint64_t s = pp[j];
115    
116                          if (j > 0)                          if (j > 0)
117                                  printf(", ");                                  printf(", ");
# Line 125  void print_all(int n) Line 126  void print_all(int n)
126  }  }
127    
128    
129  void add_count(void **pointers, int n)  void add_count(uint64_t *icpointers, int n)
130  {  {
131          int i = 0;          int i = 0;
132    
133          /*  Scan all existing entries.  */          /*  Scan all existing entries.  */
134          while (i < n_entries) {          while (i < n_entries) {
135                  if (memcmp(pointers, entries[i].ptrs, sizeof(void*) * n) == 0) {                  if (memcmp(icpointers, entries[i].ptrs,
136                        sizeof(uint64_t) * n) == 0) {
137                          entries[i].count ++;                          entries[i].count ++;
138                          return;                          return;
139                  }                  }
# Line 142  void add_count(void **pointers, int n) Line 144  void add_count(void **pointers, int n)
144          n_entries ++;          n_entries ++;
145          entries = realloc(entries, sizeof(struct entry) * n_entries);          entries = realloc(entries, sizeof(struct entry) * n_entries);
146          entries[n_entries-1].ptrs = malloc(sizeof(void *) * n);          entries[n_entries-1].ptrs = malloc(sizeof(void *) * n);
147          memcpy(entries[n_entries-1].ptrs, &pointers[0], n * sizeof(void *));          memcpy(entries[n_entries-1].ptrs, &icpointers[0], n * sizeof(uint64_t));
148          entries[n_entries-1].count = 1;          entries[n_entries-1].count = 1;
149  }  }
150    
151    
152  void try_len(FILE *f, int len)  void try_len(FILE *f, int len)
153  {  {
154          void **pointers;          uint64_t *icpointers;
155          off_t off;          off_t off, n_read = 0;
156    
157          pointers = malloc(sizeof(void *) * len);          icpointers = malloc(sizeof(uint64_t) * len);
158    
159          fseek(f, 0, SEEK_END);          fseek(f, 0, SEEK_END);
160          off = ftello(f);          off = ftello(f);
161    
162          fseek(f, 0, SEEK_SET);          fseek(f, 0, SEEK_SET);
         if (len > 1)  
                 fread(&pointers[1], sizeof(void *), len-1, f);  
163    
164          while (!feof(f)) {          while (!feof(f)) {
165                  static long long yo = 0;                  static long long yo = 0;
166                    char buf[100];
167    
168                  yo ++;                  yo ++;
169                  if ((yo & 0xfffff) == 0) {                  if ((yo & 0xfffff) == 0) {
170                          fprintf(stderr, "[ len=%i, %i%% done ]\n",                          fprintf(stderr, "[ len=%i, %i%% done ]\n",
171                              len, 100 * yo * sizeof(void *) / off);                              len, 100 * yo * sizeof(void *) / off);
172                  }                  }
173    
174                  /*  Make room for next pointer value:  */                  /*  Make room for next icpointer value:  */
175                  if (len > 1)                  if (len > 1)
176                          memmove(&pointers[0], &pointers[1],                          memmove(&icpointers[0], &icpointers[1],
177                              (len-1) * sizeof(void *));                              (len-1) * sizeof(uint64_t));
178    
179                  /*  Read one pointer into pointers[len-1]:  */                  /*  Read one value into icpointers[len-1]:  */
180                  fread(&pointers[len-1], sizeof(void *), 1, f);                  fgets(buf, sizeof(buf), f);
181                    icpointers[len-1] = strtoull(buf, NULL, 0);
182    
183                  add_count(&pointers[0], len);                  n_read ++;
184    
185                    if (n_read >= len)
186                            add_count(&icpointers[0], len);
187          }          }
188    
189          free(pointers);          free(icpointers);
190  }  }
191    
192    
# Line 189  int main(int argc, char *argv[]) Line 195  int main(int argc, char *argv[])
195          FILE *f;          FILE *f;
196          int len = 1;          int len = 1;
197    
198          f = fopen("instruction_call_statistics.raw", "r");          if (argc < 3) {
199                    fprintf(stderr, "usage: %s input.log n\n", argv[0]);
200                    exit(1);
201            }
202    
203            f = fopen(argv[1], "r");
204          if (f == NULL) {          if (f == NULL) {
205                  f = fopen("../instruction_call_statistics.raw", "r");                  perror(argv[1]);
206                  if (f == NULL) {                  exit(1);
                         perror("instruction_call_statistics.raw");  
                         exit(1);  
                 }  
207          }          }
208    
209          if (argc > 1)          len = atoi(argv[2]);
                 len = atoi(argv[1]);  
210    
211          if (len < 1) {          if (len < 1) {
212                  fprintf(stderr, "bad len\n");                  fprintf(stderr, "bad len\n");

Legend:
Removed from v.27  
changed lines
  Added in v.28

  ViewVC Help
Powered by ViewVC 1.1.26