Changeset efb8d15 in mainline for kernel/generic/src/sysinfo/sysinfo.c


Ignore:
Timestamp:
2012-03-02T15:32:13Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
196c253
Parents:
71232af
Message:

dump sysinfo in a more compact way

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/sysinfo/sysinfo.c

    r71232af refb8d15  
    464464/** Sysinfo dump indentation helper routine
    465465 *
    466  * @param depth Number of indentation characters to print.
    467  *
    468  */
    469 NO_TRACE static void sysinfo_indent(unsigned int depth)
    470 {
    471         unsigned int i;
    472         for (i = 0; i < depth; i++)
    473                 printf("  ");
     466 * @param depth Number of spaces to print.
     467 *
     468 */
     469NO_TRACE static void sysinfo_indent(size_t spaces)
     470{
     471        for (size_t i = 0; i < spaces; i++)
     472                printf(" ");
    474473}
    475474
     
    478477 * Should be called with sysinfo_lock held.
    479478 *
    480  * @param root  Root item of the current (sub)tree.
    481  * @param depth Current depth in the sysinfo tree.
    482  *
    483  */
    484 NO_TRACE static void sysinfo_dump_internal(sysinfo_item_t *root, unsigned int depth)
    485 {
    486         sysinfo_item_t *cur = root;
    487        
     479 * @param root   Root item of the current (sub)tree.
     480 * @param spaces Current indentation level.
     481 *
     482 */
     483NO_TRACE static void sysinfo_dump_internal(sysinfo_item_t *root, size_t spaces)
     484{
    488485        /* Walk all siblings */
    489         while (cur != NULL) {
    490                 sysinfo_indent(depth);
     486        for (sysinfo_item_t *cur = root; cur; cur = cur->next) {
     487                size_t length;
     488               
     489                if (spaces == 0) {
     490                        printf("%s", cur->name);
     491                        length = str_length(cur->name);
     492                } else {
     493                        sysinfo_indent(spaces);
     494                        printf(".%s", cur->name);
     495                        length = str_length(cur->name) + 1;
     496                }
    491497               
    492498                sysarg_t val;
     
    496502                switch (cur->val_type) {
    497503                case SYSINFO_VAL_UNDEFINED:
    498                         printf("+ %s\n", cur->name);
     504                        printf(" [undefined]\n");
    499505                        break;
    500506                case SYSINFO_VAL_VAL:
    501                         printf("+ %s -> %" PRIun" (%#" PRIxn ")\n", cur->name,
    502                             cur->val.val, cur->val.val);
     507                        printf(" -> %" PRIun" (%#" PRIxn ")\n", cur->val.val,
     508                            cur->val.val);
    503509                        break;
    504510                case SYSINFO_VAL_DATA:
    505                         printf("+ %s (%zu bytes)\n", cur->name,
    506                             cur->val.data.size);
     511                        printf(" (%zu bytes)\n", cur->val.data.size);
    507512                        break;
    508513                case SYSINFO_VAL_FUNCTION_VAL:
    509514                        val = cur->val.fn_val(cur);
    510                         printf("+ %s -> %" PRIun" (%#" PRIxn ") [generated]\n",
    511                             cur->name, val, val);
     515                        printf(" -> %" PRIun" (%#" PRIxn ") [generated]\n", val,
     516                            val);
    512517                        break;
    513518                case SYSINFO_VAL_FUNCTION_DATA:
    514519                        /* N.B.: No data was actually returned (only a dry run) */
    515520                        (void) cur->val.fn_data(cur, &size, true);
    516                         printf("+ %s (%zu bytes) [generated]\n", cur->name,
    517                             size);
     521                        printf(" (%zu bytes) [generated]\n", size);
    518522                        break;
    519523                default:
     
    526530                        break;
    527531                case SYSINFO_SUBTREE_TABLE:
    528                         sysinfo_dump_internal(cur->subtree.table, depth + 1);
     532                        sysinfo_dump_internal(cur->subtree.table, spaces + length);
    529533                        break;
    530534                case SYSINFO_SUBTREE_FUNCTION:
    531                         sysinfo_indent(depth + 1);
    532                         printf("+ [generated subtree]\n");
     535                        sysinfo_indent(spaces + length);
     536                        printf("<generated subtree>\n");
    533537                        break;
    534538                default:
    535                         sysinfo_indent(depth + 1);
    536                         printf("+ [unknown subtree]\n");
     539                        sysinfo_indent(spaces + length);
     540                        printf("<unknown subtree>\n");
    537541                }
    538                
    539                 cur = cur->next;
    540542        }
    541543}
Note: See TracChangeset for help on using the changeset viewer.