home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 March / PCWorld_2001-03_cd.bin / Software / Komercni / VAgeJava / ivj35 / setup / IDE.Cab / F10120_IVJTRACE.C < prev    next >
C/C++ Source or Header  |  2000-07-10  |  7KB  |  194 lines

  1.  
  2. #include <stdio.h>
  3. #include <stddef.h>
  4.  
  5. #include "itrccnst.h"
  6. #include "itrcstrt.h"
  7.  
  8. FILE *fout;
  9.  
  10. unsigned long InstrumentTraceStartup(unsigned long vmID) {
  11.     return 0;
  12. }
  13.  
  14. unsigned long InstrumentTraceShutdown() {
  15.     return 0;
  16. }
  17.  
  18. unsigned long InstrumentTraceBegin(unsigned long vmID, unsigned long flags) {
  19.     if(!(fout = fopen("output.trc", "w"))) {
  20.         return 1;
  21.     }
  22.     return 0;
  23. }
  24.  
  25. unsigned long InstrumentTraceEnd() {
  26.     fclose(fout);
  27.     return 0;
  28. }
  29.  
  30. unsigned long InstrumentTraceEvent(struct InsEventInfo *event) {
  31.     unsigned long index;
  32.     static int reportingFields = 0;
  33.     char *threadName, *groupName;
  34.     unsigned long flags, threadNameLength, groupNameLength, priority;
  35.  
  36.     switch(event->header.event) {
  37.         case InsTrcEventMethodEnter:
  38.             fprintf(fout, "\ne %8.8p ", event->body.method.receiver);
  39.             goto contMethod;
  40.             break;
  41.         case InsTrcEventMethodLeave:
  42.             fprintf(fout, "\nl %8.8p ", event->body.method.receiver);
  43. contMethod:
  44.             if(event->body.method.methodEventFlags & InstrumentMethodEventStatic) {
  45.                 fputc((int)'S', fout);
  46.             } else {
  47.                 fputc((int)'-', fout);
  48.             }
  49.             if(event->body.method.methodEventFlags & InstrumentMethodEventNative) {
  50.                 fputc((int)'N', fout);
  51.             } else {
  52.                 fputc((int)'-', fout);
  53.             }
  54.             if(event->body.method.methodEventFlags & InstrumentMethodEventSync) {
  55.                 fputc((int)'S', fout);
  56.             } else {
  57.                 fputc((int)'-', fout);
  58.             }
  59.             fputc((int)' ', fout);
  60.             if(event->body.method.methodEventFlags & InstrumentMethodEventClassDB) {
  61.                 for(index=0;index<event->body.method.classNameSize;index++)
  62.                     fputc(((short *)event->body.method.className)[index], fout);
  63.             } else {
  64.                 for(index=0;index<event->body.method.classNameSize;index++)
  65.                     fputc((int)(event->body.method.className[index]), fout);
  66.             }
  67.             fputc((int)' ', fout);
  68.             if(event->body.method.methodEventFlags & InstrumentMethodEventMethodDB) {
  69.                 for(index=0;index<event->body.method.methodNameSize;index++)
  70.                     fputc(((short *)event->body.method.methodName)[index], fout);
  71.             } else {
  72.                 for(index=0;index<event->body.method.methodNameSize;index++)
  73.                     fputc((int)(event->body.method.methodName[index]), fout);
  74.             }
  75.  
  76.             fprintf(fout, " %ld Thread[", event->body.method.stackDepth);
  77.  
  78.             if(InstrumentSupportCurrentThreadDetails(event->header.vmID, &flags, &threadName, &threadNameLength, &priority, &groupName, &groupNameLength) == 0) {
  79.                 if(flags & InstrumentThreadNameDB) {
  80.                     for(index=0;index<threadNameLength;index++)
  81.                         fputc(((short *)threadName)[index], fout);
  82.                 } else {
  83.                     for(index=0;index<threadNameLength;index++)
  84.                         fputc((int)(threadName[index]), fout);
  85.                 }
  86.                 fprintf(fout, ",%ld,", priority);
  87.                 if(flags & InstrumentThreadGroupNameDB) {
  88.                     for(index=0;index<groupNameLength;index++)
  89.                         fputc(((short *)groupName)[index], fout);
  90.                 } else {
  91.                     for(index=0;index<groupNameLength;index++)
  92.                         fputc((int)(groupName[index]), fout);
  93.                 }
  94.             }
  95.             fputc((int)']', fout);
  96.  
  97.             break;
  98.         case InsTrcEventOIDRename:
  99.             fprintf(fout, "\nr %8.8p %8.8p", event->body.oidRename.source, event->body.oidRename.destination);
  100.             break;
  101.         case InsTrcEventOIDRangeRename:
  102.             fprintf(fout, "\nrr %8.8p %8.8p %8.8p", event->body.oidRangeRename.sourceStart, event->body.oidRangeRename.sourceEnd, event->body.oidRangeRename.destination);
  103.             break;
  104.         case InsTrcEventOIDDelete:
  105.             fprintf(fout, "\ng %8.8p", event->body.oidDelete.oid);
  106.             break;
  107.         case InsTrcEventOIDRangeDelete:
  108.             fprintf(fout, "\nrg %8.8p %8.8p", event->body.oidRangeDelete.start, event->body.oidRangeDelete.end);
  109.             break;
  110.         case InsTrcEventScavengeStart:
  111.             fprintf(fout, "\nscvs");
  112.             break;
  113.         case InsTrcEventScavengeEnd:
  114.             fprintf(fout, "\nscve");
  115.             break;
  116.         case InsTrcEventGGCStart:
  117.             fprintf(fout, "\nggcs");
  118.             break;
  119.         case InsTrcEventGGCEnd:
  120.             fprintf(fout, "\nggce");
  121.             break;
  122.         case InsTrcEventAllocate:
  123.             fprintf(fout, "\na %8.8p %8.8u ", event->body.allocate.oid, event->body.allocate.sizeInLongs);
  124.             if(event->body.allocate.arrayFlag) {
  125.                 if(event->body.allocate.allocBody.array.classNameSize == 0) {
  126.                     if(event->body.allocate.allocBody.array.arity == 0) {
  127.                         fprintf(fout, "<array: object>");
  128.                     } else {
  129.                         fprintf(fout, "<array: array>");
  130.                     }
  131.                 } else {
  132.                     fprintf(fout, "<array: base type> ");
  133.                     for(index=0;index<event->body.allocate.allocBody.array.classNameSize;index++)
  134.                         fputc((int)(event->body.allocate.allocBody.array.className[index]), fout);
  135.                 }
  136.             } else {
  137.                 if(event->body.allocate.allocBody.object.allocEventFlags & InstrumentAllocEventClassDB) {
  138.                     for(index=0;index<event->body.allocate.allocBody.object.classNameSize;index++)
  139.                         fputc(((short *)event->body.allocate.allocBody.object.className)[index], fout);
  140.                 } else {
  141.                     for(index=0;index<event->body.allocate.allocBody.object.classNameSize;index++)
  142.                         fputc((int)(event->body.allocate.allocBody.object.className[index]), fout);
  143.                 }
  144.             }
  145.             break;
  146.         case InsTrcEventStartFieldReport:
  147.             reportingFields = 1;
  148.             switch(event->body.startFieldReport.type) {
  149.                 case InstrumentFREventTypeJava:
  150.                     fprintf(fout, "\nn %8.8p ", event->body.startFieldReport.oid);
  151.                     goto fieldReportClassName;
  152.                 case InstrumentFREventTypeJavaClass:
  153.                     fprintf(fout, "\nnc %8.8p ", event->body.startFieldReport.oid);
  154. fieldReportClassName:
  155.                     if(event->body.startFieldReport.reportEventFlags & InstrumentReportEventClassDB) {
  156.                         for(index=0;index<event->body.startFieldReport.classNameSize;index++)
  157.                             fputc(((short *)event->body.startFieldReport.className)[index], fout);
  158.                     } else {
  159.                         for(index=0;index<event->body.startFieldReport.classNameSize;index++)
  160.                             fputc((int)(event->body.startFieldReport.className[index]), fout);
  161.                     }
  162.                     break;
  163.                 case InstrumentFREventTypeJavaArray:
  164.                     fprintf(fout, "\nn %8.8p <array>", event->body.startFieldReport.oid);
  165.                     break;
  166.                 default:
  167.                     break;
  168.             }
  169.             break;
  170.         case InsTrcEventFieldReport:
  171.             if(reportingFields)
  172.                 fprintf(fout, " %8.8p", event->body.fieldReport.oid);
  173.             break;
  174.         case InsTrcEventEndFieldReport:
  175.             reportingFields = 0;
  176.             break;
  177.         case InsTrcEventUserEvent:
  178.             fprintf(fout, "\nu ");
  179.             if(event->body.user.msgEventFlags & InstrumentUserEventDB) {
  180.                 for(index=0;index<event->body.user.msgSize;index++)
  181.                     fputc(((short *)event->body.user.msg)[index], fout);
  182.             } else {
  183.                 for(index=0;index<event->body.user.msgSize;index++)
  184.                     fputc((int)(event->body.user.msg[index]), fout);
  185.             }
  186.             break;
  187.         default:
  188.             fprintf(fout, "\n<unknown event %d>", event->header.event);
  189.             break;
  190.     }
  191.     return 0;
  192. }
  193.  
  194.