VirtualBox

Changeset 5207 in vbox


Ignore:
Timestamp:
Oct 9, 2007 2:40:45 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
25134
Message:

Added support for multi pattern expressions (not optimized).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/STAM.cpp

    r5202 r5207  
    613613    stamR3SnapshotPrintf(&State, "<Statistics>\n");
    614614    STAM_LOCK_RD(pVM);
    615     stamR3Enum(pVM, pszPat, stamR3SnapshotOne, &State);
     615    int rc = stamR3Enum(pVM, pszPat, stamR3SnapshotOne, &State);
    616616    STAM_UNLOCK_RD(pVM);
    617617    stamR3SnapshotPrintf(&State, "</Statistics>\n");
     618
     619    if (VBOX_SUCCESS(rc))
     620        rc = State.rc;
     621    else
     622    {
     623        RTMemFree(State.pszStart);
     624        State.pszStart = State.pszEnd = State.psz = NULL;
     625        State.cbAllocated = 0;
     626    }
    618627
    619628    /*
     
    623632    if (pcchSnapshot)
    624633        *pcchSnapshot = State.psz - State.pszStart;
    625     return State.rc;
     634    return rc;
    626635}
    627636
     
    11341143 * @param   pszName     Name to match against the pattern.
    11351144 */
    1136 static bool stamr3Match(const char *pszPat, const char *pszName)
    1137 {
    1138     if (!pszPat)
    1139         return true;
    1140 
     1145static bool stamR3Match(const char *pszPat, const char *pszName)
     1146{
    11411147    /* ASSUMES ASCII */
    11421148    for (;;)
     
    11581164                    if (    ch == chPat
    11591165                        &&  (   !chPat
    1160                              || stamr3Match(pszPat + 1, pszName)))
     1166                             || stamR3Match(pszPat + 1, pszName)))
    11611167                        return true;
    11621168                    if (!ch)
     
    11851191
    11861192/**
     1193 * Match a name against an array of patterns.
     1194 *
     1195 * @returns true if it matches, false if it doesn't match.
     1196 * @param   papszExpressions    The array of pattern expressions.
     1197 * @param   cExpressions        The number of array entries.
     1198 * @param   piExpression        Where to read/store the current skip index.
     1199 *                              This is for future use.
     1200 * @param   pszName             The name to match.
     1201 */
     1202static bool stamR3MultiMatch(const char * const *papszExpressions, unsigned cExpressions,
     1203                             unsigned *piExpression, const char *pszName)
     1204{
     1205    for (unsigned i = *piExpression; i < cExpressions; i++)
     1206    {
     1207        const char *pszPat = papszExpressions[i];
     1208        if (stamR3Match(pszPat, pszName))
     1209        {
     1210            /* later:
     1211            if (i > *piExpression)
     1212            {
     1213                check if we can skip some expressions
     1214            }*/
     1215            return true;
     1216        }
     1217    }
     1218    return false;
     1219}
     1220
     1221
     1222
     1223/**
    11871224 * Enumerates the nodes selected by a pattern or all nodes if no pattern
    11881225 * is specified.
     
    12001237static int stamR3Enum(PVM pVM, const char *pszPat, int (*pfnCallback)(PSTAMDESC pDesc, void *pvArg), void *pvArg)
    12011238{
    1202     /*
    1203      * Search for it.
    1204      */
    1205     int         rc = VINF_SUCCESS;
    1206     PSTAMDESC   pCur = pVM->stam.s.pHead;
    1207     while (pCur)
    1208     {
    1209         if (stamr3Match(pszPat, pCur->pszName))
     1239    int rc = VINF_SUCCESS;
     1240
     1241    /*
     1242     * All
     1243     */
     1244    if (!pszPat || !*pszPat || !strcmp(pszPat, "*"))
     1245    {
     1246        PSTAMDESC   pCur = pVM->stam.s.pHead;
     1247        while (pCur)
    12101248        {
    12111249            rc = pfnCallback(pCur, pvArg);
    12121250            if (rc)
    12131251                break;
     1252
     1253            /* next */
     1254            pCur = pCur->pNext;
    12141255        }
    1215 
    1216         /* next */
    1217         pCur = pCur->pNext;
     1256    }
     1257
     1258    /*
     1259     * Single expression pattern.
     1260     */
     1261    else if (!strchr(pszPat, '|'))
     1262    {
     1263        for (PSTAMDESC pCur = pVM->stam.s.pHead; pCur; pCur = pCur->pNext)
     1264            if (stamR3Match(pszPat, pCur->pszName))
     1265            {
     1266                rc = pfnCallback(pCur, pvArg);
     1267                if (rc)
     1268                    break;
     1269            }
     1270    }
     1271
     1272    /*
     1273     * Multi expression pattern.
     1274     */
     1275    else
     1276    {
     1277        /*
     1278         * Split up the pattern first.
     1279         */
     1280        char *pszCopy = RTStrDup(pszPat);
     1281        if (!pszCopy)
     1282            return VERR_NO_MEMORY;
     1283
     1284        /* count them & allocate array. */
     1285        char *psz = pszCopy;
     1286        unsigned cExpressions = 1;
     1287        while ((psz = strchr(psz, '|')) != NULL)
     1288            cExpressions++, psz++;
     1289
     1290        char **papszExpressions = (char **)RTMemTmpAlloc((cExpressions + 1) * sizeof(char *));
     1291        if (!papszExpressions)
     1292        {
     1293            RTStrFree(pszCopy);
     1294            return VERR_NO_TMP_MEMORY;
     1295        }
     1296
     1297        /* split */
     1298        psz = pszCopy;
     1299        for (unsigned i = 0;;)
     1300        {
     1301            papszExpressions[i] = psz;
     1302            if (++i >= cExpressions)
     1303                break;
     1304            psz = strchr(psz, '|');
     1305            *psz++ = '\0';
     1306        }
     1307
     1308        /* sort the array, putting '*' last. */
     1309        /** @todo sort it... */
     1310
     1311        /*
     1312         * Perform the enumeration.
     1313         */
     1314        unsigned iExpression = 0;
     1315        for (PSTAMDESC pCur = pVM->stam.s.pHead; pCur; pCur = pCur->pNext)
     1316            if (stamR3MultiMatch(papszExpressions, cExpressions, &iExpression, pCur->pszName))
     1317            {
     1318                rc = pfnCallback(pCur, pvArg);
     1319                if (rc)
     1320                    break;
     1321            }
     1322
     1323        RTMemTmpFree(papszExpressions);
     1324        RTStrFree(pszCopy);
    12181325    }
    12191326
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette