OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 3 * Distributed under the terms of the GNU General Public License v2 |
| 4 */ |
| 5 |
| 6 #include <stdio.h> |
| 7 #include <unistd.h> |
| 8 |
| 9 #include "collector.h" |
| 10 #include "ktop.h" |
| 11 #include "syscall.h" |
| 12 |
| 13 void pr_buf(int cpu, int sz, u8 buf[sz]) |
| 14 { |
| 15 int i; |
| 16 int j; |
| 17 |
| 18 printf("%d. trace=%d bytes\n", cpu, sz); |
| 19 for (i = 0; i < sz; i++) { |
| 20 for (j = 0; j < 32; j++, i++) { |
| 21 if (i == sz) goto done; |
| 22 printf(" %2x", buf[i]); |
| 23 } |
| 24 printf("\n"); |
| 25 } |
| 26 done: |
| 27 printf("\n"); |
| 28 } |
| 29 |
| 30 static void pr_event(event_s *event) |
| 31 { |
| 32 printf(" type=%2u flags=%2x cnt=%2d pid=%5d lock=%2d", |
| 33 event->type, event->flags, event->preempt_count, event->pid, |
| 34 event->lock_depth); |
| 35 } |
| 36 |
| 37 static void pr_sys_enter(void *event) |
| 38 { |
| 39 sys_enter_s *sy = event; |
| 40 int i; |
| 41 |
| 42 printf(" %-20s", Syscall[sy->id]); |
| 43 for (i = 0; i < 6; i++) { |
| 44 printf(" %ld", sy->arg[i]); |
| 45 } |
| 46 printf("\n"); |
| 47 } |
| 48 |
| 49 static void pr_sys_exit(void *event) |
| 50 { |
| 51 sys_exit_s *sy = event; |
| 52 |
| 53 printf(" %-20s ret=%ld\n", Syscall[sy->id], sy->ret); |
| 54 } |
| 55 |
| 56 static void pr_ring_header(ring_header_s *rh) |
| 57 { |
| 58 printf("%lld %lld %ld\n", |
| 59 rh->time_stamp / A_BILLION, rh->time_stamp % A_BILLION, |
| 60 rh->commit); |
| 61 } |
| 62 |
| 63 static void dump_event(void *buf) |
| 64 { |
| 65 event_s *event = buf; |
| 66 |
| 67 pr_event(event); |
| 68 switch (event->type) { |
| 69 case 21: |
| 70 pr_sys_exit(event); |
| 71 break; |
| 72 case 22: |
| 73 pr_sys_enter(event); |
| 74 break; |
| 75 default: |
| 76 printf(" no processing\n"); |
| 77 break; |
| 78 } |
| 79 } |
| 80 |
| 81 static void dump_buf(u8 *buf) |
| 82 { |
| 83 ring_header_s *rh = (ring_header_s *)buf; |
| 84 ring_event_s *r; |
| 85 unint length; |
| 86 unint size; |
| 87 u64 time; |
| 88 u8 *end; |
| 89 |
| 90 pr_ring_header(rh); |
| 91 time = rh->time_stamp; |
| 92 buf += sizeof(*rh); |
| 93 end = &buf[rh->commit]; |
| 94 for (; buf < end; buf += size) { |
| 95 r = (ring_event_s *)buf; |
| 96 printf("type_len=%2u time=%9d", r->type_len, r->time_delta); |
| 97 if (r->type_len == 0) { |
| 98 length = r->array[0]; |
| 99 size = 4 + length * 4; |
| 100 time += r->time_delta; |
| 101 } else if (r->type_len <= 28) { |
| 102 length = r->type_len; |
| 103 size = 4 + length * 4; |
| 104 time += r->time_delta; |
| 105 dump_event(buf+4); |
| 106 } else if (r->type_len == 29) { |
| 107 printf("\n"); |
| 108 if (r->time_delta == 0) { |
| 109 return; |
| 110 } else { |
| 111 length = r->array[0]; |
| 112 size = 4 + length * 4; |
| 113 } |
| 114 } else if (r->type_len == 30) { |
| 115 /* Extended time delta */ |
| 116 printf("\n"); |
| 117 size = 8; |
| 118 time += (((u64)r->array[0]) << 28) | r->time_delta; |
| 119 } else if (r->type_len == 31) { |
| 120 /* Sync time with external clock (NOT IMMPLEMENTED) */ |
| 121 //tv_nsec = r->array[0]; |
| 122 //tv_sec = *(u64 *)&(r->array[1]); |
| 123 } else { |
| 124 printf(" Unknown event %d\n", r->type_len); |
| 125 /* Unknown - ignore */ |
| 126 size = 4; |
| 127 } |
| 128 } |
| 129 } |
| 130 |
| 131 static void dump_raw(int cpu, int sz, u8 buf[sz]) |
| 132 { |
| 133 dump_buf(buf); // Need to do something with sz |
| 134 } |
| 135 |
| 136 void *dump_collector(void *args) |
| 137 { |
| 138 Collector_args_s *a = args; |
| 139 u8 buf[BUF_SIZE]; |
| 140 int cpu = a->cpu_id; |
| 141 int trace_pipe; |
| 142 int rc; |
| 143 int i; |
| 144 |
| 145 ignore_pid(gettid()); |
| 146 trace_pipe = open_raw(cpu); |
| 147 for (i = 0;; i++) { |
| 148 rc = read(trace_pipe, buf, sizeof(buf)); |
| 149 printf("i=%d rc=%d\n", i, rc); |
| 150 if (rc == -1) { |
| 151 close(trace_pipe); |
| 152 cleanup(0); |
| 153 } |
| 154 dump_raw(cpu, rc, buf); |
| 155 if (rc < SMALL_READ) { |
| 156 sleep(1); // Wait for input to accumulate |
| 157 } |
| 158 } |
| 159 return NULL; |
| 160 } |
OLD | NEW |