1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <jmp.h>
#include <jthread.h>
#include <cls.h>
#include <method.h>
/** Thread comparators */
/** Compare two jthreads by there name. */
int jthread_compr_name (const void* v1, const void* v2) {
jthread **t1 = (jthread**) v1;
jthread **t2 = (jthread**) v2;
return strcmp (jthread_get_thread_name(*t1), jthread_get_thread_name(*t2));
}
/** compare threads based on thread group */
int jthread_compr_group (const void* v1, const void* v2) {
jthread** t1 = (jthread**)v1;
jthread** t2 = (jthread**)v2;
return (strcmp (jthread_get_group_name (*t1), jthread_get_group_name (*t2)));
}
/** compare threads based on thread parent */
int jthread_compr_parent (const void* v1, const void* v2) {
jthread** t1 = (jthread**)v1;
jthread** t2 = (jthread**)v2;
return (strcmp (jthread_get_parent_name (*t1), jthread_get_parent_name (*t2)));
}
/** Compare threads based on contenation time for the threads. */
int jthread_compr_contenation (const void* v1, const void* v2) {
jlong l;
jthread** t1 = (jthread**)v1;
jthread** t2 = (jthread**)v2;
l = (*t1)->timerstack->contendtime - (*t2)->timerstack->contendtime;
if (l < 0)
return 1;
else if (l > 0)
return -1;
return 0;
}
/** Compare threads based on consumed cpu time. */
int jthread_compr_state (const void* v1, const void* v2) {
jthread** t1 = (jthread**)v1;
jthread** t2 = (jthread**)v2;
return (*t1)->state - (*t2)->state;
}
/** Compare threads based on consumed cpu time. */
int jthread_compr_cputime (const void* v1, const void* v2) {
jlong l;
jthread** t1 = (jthread**)v1;
jthread** t2 = (jthread**)v2;
l = (*t1)->timerstack->cpu_time - (*t2)->timerstack->cpu_time;
if (l < 0)
return 1;
else if (l > 0)
return -1;
return 0;
}
/** class comparators... */
/** compare classes based on class name */
int cls_compr_name (const void* v1, const void* v2) {
cls** c1 = (cls**)v1;
cls** c2 = (cls**)v2;
return (strcmp (cls_get_name (*c1), cls_get_name (*c2)));
}
/** compare classes based on instance count */
int cls_compr_instance (const void* v1, const void* v2) {
cls** c1 = (cls**)v1;
cls** c2 = (cls**)v2;
return (cls_get_instances (*c2) - cls_get_instances (*c1));
}
/** compare classes based on maximum instance count */
int cls_compr_max_instance (const void* v1, const void* v2) {
cls** c1 = (cls**)v1;
cls** c2 = (cls**)v2;
return (cls_get_max_instances (*c2) - cls_get_max_instances (*c1));
}
/** compare classes based on current size in bytes */
int cls_compr_size (const void* v1, const void* v2) {
cls** c1 = (cls**)v1;
cls** c2 = (cls**)v2;
return (cls_get_size (*c2) - cls_get_size (*c1));
}
/** compare classes based on number of garbage collected instances */
int cls_compr_instance_gc (const void* v1, const void* v2) {
cls** c1 = (cls**)v1;
cls** c2 = (cls**)v2;
return (cls_get_total_gc (*c2) - cls_get_total_gc (*c1));
}
/** compare classes based on number of garbage collected instances */
int cls_compr_tenure (const void* v1, const void* v2) {
cls** c1 = (cls**)v1;
cls** c2 = (cls**)v2;
return (cls_get_tenure (*c1) - cls_get_tenure (*c2));
}
/** Method comparators. */
/** Compare methods based on signature. */
int method_compr_signature (const void* v1, const void* v2) {
method** m1 = (method**)v1;
method** m2 = (method**)v2;
return (strcmp (method_get_method_signature (*m1), method_get_method_signature (*m2)));
}
/** Compare methods based on method name (and signature if needed) */
int method_compr_name (const void* v1, const void* v2) {
method** m1 = (method**)v1;
method** m2 = (method**)v2;
int c = 0;
c = (strcmp (method_get_method_name (*m1), method_get_method_name (*m2)));
if (c)
return c;
return method_compr_signature (v1, v2);
}
/** Compare method based on class name, method name and signature (in that order) */
int method_compr_class (const void* v1, const void* v2) {
cls* c1;
cls* c2;
int c;
method** m1 = (method**)v1;
method** m2 = (method**)v2;
c1 = method_get_owner (*m1);
c2 = method_get_owner (*m2);
c = (strcmp (cls_get_class_name (c1), cls_get_class_name (c2)));
if (c)
return c;
return method_compr_name (v1, v2);
}
/** Compare methods based on used time in the method. */
int method_compr_time (const void* v1, const void* v2) {
jlong l;
method** m1 = (method**)v1;
method** m2 = (method**)v2;
l = (*m1)->time_used.tv - (*m2)->time_used.tv;
/* l is a long long, dont want it to be auto casted to an int,
* so check and return by ourselfs..
*/
if (l < 0)
return 1;
else if (l > 0)
return -1;
return 0;
}
/** Compare methods based on number of calls. */
int method_compr_calls (const void* v1, const void* v2) {
method** m1 = (method**)v1;
method** m2 = (method**)v2;
return method_get_calls (*m2) - method_get_calls (*m1);
}
/** Compare methods based on time used in method called from this method. */
int method_compr_hold_time (const void* v1, const void* v2) {
jlong l;
method** m1 = (method**)v1;
method** m2 = (method**)v2;
l = (*m1)->time_used.tv_hold - (*m2)->time_used.tv_hold;
if (l < 0)
return 1;
else if (l > 0)
return -1;
return 0;
}
/** Compare methods based on time used in this method and method called from this method. */
int method_compr_total_time (const void* v1, const void* v2) {
jlong diff, tot1, tot2;
method** m1 = (method**)v1;
method** m2 = (method**)v2;
tot1 = (*m1)->time_used.tv + (*m1)->time_used.tv_hold;
tot2 = (*m2)->time_used.tv + (*m2)->time_used.tv_hold;
if ((diff = (tot1 - tot2)) < 0)
return 1;
else if (diff > 0)
return -1;
return 0;
}
/** Compare methods based on allocated objects */
int method_compr_objects (const void* v1, const void* v2) {
method** m1 = (method**) v1;
method** m2 = (method**) v2;
return (*m2)->allocated_objects - (*m1)->allocated_objects;
}
/** Compare methods based on allocated objects per call */
int method_compr_objpercall (const void* v1, const void* v2) {
int ao1, ao2, mc1, mc2;
method** m1 = (method**) v1;
method** m2 = (method**) v2;
ao2 = (*m2)->allocated_objects;
ao1 = (*m1)->allocated_objects;
mc2 = method_get_calls (*m2);
mc1 = method_get_calls (*m1);
if(mc2>0)
ao2 = ao2/mc2;
if(mc1>0)
ao1 = ao1/mc1;
return ao2 - ao1;
}
/** Compare methods based on total time per call. */
int method_compr_total_time_per_call (const void* v1, const void* v2) {
jlong diff, tot1, tot2;
int mc1, mc2;
method** m1 = (method**)v1;
method** m2 = (method**)v2;
tot1 = (*m1)->time_used.tv + (*m1)->time_used.tv_hold;
tot2 = (*m2)->time_used.tv + (*m2)->time_used.tv_hold;
mc2 = method_get_calls (*m2);
mc1 = method_get_calls (*m1);
if(mc2>0)
tot2 = tot2/mc2;
if(mc1>0)
tot1 = tot1/mc1;
if ((diff = (tot1 - tot2)) < 0)
return 1;
else if (diff > 0)
return -1;
return 0;
}
/** Compare methods based on allocated memory */
int method_compr_bytes (const void* v1, const void* v2) {
jlong diff;
method** m1 = (method**) v1;
method** m2 = (method**) v2;
diff = (*m2)->allocated_memory - (*m1)->allocated_memory;
if (diff<0) return -1;
else if (diff==0) return 0;
else return 1;
}
/* Emacs Local Variables: */
/* Emacs mode:C */
/* Emacs c-indentation-style:"gnu" */
/* Emacs c-hanging-braces-alist:((brace-list-open)(brace-entry-open)(defun-open after)(substatement-open after)(block-close . c-snug-do-while)(extern-lang-open after)) */
/* Emacs c-cleanup-list:(brace-else-brace brace-elseif-brace space-before-funcall) */
/* Emacs c-basic-offset:4 */
/* Emacs End: */
|