Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

static int KPRF_NAME() WriteHtmlReport ( KPRF_TYPE(P, REPORT)  pReport,
FILE *  pOut 
) [static]

Writes an HTML report.

Returns:
0 on success.

-1 on failure.

Parameters:
pReport The report to put into HTML.
pOut The file stream to write the HTML to.

Definition at line 1252 of file prfreader.cpp.h.

References FuncCompareCallsFrom(), FuncCompareCallsTo(), FuncCompareOnStack(), FuncCompareOnStackAvg(), FuncCompareOnStackMax(), FuncCompareOnStackMin(), FuncCompareOnTopOfStack(), FuncCompareOnTopOfStackAvg(), FuncCompareOnTopOfStackMax(), FuncCompareOnTopOfStackMin(), HtmlWriteSortedFunctions(), KPRF_NAME, KPRF_OFF2PTR, and KPRF_TYPE.

{
    KPRF_TYPE(PC,HDR) pHdr = pReport->pHdr;

    /*
     * Write the standard html.
     */
    fprintf(pOut,
            "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
            "<html>\n"
            "<head>\n"
            "  <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n"
            "  <title>kProfiler 2 - %s</title>\n"
            "</head>\n"
            "<style>\n"
            "table\n"
            "{\n"
//            "  width: 90%%;\n"
            "  background: #999999;\n"
//            "  margin-top: .6em;\n"
//            "  margin-bottom: .3em;\n"
            "}\n"
            "th\n"
            "{\n"
            "  padding: 1px 4px;\n"
            "  background: #cccccc;\n"
//            "  text-align: left;\n"
            "  font-size: 90%%;\n"
            //"  width: 30%%;\n"
            "}\n"
            "td\n"
            "{\n"
            "  padding: 1px 4px;\n"
            "  background: #ffffff;\n"
            "  font-size: 90%%;\n"
            "}\n"
            "td.Ticks\n"
            "{\n"
            "  text-align: right;\n"
            "}\n"
            "td.TicksRow\n"
            "{\n"
            "  text-align: right;\n"
            "}\n"
            "td.MinMaxTicks\n"
            "{\n"
            "  text-align: right;\n"
            "}\n"
            "td.MinMaxTicksRow\n"
            "{\n"
            "  text-align: right;\n"
            "}\n"
            "td.Parts\n"
            "{\n"
            "  text-align: right;\n"
            "}\n"
            "td.PartsRow\n"
            "{\n"
            "  text-align: left;\n"
            "}\n"
            "td.Calls\n"
            "{\n"
            "  text-align: right;\n"
            "}\n"
            "td.CallsRow\n"
            "{\n"
            "  text-align: right;\n"
            "}\n"
            "td.BlankRow\n"
            "{\n"
            "  background: #e0e0e0;\n"
            "}\n"
            "td.Name\n"
            "{\n"
            "  font-weight: bold;\n"
            "}\n"
            "table.Summary th\n"
            "{\n"
            "  width:200px;\n"
            "}\n"
            "table.Thread\n"
            "{\n"
            "  min-width:60%%\n"
            "}\n"
            "table.Thread th\n"
            "{\n"
            "  width:200px;\n"
            "}\n"
            "table.Functions\n"
            "{\n"
            "  width:60%%;\n"
            "}\n"
            "table.Functions th\n"
            "{\n"
            "  width:200px;\n"
            "}\n"
            "table.Modules\n"
            "{\n"
            "  width:60%%;\n"
            "}\n"
            "table.Modules th\n"
            "{\n"
            "  width:200px;\n"
            "}\n"
            "table.FunctionsSorted\n"
            "{\n"
            "}\n"
            "</style>\n"
            "<body topmargin=\"0\">\n"
            ,
            pHdr->offCommandLine
                ? (const char *)KPRF_OFF2PTR(P,FUNC, pHdr->offCommandLine, pHdr)
                : ""
            );

    /*
     * Table of contents.
     */
    fprintf(pOut,
            "<h2>Table of Contents</h2>\n"
            "\n"
            "<ul>\n"
            "  <li><a href=\"#Summary\"  >1.0 Summary</a></li>\n"
            "  <li><a href=\"#Functions\">2.0 Functions</a></li>\n"
            "      <ul>\n"
            "        <li><a href=\"#Functions-TimeOnStack\"     >2.1 Time On Stack</a></li>\n"
            "          <ul>\n"
            "            <li><a href=\"#Functions-TimeOnStack-Avg\"     >2.2.1 Time On Stack - Average</a></li>\n"
            "            <li><a href=\"#Functions-TimeOnStack-Min\"     >2.2.1 Time On Stack - Min</a></li>\n"
            "            <li><a href=\"#Functions-TimeOnStack-Max\"     >2.2.2 Time On Stack - Max</a></li>\n"
            "          </ul>\n"
            "        <li><a href=\"#Functions-TimeOnTopOfStack\">2.3 Time On Top Of Stack</a></li>\n"
            "          <ul>\n"
            "            <li><a href=\"#Functions-TimeOnTopOfStack-Avg\">2.3.1 Time On Top Of Stack - Average</a></li>\n"
            "            <li><a href=\"#Functions-TimeOnTopOfStack-Min\">2.3.2 Time On Top Of Stack - Min</a></li>\n"
            "            <li><a href=\"#Functions-TimeOnTopOfStack-Max\">2.3.3 Time On Top Of Stack - Max</a></li>\n"
            "          </ul>\n"
            "        <li><a href=\"#Functions-CallsTo\"         >2.3 Calls To</a></li>\n"
            "        <li><a href=\"#Functions-CallsFrom\"       >2.4 Calls From</a></li>\n"
            "        <li><a href=\"#Function-Details\"          >2.5 Function Details</a></li>\n"
            "      </ul>\n"
            "  <li><a href=\"#Threads\"  >3.0 Threads</a></li>\n"
            "  <li><a href=\"#Modules\"  >4.0 Modules</a></li>\n"
            "</ul>\n"
            "\n"
            "\n");

    /*
     * Summary.
     */
    fprintf(pOut,
            "<h2><a name=\"Summary\">1.0 Summary</a></h2>\n"
            "\n"
            "<p>\n"
            "<table class=\"Summary\">\n");
    if (pHdr->offCommandLine)
        KPRF_NAME(HtmlWriteRowString)(pOut, "Command Line", NULL, "%s", (const char *)KPRF_OFF2PTR(P,FUNC, pHdr->offCommandLine, pHdr));
    KPRF_NAME(HtmlWriteRowU32X32)(pOut, "Threads", pHdr->cThreads, NULL);
    KPRF_NAME(HtmlWriteRowU32X32)(pOut, "Modules", pReport->cMods, NULL);
    KPRF_NAME(HtmlWriteRowU32X32)(pOut, "Functions", pHdr->cFunctions, NULL);
    KPRF_NAME(HtmlWriteRowTicks)(pOut, "Profiled", pReport->ProfiledTicks, pReport->ProfiledTicks);
    KPRF_NAME(HtmlWriteRowTicks)(pOut, "Sleep", pReport->SleepTicks, pReport->ProfiledTicks);
    KPRF_NAME(HtmlWriteRowTicks)(pOut, "Overhead", pReport->OverheadTicks, pReport->ProfiledTicks + pReport->OverheadTicks);
    KPRF_NAME(HtmlWriteRowCalls)(pOut, "Recorded Calls", pReport->cCalls, pReport->cCalls);
    fprintf(pOut, "<tr><td class=\"BlankRow\" colspan=7>&nbsp;</td></tr>\n");
    KPRF_NAME(HtmlWriteRowString)(pOut, "kProfiler Version ", NULL, "Mark 2 Alpha 1");
    KPRF_NAME(HtmlWriteRowString)(pOut, "kProfiler Build Time ", NULL, __DATE__ " " __TIME__);
    fprintf(pOut,
            "</table>\n"
            "</p>\n"
            "\n"
            "\n");

    /*
     * Functions.
     */
    fprintf(pOut,
            "<h2><a name=\"Functions\">2.0 Functions</a></h2>\n"
            "\n");

    qsort(&pReport->papSortedFunctions[0], pHdr->cFunctions, sizeof(pReport->papSortedFunctions[0]), KPRF_NAME(FuncCompareOnStack));
    KPRF_NAME(HtmlWriteSortedFunctions)(pReport, pOut, "Functions-TimeOnStack",     "2.1 Time On Stack", KPRF_TYPE(,FIRSTCOLUMN_ON_STACK));
    qsort(&pReport->papSortedFunctions[0], pHdr->cFunctions, sizeof(pReport->papSortedFunctions[0]), KPRF_NAME(FuncCompareOnStackAvg));
    KPRF_NAME(HtmlWriteSortedFunctions)(pReport, pOut, "Functions-TimeOnStack-Avg",     "2.2.1 Time On Stack - Average", KPRF_TYPE(,FIRSTCOLUMN_ON_STACK));
    qsort(&pReport->papSortedFunctions[0], pHdr->cFunctions, sizeof(pReport->papSortedFunctions[0]), KPRF_NAME(FuncCompareOnStackMin));
    KPRF_NAME(HtmlWriteSortedFunctions)(pReport, pOut, "Functions-TimeOnStack-Min",     "2.2.2 Time On Stack - Min", KPRF_TYPE(,FIRSTCOLUMN_ON_STACK));
    qsort(&pReport->papSortedFunctions[0], pHdr->cFunctions, sizeof(pReport->papSortedFunctions[0]), KPRF_NAME(FuncCompareOnStackMax));
    KPRF_NAME(HtmlWriteSortedFunctions)(pReport, pOut, "Functions-TimeOnStack-Max",     "2.2.3 Time On Stack - Max", KPRF_TYPE(,FIRSTCOLUMN_ON_STACK));

    qsort(&pReport->papSortedFunctions[0], pHdr->cFunctions, sizeof(pReport->papSortedFunctions[0]), KPRF_NAME(FuncCompareOnTopOfStack));
    KPRF_NAME(HtmlWriteSortedFunctions)(pReport, pOut, "Functions-TimeOnTopOfStack",    "2.2 Time On Top Of Stack", KPRF_TYPE(,FIRSTCOLUMN_ON_TOP_OF_STACK));
    qsort(&pReport->papSortedFunctions[0], pHdr->cFunctions, sizeof(pReport->papSortedFunctions[0]), KPRF_NAME(FuncCompareOnTopOfStackAvg));
    KPRF_NAME(HtmlWriteSortedFunctions)(pReport, pOut, "Functions-TimeOnTopOfStack-Avg","2.2.1 Time On Top Of Stack - Average", KPRF_TYPE(,FIRSTCOLUMN_ON_TOP_OF_STACK));
    qsort(&pReport->papSortedFunctions[0], pHdr->cFunctions, sizeof(pReport->papSortedFunctions[0]), KPRF_NAME(FuncCompareOnTopOfStackMin));
    KPRF_NAME(HtmlWriteSortedFunctions)(pReport, pOut, "Functions-TimeOnTopOfStack-Min","2.2.2 Time On Top Of Stack - Min", KPRF_TYPE(,FIRSTCOLUMN_ON_TOP_OF_STACK));
    qsort(&pReport->papSortedFunctions[0], pHdr->cFunctions, sizeof(pReport->papSortedFunctions[0]), KPRF_NAME(FuncCompareOnTopOfStackMax));
    KPRF_NAME(HtmlWriteSortedFunctions)(pReport, pOut, "Functions-TimeOnTopOfStack-Max","2.2.3 Time On Top Of Stack - Max", KPRF_TYPE(,FIRSTCOLUMN_ON_TOP_OF_STACK));

    qsort(&pReport->papSortedFunctions[0], pHdr->cFunctions, sizeof(pReport->papSortedFunctions[0]), KPRF_NAME(FuncCompareCallsTo));
    KPRF_NAME(HtmlWriteSortedFunctions)(pReport, pOut, "Functions-CallsTo",         "2.4 Calls To", KPRF_TYPE(,FIRSTCOLUMN_CALLS_TO));

    qsort(&pReport->papSortedFunctions[0], pHdr->cFunctions, sizeof(pReport->papSortedFunctions[0]), KPRF_NAME(FuncCompareCallsFrom));
    KPRF_NAME(HtmlWriteSortedFunctions)(pReport, pOut, "Functions-CallsFrom",       "2.5 Calls From", KPRF_TYPE(,FIRSTCOLUMN_CALLS_FROM));

    fprintf(pOut,
            "<h2><a name=\"Function-Details\">2.5 Function Details</a></h2>\n"
            "\n"
            "<p>\n"
            "<table class=\"Functions\">\n");
    for (KU32 iFunc = 0; iFunc < pHdr->cFunctions; iFunc++)
    {
        KPRF_TYPE(P,REPORTFUNC) pReportFunc = &pReport->paFunctions[iFunc];
        KPRF_TYPE(PC,FUNC) pFunc = pReportFunc->pFunc;

        fprintf(pOut,
                "<tr><td class=\"BlankRow\" colspan=7><a name=\"Func-%u\">&nbsp;</a></td></tr>\n",
                iFunc);
        KPRF_NAME(HtmlWriteRowU32)(pOut, "Function No.", iFunc, NULL);
        if (pReportFunc->pSym)
            KPRF_NAME(HtmlWriteRowString)(pOut, "Name", "Name", "%s", pReportFunc->pSym->szName);
        if (pReportFunc->pLine)
            KPRF_NAME(HtmlWriteRowString)(pOut, "Location", NULL, "<a href=\"file:///%s\">%s</a> Line #%d",
                                          pReportFunc->pLine->szFile, pReportFunc->pLine->szFile, pReportFunc->pLine->iLine);
        if (pReportFunc->pModSeg)
        {
            KPRF_NAME(HtmlWriteRowString)(pOut, "Module", NULL, "<a href=\"#Mod-%u\">%s</a>",
                                          pReportFunc->pModSeg->pMod->iMod, pReportFunc->pModSeg->pModSeg->szPath);
            KPRF_NAME(HtmlWriteRowString)(pOut, "Segment:Offset", NULL, "%x:%" KPRF_FMT_UPTR,
                                          pReportFunc->pModSeg->pModSeg->iSegment,
                                          pFunc->uEntryPtr - pReportFunc->pModSeg->pModSeg->uBasePtr);
        }
        KPRF_NAME(HtmlWriteRowUPTR)(pOut, "Address", pFunc->uEntryPtr, NULL);

        KPRF_NAME(HtmlWriteRowTimeStat)(pOut, "On Stack", &pFunc->OnStack, pReport->ProfiledTicks);
        KPRF_NAME(HtmlWriteRowTimeStat)(pOut, "On Top Of Stack", &pFunc->OnTopOfStack, pReport->ProfiledTicks);
        KPRF_NAME(HtmlWriteRowCalls)(pOut, "Calls To", pFunc->cOnStack, pReport->cCalls);
        KPRF_NAME(HtmlWriteRowCalls)(pOut, "Calls From", pFunc->cCalls, pReport->cCalls);

        fprintf(pOut,
                "\n");
    }
    fprintf(pOut,
            "</table>\n"
            "</p>\n"
            "\n");

    /*
     * Threads.
     */
    fprintf(pOut,
            "<h2><a name=\"Threads\">3.0 Threads</a></h2>\n"
            "\n"
            "<p>\n"
            "<table class=\"Threads\">\n");

    for (KU32 iThread = 0; iThread < pHdr->cThreads; iThread++)
    {
        KPRF_TYPE(PC,THREAD) pThread = pReport->paThreads[iThread].pThread;

        fprintf(pOut,
                "<tr><td class=\"BlankRow\" colspan=7><a name=\"Thread-%u\">&nbsp;</a></td></tr>\n",
                iThread);
        KPRF_NAME(HtmlWriteRowU32)(pOut, "Thread No.", iThread, NULL);
        KPRF_NAME(HtmlWriteRowX64)(pOut, "Thread Id", pThread->ThreadId, NULL);
        if (pThread->szName[0])
            KPRF_NAME(HtmlWriteRowString)(pOut, "Name", "Name", "%s", pThread->szName);
        KPRF_NAME(HtmlWriteRowUPTR)(pOut, "Stack Base Address", pThread->uStackBasePtr, NULL);
        KPRF_NAME(HtmlWriteRowUPTR)(pOut, "Max Stack Depth", pThread->cbMaxStack, "bytes");
        //KPRF_NAME(HtmlWriteRowUPTR)(pOut, "Max Stack Depth", pThread->cMaxFrames, "frames"); /** @todo max stack frames! */
        KPRF_NAME(HtmlWriteRowTicks)(pOut, "Profiled", pThread->ProfiledTicks, pReport->ProfiledTicks);
        KPRF_NAME(HtmlWriteRowTicks)(pOut, "Sleep", pThread->SleepTicks, pReport->ProfiledTicks);
        KPRF_NAME(HtmlWriteRowTicks)(pOut, "Overhead", pThread->OverheadTicks, pReport->ProfiledTicks + pReport->OverheadTicks);
        KPRF_NAME(HtmlWriteRowCalls)(pOut, "Recorded Calls",  pThread->cCalls, pReport->cCalls);
        KPRF_NAME(HtmlWriteRowU64)(pOut, "Unwinds", pThread->cUnwinds, NULL);
        KPRF_NAME(HtmlWriteRowU64)(pOut, "Profiler Stack Overflows", pThread->cOverflows, NULL);
        KPRF_NAME(HtmlWriteRowU64)(pOut, "Profiler Stack Switch Rejects", pThread->cStackSwitchRejects, NULL);

        fprintf(pOut,
                "\n");
    }
    fprintf(pOut,
            "</table>\n"
            "</p>\n"
            "\n");


    /*
     * Modules.
     */
    fprintf(pOut,
            "<h2><a name=\"Modules\">4.0 Modules</a></h2>\n"
            "\n"
            "<p>\n"
            "<table class=\"Modules\">\n");

    KPRF_TYPE(P,REPORTMOD) pMod = pReport->pFirstMod;
    KU32 iMod = 0;
    while (pMod)
    {
        fprintf(pOut,
                "<a name=\"Mod-%u\">\n"
                "<tr><td class=\"BlankRow\" colspan=7><a name=\"Module-%u\">&nbsp;</a></td></tr>\n",
                iMod);
        KPRF_NAME(HtmlWriteRowU32)(pOut, "Module No.", iMod, NULL);
        KPRF_NAME(HtmlWriteRowString)(pOut, "Name", "Name", "%s", pMod->pFirstSeg->pModSeg->szPath);

        for (KPRF_TYPE(P,REPORTMODSEG) pSeg = pMod->pFirstSeg; pSeg; pSeg = pSeg->pNext)
        {
            char szName[64];
            sprintf(szName, "Segment No.%u - Base", pSeg->pModSeg->iSegment);
            KPRF_NAME(HtmlWriteRowUPTR)(pOut, szName, pSeg->pModSeg->uBasePtr, NULL);
            sprintf(szName, "Segment No.%u - Size", pSeg->pModSeg->iSegment);
            KPRF_NAME(HtmlWriteRowUPTR)(pOut, szName,
                                        pSeg->pModSeg->cbSegmentMinusOne + 1 > pSeg->pModSeg->cbSegmentMinusOne
                                        ? pSeg->pModSeg->cbSegmentMinusOne + 1
                                        : pSeg->pModSeg->cbSegmentMinusOne,
                                        NULL);
        }

        KPRF_NAME(HtmlWriteRowTicks)(pOut, "On Stack", pMod->OnStackTicks, pReport->ProfiledTicks);
        KPRF_NAME(HtmlWriteRowTicks)(pOut, "On Top Of Stack", pMod->OnTopOfStackTicks, pReport->ProfiledTicks);
        KPRF_NAME(HtmlWriteRowU32)(pOut, "Functions", pMod->cFunctions, NULL);

        fprintf(pOut,
                "\n");

        /* next */
        iMod++;
        pMod = pMod->pNext;
    }
    fprintf(pOut,
            "</table>\n"
            "</p>\n"
            "\n");


    /*
     * The End.
     */
    fprintf(pOut,
            "</body>\n"
            "</html>\n");
    return 0;
}


Generated by  Doxygen 1.6.0   Back to index