Print this page
cleanup
libconv


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.


  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include <ctype.h>
  30 #include <string.h>
  31 #include <sys/param.h>
  32 #include <stdlib.h>
  33 #include "conv.h"
  34 #include "gprof.h"
  35 
  36 void print_demangled_name(int, nltype *);
  37 void striped_name(char *, nltype **);
  38 
  39 extern long hz;
  40 
  41 /*
  42  * Symbols that must never be printed, no matter what.
  43  */
  44 char *splsym[] = {
  45         PRF_ETEXT,
  46         PRF_EXTSYM,
  47         PRF_MEMTERM,
  48         NULL


 483                                     arcp->arc_childtime / hz, arcp->arc_count,
 484                                     "");
 485 
 486                         printname(childp);
 487 
 488                         if (Cflag)
 489                                 print_demangled_name(54, childp);
 490 
 491                         (void) printf("\n");
 492                 }
 493         }
 494 }
 495 
 496 void
 497 printname(nltype *selfp)
 498 {
 499         const char  *c;
 500         c = demangled_name(selfp);
 501 
 502         if (selfp->name != 0) {
 503                 if (!Cflag)
 504                         (void) printf("%s", selfp->name);
 505                 else
 506                         (void) printf("%s", c);
 507 
 508 #ifdef DEBUG
 509                 if (debug & DFNDEBUG)
 510                         (void) printf("{%d} ", selfp->toporder);
 511 
 512                 if (debug & PROPDEBUG)
 513                         (void) printf("%5.2f%% ", selfp->propfraction);
 514 #endif /* DEBUG */
 515         }
 516 
 517         if (selfp->cycleno != 0)
 518                 (void) printf("\t<cycle %d>", selfp->cycleno);
 519 
 520         if (selfp->index != 0) {
 521                 if (selfp->printflag)
 522                         (void) printf(" [%d]", selfp->index);
 523                 else
 524                         (void) printf(" (%d)", selfp->index);
 525         }



 526 }
 527 
 528 void
 529 print_demangled_name(int n, nltype *selfp)
 530 {
 531         char *c;
 532         int i;
 533 
 534         c = selfp->name;
 535 
 536         if (strcmp(c, demangled_name(selfp)) == 0)
 537                 return;
 538         else {
 539                 (void) printf("\n");
 540                 for (i = 1; i < n; i++)
 541                         (void) printf(" ");
 542                 (void) printf("[%s]", selfp->name);
 543         }

 544 }
 545 
 546 void
 547 sortchildren(nltype *parentp)
 548 {
 549         arctype *arcp;
 550         arctype *detachedp;
 551         arctype sorted;
 552         arctype *prevp;
 553 
 554         /*
 555          *      unlink children from parent,
 556          *      then insertion sort back on to sorted's children.
 557          *          *arcp       the arc you have detached and are inserting.
 558          *          *detachedp  the rest of the arcs to be sorted.
 559          *          sorted      arc list onto which you insertion sort.
 560          *          *prevp      arc before the arc you are comparing.
 561          */
 562         sorted.arc_childlist = 0;
 563 


 865 char *s1, *s2;
 866 
 867 static int
 868 namecmp(const void *arg1, const void *arg2)
 869 {
 870         nltype **npp1 = (nltype **)arg1;
 871         nltype **npp2 = (nltype **)arg2;
 872 
 873         if (!Cflag)
 874                 return (strcmp((*npp1)->name, (*npp2)->name));
 875         else {
 876                 striped_name(s1, npp1);
 877                 striped_name(s2, npp2);
 878                 return (strcmp(s1, s2));
 879         }
 880 }
 881 
 882 void
 883 striped_name(char *s, nltype **npp)
 884 {
 885         const char *d;
 886         char *c;
 887 
 888         c = (char *)s;
 889         d = demangled_name(*npp);
 890 
 891         while ((*d != '(') && (*d != '\0')) {
 892                 if (*d != ':')
 893                         *c++ = *d++;
 894                 else
 895                         d++;
 896         }
 897         *c = '\0';



 898 }
 899 
 900 /*
 901  * Checks if the current symbol name is the same as its neighbour and
 902  * returns TRUE if it is.
 903  */
 904 static bool
 905 does_clash(nltype **nlp, int ndx, int nnames)
 906 {
 907         /*
 908          * same as previous (if there's one) ?
 909          */
 910         if (ndx && (strcmp(nlp[ndx]->name, nlp[ndx-1]->name) == 0))
 911                 return (TRUE);
 912 
 913         /*
 914          * same as next (if there's one) ?
 915          */
 916         if ((ndx < (nnames - 1)) &&
 917             (strcmp(nlp[ndx]->name, nlp[ndx+1]->name) == 0)) {


1021                                         (void) printf("%6.6s ", peterbuffer);
1022                                         (void) sprintf(peterbuffer,
1023                                             "<cycle %d>", nlp->cycleno);
1024                                         (void) printf("%-19.19s", peterbuffer);
1025                                 }
1026                         }
1027                 } else {
1028                         nlp = namesortnlp[i];
1029 
1030                         if (nlp->printflag)
1031                                 (void) sprintf(peterbuffer, "[%d]", nlp->index);
1032                         else
1033                                 (void) sprintf(peterbuffer, "(%d)", nlp->index);
1034 
1035                         if (i < nnames) {
1036                                 const char *d = demangled_name(nlp);
1037 
1038                                 if (does_clash(namesortnlp, i, nnames)) {
1039                                         (void) printf("%6.6s %d:%s\n",
1040                                             peterbuffer, nlp->module->id, d);
1041                                 } else
1042                                         (void) printf("%6.6s %s\n", peterbuffer,
1043                                             d);

1044 
1045                                 if (d != nlp->name)
1046                                         (void) printf("%6.6s   [%s]", "",
1047                                             nlp->name);


1048                         } else {
1049                                 (void) printf("%6.6s ", peterbuffer);
1050                                 (void) sprintf(peterbuffer, "<cycle %d>",
1051                                     nlp->cycleno);
1052                                 (void) printf("%-33.33s", peterbuffer);
1053                         }
1054                 }
1055                 (void) printf("\n");
1056         }
1057         free(namesortnlp);
1058 }


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  *
  26  * Copyright 2018 Jason King
  27  */
  28 


  29 #include <ctype.h>
  30 #include <string.h>
  31 #include <sys/param.h>
  32 #include <stdlib.h>
  33 #include "conv.h"
  34 #include "gprof.h"
  35 
  36 void print_demangled_name(int, nltype *);
  37 void striped_name(char *, nltype **);
  38 
  39 extern long hz;
  40 
  41 /*
  42  * Symbols that must never be printed, no matter what.
  43  */
  44 char *splsym[] = {
  45         PRF_ETEXT,
  46         PRF_EXTSYM,
  47         PRF_MEMTERM,
  48         NULL


 483                                     arcp->arc_childtime / hz, arcp->arc_count,
 484                                     "");
 485 
 486                         printname(childp);
 487 
 488                         if (Cflag)
 489                                 print_demangled_name(54, childp);
 490 
 491                         (void) printf("\n");
 492                 }
 493         }
 494 }
 495 
 496 void
 497 printname(nltype *selfp)
 498 {
 499         const char  *c;
 500         c = demangled_name(selfp);
 501 
 502         if (selfp->name != 0) {



 503                 (void) printf("%s", c);
 504 
 505 #ifdef DEBUG
 506                 if (debug & DFNDEBUG)
 507                         (void) printf("{%d} ", selfp->toporder);
 508 
 509                 if (debug & PROPDEBUG)
 510                         (void) printf("%5.2f%% ", selfp->propfraction);
 511 #endif /* DEBUG */
 512         }
 513 
 514         if (selfp->cycleno != 0)
 515                 (void) printf("\t<cycle %d>", selfp->cycleno);
 516 
 517         if (selfp->index != 0) {
 518                 if (selfp->printflag)
 519                         (void) printf(" [%d]", selfp->index);
 520                 else
 521                         (void) printf(" (%d)", selfp->index);
 522         }
 523 
 524         if (c != selfp->name)
 525                 free((void *)c);
 526 }
 527 
 528 void
 529 print_demangled_name(int n, nltype *selfp)
 530 {
 531         char *c = (char *)demangled_name(selfp);
 532         int i;
 533 
 534         if (c == selfp->name)


 535                 return;
 536 
 537         (void) printf("\n");
 538         for (i = 1; i < n; i++)
 539                 (void) printf(" ");
 540         (void) printf("[%s]", selfp->name);
 541 
 542         free(c);
 543 }
 544 
 545 void
 546 sortchildren(nltype *parentp)
 547 {
 548         arctype *arcp;
 549         arctype *detachedp;
 550         arctype sorted;
 551         arctype *prevp;
 552 
 553         /*
 554          *      unlink children from parent,
 555          *      then insertion sort back on to sorted's children.
 556          *          *arcp       the arc you have detached and are inserting.
 557          *          *detachedp  the rest of the arcs to be sorted.
 558          *          sorted      arc list onto which you insertion sort.
 559          *          *prevp      arc before the arc you are comparing.
 560          */
 561         sorted.arc_childlist = 0;
 562 


 864 char *s1, *s2;
 865 
 866 static int
 867 namecmp(const void *arg1, const void *arg2)
 868 {
 869         nltype **npp1 = (nltype **)arg1;
 870         nltype **npp2 = (nltype **)arg2;
 871 
 872         if (!Cflag)
 873                 return (strcmp((*npp1)->name, (*npp2)->name));
 874         else {
 875                 striped_name(s1, npp1);
 876                 striped_name(s2, npp2);
 877                 return (strcmp(s1, s2));
 878         }
 879 }
 880 
 881 void
 882 striped_name(char *s, nltype **npp)
 883 {
 884         const char *name, *d;
 885         char *c;
 886 
 887         c = (char *)s;
 888         name = d = demangled_name(*npp);
 889 
 890         while ((*d != '(') && (*d != '\0')) {
 891                 if (*d != ':')
 892                         *c++ = *d++;
 893                 else
 894                         d++;
 895         }
 896         *c = '\0';
 897 
 898         if ((*npp)->name != name)
 899                 free((void *)name);
 900 }
 901 
 902 /*
 903  * Checks if the current symbol name is the same as its neighbour and
 904  * returns TRUE if it is.
 905  */
 906 static bool
 907 does_clash(nltype **nlp, int ndx, int nnames)
 908 {
 909         /*
 910          * same as previous (if there's one) ?
 911          */
 912         if (ndx && (strcmp(nlp[ndx]->name, nlp[ndx-1]->name) == 0))
 913                 return (TRUE);
 914 
 915         /*
 916          * same as next (if there's one) ?
 917          */
 918         if ((ndx < (nnames - 1)) &&
 919             (strcmp(nlp[ndx]->name, nlp[ndx+1]->name) == 0)) {


1023                                         (void) printf("%6.6s ", peterbuffer);
1024                                         (void) sprintf(peterbuffer,
1025                                             "<cycle %d>", nlp->cycleno);
1026                                         (void) printf("%-19.19s", peterbuffer);
1027                                 }
1028                         }
1029                 } else {
1030                         nlp = namesortnlp[i];
1031 
1032                         if (nlp->printflag)
1033                                 (void) sprintf(peterbuffer, "[%d]", nlp->index);
1034                         else
1035                                 (void) sprintf(peterbuffer, "(%d)", nlp->index);
1036 
1037                         if (i < nnames) {
1038                                 const char *d = demangled_name(nlp);
1039 
1040                                 if (does_clash(namesortnlp, i, nnames)) {
1041                                         (void) printf("%6.6s %d:%s\n",
1042                                             peterbuffer, nlp->module->id, d);
1043                                 } else {
1044                                         (void) printf("%6.6s %s\n", peterbuffer,
1045                                             d);
1046                                 }
1047 
1048                                 if (d != nlp->name) {
1049                                         (void) printf("%6.6s   [%s]", "",
1050                                             nlp->name);
1051                                         free((void *)d);
1052                                 }
1053                         } else {
1054                                 (void) printf("%6.6s ", peterbuffer);
1055                                 (void) sprintf(peterbuffer, "<cycle %d>",
1056                                     nlp->cycleno);
1057                                 (void) printf("%-33.33s", peterbuffer);
1058                         }
1059                 }
1060                 (void) printf("\n");
1061         }
1062         free(namesortnlp);
1063 }