]> git.saurik.com Git - apple/system_cmds.git/blobdiff - latency.tproj/latency.c
system_cmds-336.6.tar.gz
[apple/system_cmds.git] / latency.tproj / latency.c
index 3682b856bdbf6a51352c2f8000077819912b6ee9..0b6da264cc94917c588f5ca105fca2ed2194ecfd 100644 (file)
@@ -24,7 +24,7 @@
 
 
 /* 
-   cc -I. -DKERNEL_PRIVATE -O -o latency latency.c -lncurses
+   cc -I. -DPRIVATE -D__APPLE_PRIVATE -O -o latency latency.c -lncurses
 */
 
 #include <mach/mach.h>
@@ -147,9 +147,8 @@ struct ct {
         char name[32];
 } codes_tab[MAX_ENTRIES];
 
-/* If NUMPARMS changes from the kernel, then PATHLENGTH will also reflect the change */
+
 #define NUMPARMS 23
-#define PATHLENGTH (NUMPARMS*sizeof(long))
 
 struct th_info {
         int  thread;
@@ -158,7 +157,7 @@ struct th_info {
         int  arg1;
         double stime;
         long *pathptr;
-        char pathname[PATHLENGTH + 1];
+        long pathname[NUMPARMS + 1];
 };
 
 #define MAX_THREADS 512
@@ -704,7 +703,7 @@ char *argv[];
        int      loop_cnt, sample_sc_now;
        int      decrementer_usec = 0;
         kern_return_t           ret;
-        int                     size;
+        unsigned int            size;
         host_name_port_t        host;
        void     getdivisor();
        void     sample_sc();
@@ -1216,7 +1215,7 @@ void sample_sc(uint64_t start, uint64_t stop)
                for (i = 0; i < cur_max; i++) {
                        th_state[i].thread = 0;
                        th_state[i].type = -1;
-                       th_state[i].pathptr = (long *)0;
+                       th_state[i].pathptr = (long *)NULL;
                        th_state[i].pathname[0] = 0;
                }
                cur_max = 0;
@@ -1453,14 +1452,17 @@ void sample_sc(uint64_t start, uint64_t stop)
                    }
                    while ( (kd < end_of_sample) && ((kd->debugid & DBG_FUNC_MASK) == VFS_LOOKUP))
                      {
-                       if (!ti->pathptr) {
+                       if (ti->pathptr == NULL) {
                            ti->arg1 = kd->arg1;
-                           memset(&ti->pathname[0], 0, (PATHLENGTH + 1));
-                           sargptr = (long *)&ti->pathname[0];
+                           sargptr = ti->pathname;
                                
                            *sargptr++ = kd->arg2;
                            *sargptr++ = kd->arg3;
                            *sargptr++ = kd->arg4;
+                           /*
+                            * NULL terminate the 'string'
+                            */
+                           *sargptr = 0;
                            ti->pathptr = sargptr;
 
                        } else {
@@ -1472,7 +1474,7 @@ void sample_sc(uint64_t start, uint64_t stop)
                                handle.
                            */
 
-                            if ((long *)sargptr >= (long *)&ti->pathname[PATHLENGTH])
+                            if (sargptr >= &ti->pathname[NUMPARMS])
                              {
                                kd++;
                                continue;
@@ -1487,7 +1489,7 @@ void sample_sc(uint64_t start, uint64_t stop)
 
                             if (kd->debugid & DBG_FUNC_START)
                               {
-                                (long *)ti->pathptr = (long *)&ti->pathname[PATHLENGTH];
+                                ti->pathptr = &ti->pathname[NUMPARMS];
                               }
                            else
                              {
@@ -1495,16 +1497,22 @@ void sample_sc(uint64_t start, uint64_t stop)
                                *sargptr++ = kd->arg2;
                                *sargptr++ = kd->arg3;
                                *sargptr++ = kd->arg4;
+                               /*
+                                * NULL terminate the 'string'
+                                */
+                               *sargptr = 0;
+
                                ti->pathptr = sargptr;
                              }
                        }
                        kd++;
                    }
+                   p = (char *)ti->pathname;
 
                    kd--;
 
-                               /* print the tail end of the pathname */
-                   len = strlen(ti->pathname);
+                   /* print the tail end of the pathname */
+                   len = strlen(p);
                    if (len > 42)
                      len -= 42;
                    else
@@ -1513,7 +1521,7 @@ void sample_sc(uint64_t start, uint64_t stop)
                    if (log_fp) {
                      fprintf(log_fp, "%9.1f %8.1f\t\t%-14.14s %-42s    %-8x   %-8x  %d  %s\n",
                              timestamp - start_bias, delta, "VFS_LOOKUP", 
-                             &ti->pathname[len], ti->arg1, thread, cpunum, command);
+                             &p[len], ti->arg1, thread, cpunum, command);
                    }
 
                    last_timestamp = timestamp;
@@ -1610,7 +1618,7 @@ enter_syscall(FILE *fp, kd_buf *kd, int thread, int type, char *command, double
        else
               ti->type = -1;
        ti->stime  = timestamp;
-       ti->pathptr = (long *)0;
+       ti->pathptr = (long *)NULL;
 
 #if 0
        if (print_info && fp)
@@ -1665,7 +1673,7 @@ exit_syscall(FILE *fp, kd_buf *kd, int thread, int type, char *command, double t
 
                       ti->thread = thread;
                       ti->child_thread = 0;
-                      ti->pathptr = (long *)0;
+                      ti->pathptr = (long *)NULL;
               }
        }
        ti->type = -1;
@@ -1711,7 +1719,7 @@ check_for_thread_update(int thread, int type, kd_buf *kd)
 
                    ti->thread = thread;
                    ti->type   = -1;
-                   ti->pathptr = (long *)0;
+                   ti->pathptr = (long *)NULL;
            }
            ti->child_thread = kd->arg1;
            return (1);
@@ -1919,20 +1927,24 @@ kd_buf *log_decrementer(kd_buf *kd_beg, kd_buf *kd_end, kd_buf *end_of_sample, d
 
                            ti->thread = thread;
                            ti->type   = -1;
-                           ti->pathptr = (long *)0;
+                           ti->pathptr = (long *)NULL;
                            ti->child_thread = 0;
                    }
 
                    while ( (kd <= kd_stop) && (kd->debugid & DBG_FUNC_MASK) == VFS_LOOKUP)
                      {
-                       if (!ti->pathptr) {
+                       if (ti->pathptr == NULL) {
                            ti->arg1 = kd->arg1;
-                           memset(&ti->pathname[0], 0, (PATHLENGTH + 1));
-                           sargptr = (long *)&ti->pathname[0];
+                           sargptr = ti->pathname;
                                
                            *sargptr++ = kd->arg2;
                            *sargptr++ = kd->arg3;
                            *sargptr++ = kd->arg4;
+                           /*
+                            * NULL terminate the 'string'
+                            */
+                           *sargptr = 0;
+
                            ti->pathptr = sargptr;
 
                        } else {
@@ -1944,7 +1956,7 @@ kd_buf *log_decrementer(kd_buf *kd_beg, kd_buf *kd_end, kd_buf *end_of_sample, d
                                handle.
                            */
 
-                            if ((long *)sargptr >= (long *)&ti->pathname[PATHLENGTH])
+                            if (sargptr >= &ti->pathname[NUMPARMS])
                              {
                                kd++;
                                continue;
@@ -1959,7 +1971,7 @@ kd_buf *log_decrementer(kd_buf *kd_beg, kd_buf *kd_end, kd_buf *end_of_sample, d
 
                             if (kd->debugid & DBG_FUNC_START)
                               {
-                                (long *)ti->pathptr = (long *)&ti->pathname[PATHLENGTH];
+                                ti->pathptr = &ti->pathname[NUMPARMS];
                               }
                            else
                              {
@@ -1967,15 +1979,21 @@ kd_buf *log_decrementer(kd_buf *kd_beg, kd_buf *kd_end, kd_buf *end_of_sample, d
                                *sargptr++ = kd->arg2;
                                *sargptr++ = kd->arg3;
                                *sargptr++ = kd->arg4;
+                               /*
+                                * NULL terminate the 'string'
+                                */
+                               *sargptr = 0;
+
                                ti->pathptr = sargptr;
                              }
                        }
                        kd++;
                    }
+                   p = (char *)ti->pathname;
 
                    kd--;
                    /* print the tail end of the pathname */
-                   len = strlen(ti->pathname);
+                   len = strlen(p);
                    if (len > 42)
                      len -= 42;
                    else
@@ -1983,7 +2001,7 @@ kd_buf *log_decrementer(kd_buf *kd_beg, kd_buf *kd_end, kd_buf *end_of_sample, d
                    
                    fprintf(log_fp, "%9.1f %8.1f\t\t%-14.14s %-42s    %-8x   %-8x  %d  %s\n",
                            timestamp - start_bias, delta, "VFS_LOOKUP", 
-                           &ti->pathname[len], ti->arg1, thread, cpunum, command);
+                           &p[len], ti->arg1, thread, cpunum, command);
 
                    last_timestamp = timestamp;
                    break;