6#include "dawn/proto/shell/pretty.hxx"
8#ifdef CONFIG_DAWN_PROTO_SHELL_INSPECT
13# include "dawn/common/object.hxx"
14# include "dawn/common/objectid.hxx"
15# include "dawn/dev/inspector.hxx"
16# include "dawn/io/common.hxx"
17# include "dawn/io/config.hxx"
21# define DAWN_PROTO_SHELL_LIST_ARG_MAX 64
23void CProtoShellPretty::cmdList(
const char *arg)
40 if (arg !=
nullptr && arg[0] !=
'\0')
42 char argbuf[DAWN_PROTO_SHELL_LIST_ARG_MAX];
43 char *saveptr =
nullptr;
45 bool filtered =
false;
47 std::strncpy(argbuf, arg,
sizeof(argbuf) - 1);
48 argbuf[
sizeof(argbuf) - 1] =
'\0';
50 token = strtok_r(argbuf,
" \t", &saveptr);
51 while (token !=
nullptr)
53 if (std::strcmp(token,
"verbose") == 0 || std::strcmp(token,
"full") == 0)
57 else if (std::strcmp(token,
"io") == 0)
68 else if (std::strcmp(token,
"prog") == 0)
79 else if (std::strcmp(token,
"proto") == 0)
92 fprintf(outstream,
"Usage: list [io|prog|proto] [verbose]\n");
96 token = strtok_r(
nullptr,
" \t", &saveptr);
100 inspector = CDevInspector::getInst();
102 fprintf(outstream,
"\n");
103 fprintf(outstream,
"Object Inventory\n");
104 fprintf(outstream,
"================\n\n");
111 fprintf(outstream,
"IOs: %zu objects\n", count);
115# ifdef CONFIG_DAWN_IO_HAS_STATS
119 " Name ObjID Type Cls DType Dim Size Flags "
122 " -------------- ---------- ---- ---- ------ --- ---- ------ "
127 fprintf(outstream,
" Name ObjID DType[Dim] Cls Flags R/W/E\n");
128 fprintf(outstream,
" -------------- ---------- ----------- --- ------ -------\n");
133 fprintf(outstream,
" Name ObjID Type Cls DType Dim Size Flags\n");
134 fprintf(outstream,
" -------------- ---------- ---- ---- ------ --- ---- ------\n");
138 fprintf(outstream,
" Name ObjID DType[Dim] Cls Flags\n");
139 fprintf(outstream,
" -------------- ---------- ----------- --- ------\n");
143 for (i = 0; i < count; i++)
145 io = inspector->
getIO(i);
153 fprintf(outstream,
" %-14s ", io->getName());
154 fprintf(outstream,
"0x%08" PRIx32
" ", io->
getIdV());
159 SObjectId::dtypeToString(io->
getDtype()));
165 " %-14s 0x%08" PRIx32
" %s[%zu] %3d ",
168 SObjectId::dtypeToString(io->
getDtype()),
176 io->isWrite() ?
'W' :
'-',
177 io->isNotify() ?
'N' :
'-',
178 io->isTimestamp() ?
'T' :
'-',
179 io->getCfgFlag() ?
'C' :
'-');
181# ifdef CONFIG_DAWN_IO_HAS_STATS
182 const auto &stats = io->getStats();
186 " %6" PRIu32
"/%6" PRIu32
"/%6" PRIu32
"\n",
194 " %" PRIu32
"/%" PRIu32
"/%" PRIu32
"\n",
200 fprintf(outstream,
"\n");
205 fprintf(outstream,
"\n");
213 fprintf(outstream,
"PROGs: %zu objects\n", count);
219 fprintf(outstream,
" Name ObjID Type Cls Running\n");
220 fprintf(outstream,
" -------------- ---------- ---- ---- -------\n");
224 fprintf(outstream,
" Name ObjID Cls State\n");
225 fprintf(outstream,
" -------------- ---------- --- -------\n");
228 for (i = 0; i < count; i++)
238 fprintf(outstream,
" %-14s ", obj->getName());
239 fprintf(outstream,
"0x%08" PRIx32
" ", obj->
getIdV());
244 obj->
getState() == CObject::STATE_RUNNING ?
"YES" :
"NO");
249 " %-14s 0x%08" PRIx32
" %3d %s\n",
253 obj->
getState() == CObject::STATE_RUNNING ?
"RUNNING" :
"STOPPED");
258 fprintf(outstream,
"\n");
266 fprintf(outstream,
"PROTOs: %zu objects\n", count);
272 fprintf(outstream,
" Name ObjID Type Cls Running\n");
273 fprintf(outstream,
" -------------- ---------- ---- ---- -------\n");
277 fprintf(outstream,
" Name ObjID Cls State\n");
278 fprintf(outstream,
" -------------- ---------- --- -------\n");
281 for (i = 0; i < count; i++)
291 fprintf(outstream,
" %-14s ", obj->getName());
292 fprintf(outstream,
"0x%08" PRIx32
" ", obj->
getIdV());
297 obj->
getState() == CObject::STATE_RUNNING ?
"YES" :
"NO");
302 " %-14s 0x%08" PRIx32
" %3d %s\n",
306 obj->
getState() == CObject::STATE_RUNNING ?
"RUNNING" :
"STOPPED");
311 fprintf(outstream,
"\n");
314 fprintf(outstream,
"Flags: R=Read W=Write N=Notify T=Timestamp C=Config\n");
315# ifdef CONFIG_DAWN_IO_HAS_STATS
316 fprintf(outstream,
"Stats: R=Reads W=Writes E=Errors\n");
318 fprintf(outstream,
"Use 'list io|prog|proto' to filter and 'list verbose' for details.\n");
319 fprintf(outstream,
"\n");
322void CProtoShellPretty::cmdInspect(
const char *arg)
328 const char *handler_type;
330 if (!arg || arg[0] ==
'\0')
332 fprintf(outstream,
"Usage: inspect <object_id>\n");
333 fprintf(outstream,
" object_id: hex (0xNNNNNNNN) or decimal\n");
339 objid_val = strtoul(arg, &endptr, 0);
340 if (*endptr !=
'\0' && *endptr !=
' ' && *endptr !=
'\t')
342 fprintf(outstream,
"Error: invalid object ID '%s'\n", arg);
348 inspector = CDevInspector::getInst();
353 fprintf(outstream,
"Error: object 0x%08" PRIx32
" not found\n", objid_val);
361 case SObjectId::OBJTYPE_IO:
364 case SObjectId::OBJTYPE_PROG:
365 handler_type =
"PROG";
367 case SObjectId::OBJTYPE_PROTO:
368 handler_type =
"PROTO";
371 handler_type =
"UNKNOWN";
377 fprintf(outstream,
"\n");
378 fprintf(outstream,
"Object Details\n");
379 fprintf(outstream,
"==============\n\n");
380 fprintf(outstream,
" Name: %s\n", obj->getName());
381 fprintf(outstream,
" Object ID: 0x%08" PRIx32
"\n", obj->
getIdV());
382 fprintf(outstream,
" Handler: %s\n", handler_type);
383 fprintf(outstream,
"\n");
387 fprintf(outstream,
" Type: 0x%02x ", obj->
getType());
390 case SObjectId::OBJTYPE_IO:
391 fprintf(outstream,
"(IO)\n");
393 case SObjectId::OBJTYPE_PROG:
394 fprintf(outstream,
"(PROG)\n");
396 case SObjectId::OBJTYPE_PROTO:
397 fprintf(outstream,
"(PROTO)\n");
400 fprintf(outstream,
"(UNKNOWN)\n");
404 fprintf(outstream,
" Class: 0x%03x (%u)\n", obj->
getCls(), obj->
getCls());
405 fprintf(outstream,
" Data Type: 0x%02x ", obj->
getDtype());
409 if (obj->
getDtype() == SObjectId::DTYPE_ANY)
411 fprintf(outstream,
"(%s)\n", SObjectId::dtypeToString(obj->
getDtype()));
413 else if (obj->
getDtype() == SObjectId::DTYPE_BLOCK)
415 fprintf(outstream,
"(%s)\n", SObjectId::dtypeToString(obj->
getDtype()));
421 SObjectId::dtypeToString(obj->
getDtype()),
425 if (obj->
getType() == SObjectId::OBJTYPE_IO)
429 " Dimension: %zu (item size %zu bytes)\n",
434 fprintf(outstream,
" Flags: 0x%02x\n", obj->
getFlags());
435 fprintf(outstream,
" Instance: %u\n", obj->
getPriv());
436 fprintf(outstream,
"\n");
442 fprintf(outstream,
" Config: Yes\n");
446 fprintf(outstream,
" Config: No\n");
449 fprintf(outstream,
"\n");
453 if (obj->
getType() == SObjectId::OBJTYPE_IO && obj->
getCls() == CIOCommon::IO_CLASS_CONFIG)
457 fprintf(outstream,
"ConfigIO Bindings\n");
458 fprintf(outstream,
"-----------------\n");
460 if (cfg_io->
map.empty())
462 fprintf(outstream,
" (no bindings)\n");
466 for (
const auto &[
id, bound_obj] : cfg_io->map)
470 const char *type_str =
"UNKNOWN";
472 switch (bound_obj->getType())
474 case SObjectId::OBJTYPE_IO:
477 case SObjectId::OBJTYPE_PROG:
480 case SObjectId::OBJTYPE_PROTO:
486 " -> %s: %s (0x%08" PRIx32
")\n",
488 bound_obj->getName(),
489 bound_obj->getIdV());
493 fprintf(outstream,
" -> 0x%08" PRIx32
" (not bound yet)\n",
id);
498 fprintf(outstream,
"\n");
503# ifdef CONFIG_DAWN_IO_HAS_STATS
504 if (obj->
getType() == SObjectId::OBJTYPE_IO)
507 const CIOCommon::IOStats &stats = io->getStats();
508 fprintf(outstream,
"Statistics\n");
509 fprintf(outstream,
"----------\n");
510 fprintf(outstream,
" Reads: %" PRIu32
"\n", stats.read_count);
511 fprintf(outstream,
" Writes: %" PRIu32
"\n", stats.write_count);
512 fprintf(outstream,
" Errors: %" PRIu32
"\n", stats.error_count);
513 fprintf(outstream,
"\n");
518void CProtoShellPretty::cmdTree(
const char *arg)
530 const CObject *bound_objs[128];
531 size_t binding_count;
533 size_t io_binding_count;
540 inspector = CDevInspector::getInst();
542 fprintf(outstream,
"\n");
543 fprintf(outstream,
"Data Flow Tree\n");
544 fprintf(outstream,
"==============\n\n");
550 if (proto_count == 0)
552 fprintf(outstream,
"(no protocol objects)\n\n");
556 for (i = 0; i < proto_count; i++)
559 if (proto ==
nullptr)
564 fprintf(outstream,
"PROTO: %s\n", proto->getName());
568 if (binding_count > 0)
570 for (j = 0; j < binding_count; j++)
572 const bool is_last = (j == binding_count - 1);
573 const char *branch = is_last ?
"└──" :
"├──";
574 const char *cont = is_last ?
" " :
"│ ";
576 bound_obj = bound_objs[j];
580 if (bound_obj->
getType() == SObjectId::OBJTYPE_PROG)
582 fprintf(outstream,
"%s PROG: %s\n", branch, bound_obj->getName());
592 if (io_binding_count > 0)
596 for (io_idx = 0; io_idx < io_binding_count; io_idx++)
598 const bool io_last = (io_idx == io_binding_count - 1);
599 const char *io_branch = io_last ?
"└──" :
"├──";
605 io_bindings[io_idx]->getName());
613 else if (bound_obj->
getType() == SObjectId::OBJTYPE_IO)
615 fprintf(outstream,
"%s IO: %s\n", branch, bound_obj->getName());
621 fprintf(outstream,
" (no bindings)\n");
624 fprintf(outstream,
"\n");
633 for (i = 0; i < prog_count; i++)
645 for (j = 0; j < proto_count; j++)
649 for (k = 0; k < binding_count; k++)
651 if (bound_objs[k]->getIdV() == prog->
getIdV())
668 fprintf(outstream,
"Unbound PROG objects:\n");
672 fprintf(outstream,
" * %s\n", prog->getName());
676 if (io_binding_count > 0)
678 fprintf(outstream,
" └── Bound I/O: ");
680 for (k = 0; k < io_binding_count; k++)
684 fprintf(outstream,
", ");
687 fprintf(outstream,
"%s", io_bindings[k]->getName());
690 fprintf(outstream,
"\n");
697 fprintf(outstream,
"\n");
705 for (i = 0; i < io_count; i++)
707 io = inspector->
getIO(i);
715 if (io->
getCls() == CIOCommon::IO_CLASS_CONFIG)
721 fprintf(outstream,
"ConfigIO objects:\n");
725 fprintf(outstream,
" * %s\n", io->getName());
727 if (!cfg_io->
map.empty())
729 for (
const auto &[
id, cfg_bound_obj] : cfg_io->map)
733 const char *type_str =
"UNKNOWN";
735 switch (cfg_bound_obj->getType())
737 case SObjectId::OBJTYPE_IO:
740 case SObjectId::OBJTYPE_PROG:
743 case SObjectId::OBJTYPE_PROTO:
749 " └── Configures %s: %s\n",
751 cfg_bound_obj->getName());
760 fprintf(outstream,
"\n");
766 for (i = 0; i < io_count; i++)
768 io = inspector->
getIO(i);
776 if (io->
getCls() == CIOCommon::IO_CLASS_CONFIG)
785 for (j = 0; j < proto_count; j++)
789 for (k = 0; k < binding_count; k++)
791 if (bound_objs[k]->getIdV() == io->
getIdV())
808 for (j = 0; j < prog_count; j++)
812 for (k = 0; k < io_binding_count; k++)
814 if (io_bindings[k]->getIdV() == io->
getIdV())
832 fprintf(outstream,
"Unbound I/O objects:\n");
836 fprintf(outstream,
" * %s\n", io->getName());
842 fprintf(outstream,
"\n");
846void CProtoShellPretty::cmdStats(
const char *arg)
850# ifdef CONFIG_DAWN_IO_HAS_STATS
851 uint32_t total_reads;
852 uint32_t total_writes;
853 uint32_t total_errors;
861 const CIOCommon::IOStats *stats;
866 inspector = CDevInspector::getInst();
868 fprintf(outstream,
"\n");
869 fprintf(outstream,
"I/O Statistics\n");
870 fprintf(outstream,
"==============\n\n");
876 fprintf(outstream,
"No I/O objects registered\n");
880# ifdef CONFIG_DAWN_IO_HAS_STATS
889 most_reads =
nullptr;
890 most_writes =
nullptr;
896 for (i = 0; i < io_count; i++)
898 io = inspector->
getIO(i);
904 stats = &io->getStats();
905 total_reads += stats->read_count;
906 total_writes += stats->write_count;
907 total_errors += stats->error_count;
909 if (stats->read_count > max_reads)
911 max_reads = stats->read_count;
915 if (stats->write_count > max_writes)
917 max_writes = stats->write_count;
924 fprintf(outstream,
"Summary\n");
925 fprintf(outstream,
"-------\n");
926 fprintf(outstream,
" Total I/O Objects: %zu\n", io_count);
927 fprintf(outstream,
" Total Reads: %" PRIu32
"\n", total_reads);
928 fprintf(outstream,
" Total Writes: %" PRIu32
"\n", total_writes);
929 fprintf(outstream,
" Total Errors: %" PRIu32
"\n", total_errors);
930 fprintf(outstream,
"\n");
934 if (most_reads && max_reads > 0)
936 fprintf(outstream,
"Most Read I/O\n");
937 fprintf(outstream,
"-------------\n");
938 fprintf(outstream,
" Name: %s\n", most_reads->getName());
939 fprintf(outstream,
" Object ID: 0x%08" PRIx32
"\n", most_reads->
getIdV());
940 fprintf(outstream,
" Read Count: %" PRIu32
"\n", max_reads);
941 fprintf(outstream,
"\n");
944 if (most_writes && max_writes > 0)
946 fprintf(outstream,
"Most Written I/O\n");
947 fprintf(outstream,
"----------------\n");
948 fprintf(outstream,
" Name: %s\n", most_writes->getName());
949 fprintf(outstream,
" Object ID: 0x%08" PRIx32
"\n", most_writes->
getIdV());
950 fprintf(outstream,
" Write Count: %" PRIu32
"\n", max_writes);
951 fprintf(outstream,
"\n");
958 for (i = 0; i < io_count; i++)
960 io = inspector->
getIO(i);
966 stats = &io->getStats();
968 if (stats->error_count > 0)
972 fprintf(outstream,
"I/O Objects with Errors\n");
973 fprintf(outstream,
"-----------------------\n");
978 " %-14s 0x%08" PRIx32
" - %" PRIu32
" errors\n",
987 fprintf(outstream,
"No errors recorded.\n");
990 fprintf(outstream,
"\n");
993 "Statistics tracking is disabled.\n"
994 "Enable CONFIG_DAWN_IO_HAS_STATS to track I/O statistics.\n\n");
Global registry for object inspection.
size_t getProtoBindings(size_t proto_index, const CObject **obj_list, size_t max_size) const
Get object bindings for PROTO object.
size_t getProtoCount() const
Get number of PROTO objects.
size_t getProgCount() const
Get number of PROG objects.
const CObject * getProg(size_t index) const
Get PROG object by index.
const CObject * findObject(uint32_t objid) const
Find object by ID.
const CIOCommon * getIO(size_t index) const
Get IO object by index.
size_t getProgIOBindings(size_t prog_index, const CIOCommon **io_list, size_t max_size) const
Get IO bindings for PROG object.
size_t getIOCount() const
Get number of IO objects.
const CObject * getProto(size_t index) const
Get PROTO object by index.
Base class for all I/O objects.
virtual size_t getDataDim() const =0
Get data vector dimension.
virtual size_t getDataSize() const =0
Get data size in bytes.
virtual bool isRead() const =0
Check if IO supports read operations.
Configuration I/O for runtime object management.
std::map< uint32_t, CObject * > map
Map of object ID to bound CObject pointers.
Base class for all Dawn objects (IOs, Programs, Protocols).
uint8_t getType() const
Get object type field.
uint16_t getPriv() const
Get instance/private data field.
uint16_t getCls() const
Get object class field.
uint8_t getFlags() const
Get type-specific flags field.
virtual EObjectState getState() const
Get current operational state.
SObjectId::ObjectId getIdV() const
Get object identifier as raw 32-bit value.
size_t getDtypeSize() const
Get size of this object's data type.
uint8_t getDtype() const
Get data type field.
bool getCfgFlag() const
Check if configuration flag is set.
Out-of-tree user-extension hooks for Dawn.