static void print_ndtstats(const struct ndt_stats *ndts) { print_string(PRINT_FP, NULL, " stats ", NULL); print_u64(PRINT_ANY, "allocs", "allocs %llu ", ndts->ndts_allocs); print_u64(PRINT_ANY, "destroys", "destroys %llu ", ndts->ndts_destroys); print_u64(PRINT_ANY, "hash_grows", "hash_grows %llu ", ndts->ndts_hash_grows); print_string(PRINT_FP, NULL, "%s ", _SL_); print_u64(PRINT_ANY, "res_failed", "res_failed %llu ", ndts->ndts_res_failed); print_u64(PRINT_ANY, "lookups", "lookups %llu ", ndts->ndts_lookups); print_u64(PRINT_ANY, "hits", "hits %llu ", ndts->ndts_hits); print_string(PRINT_FP, NULL, "%s ", _SL_); print_u64(PRINT_ANY, "rcv_probes_mcast", "rcv_probes_mcast %llu ", ndts->ndts_rcv_probes_mcast); print_u64(PRINT_ANY, "rcv_probes_ucast", "rcv_probes_ucast %llu ", ndts->ndts_rcv_probes_ucast); print_string(PRINT_FP, NULL, "%s ", _SL_); print_u64(PRINT_ANY, "periodic_gc_runs", "periodic_gc_runs %llu ", ndts->ndts_periodic_gc_runs); print_u64(PRINT_ANY, "forced_gc_runs", "forced_gc_runs %llu ", ndts->ndts_forced_gc_runs); print_nl(); }
static void print_i64(char* Result, int64_t Value) { if (Value < -9223372036854775807) strcpy(Result, "-9223372036854775808"); else if (Value < 0) { Result[0] = '-'; print_u64(Result + 1, (uint64_t) -Value); } else print_u64(Result, (uint64_t) Value); }
void read_vector_test() { cbuf_t in; printf("read_vector_test1: BEGIN\n"); cbuf_initv(&in, &vec1); cbuf_print(&in, "vec1"); print_u8(&in, 10); print_u16(&in, 10); print_u32(&in, 10); print_u64(&in, 10); print_f32(&in, 10); print_f64(&in, 10); printf("read_vector_test1: END%s\n", !cbuf_eob(&in) ? " (data not consumed)" : ""); cbuf_print(&in, "vec1"); cbuf_final(&in); printf("read_vector_test2: BEGIN\n"); cbuf_initv(&in, &vec2); cbuf_print(&in, "vec2"); print_u32(&in, 5); print_u16(&in, 1); print_u8(&in, 1); printf("read_vector_test2: END%s\n", !cbuf_eob(&in) ? " (data not consumed)" : ""); cbuf_print(&in, "vec2"); cbuf_final(&in); }
static void DefaultDisplayValueFunction(struct MenuEntry* DrawnMenuEntry, struct MenuEntry* ActiveMenuEntry) { if (DrawnMenuEntry->Kind == KIND_OPTION || DrawnMenuEntry->Kind == KIND_DISPLAY) { char* Value; char Temp[21]; bool Error = false; if (DrawnMenuEntry->Kind == KIND_OPTION) { if (*(uint32_t*) DrawnMenuEntry->Target < DrawnMenuEntry->ChoiceCount) Value = DrawnMenuEntry->Choices[*(uint32_t*) DrawnMenuEntry->Target].Pretty; else { Value = "Out of bounds"; Error = true; } } else if (DrawnMenuEntry->Kind == KIND_DISPLAY) { switch (DrawnMenuEntry->DisplayType) { case TYPE_STRING: Value = (char*) DrawnMenuEntry->Target; break; case TYPE_INT32: sprintf(Temp, "%" PRIi32, *(int32_t*) DrawnMenuEntry->Target); Value = Temp; break; case TYPE_UINT32: sprintf(Temp, "%" PRIu32, *(uint32_t*) DrawnMenuEntry->Target); Value = Temp; break; case TYPE_INT64: print_i64(Temp, *(int64_t*) DrawnMenuEntry->Target); Value = Temp; break; case TYPE_UINT64: print_u64(Temp, *(uint64_t*) DrawnMenuEntry->Target); Value = Temp; break; default: Value = "Unknown type"; Error = true; break; } } uint32_t TextWidth = GetRenderedWidth(Value); if (TextWidth <= GCW0_SCREEN_WIDTH - 2) { bool IsActive = (DrawnMenuEntry == ActiveMenuEntry); uint16_t TextColor = Error ? COLOR_ERROR_TEXT : (IsActive ? COLOR_ACTIVE_TEXT : COLOR_INACTIVE_TEXT); uint16_t OutlineColor = Error ? COLOR_ERROR_OUTLINE : (IsActive ? COLOR_ACTIVE_OUTLINE : COLOR_INACTIVE_OUTLINE); print_string_outline(Value, TextColor, OutlineColor, GCW0_SCREEN_WIDTH - TextWidth - 1, GetRenderedHeight(" ") * (DrawnMenuEntry->Position + 2) + 1); } else ReGBA_Trace("W: Hid value '%s' from the menu due to it being too long", Value); } }
static void print_json_stats(const char *names[], unsigned int num, struct rtattr *stats[]) { unsigned int i; for (i = 1; i < num; i++) { if (!names[i] || !stats[i]) continue; print_u64(PRINT_JSON, names[i], NULL, getattr_u64(stats[i])); } }
void read_buffer_test() { cbuf_t in; printf("read_buffer_test vu8: BEGIN\n"); cbuf_init(&in, &vu8, sizeof(vu8), 0, 0); print_u8(&in, 10); printf("read_buffer_test vu8: END%s\n", !cbuf_eob(&in) ? " (data not consumed)" : ""); cbuf_final(&in); printf("read_buffer_test vu16: BEGIN\n"); cbuf_init(&in, &vu16, sizeof(vu16), 0, 0); print_u16(&in, 10); printf("read_buffer_test vu16: END%s\n", !cbuf_eob(&in) ? " (data not consumed)" : ""); cbuf_final(&in); printf("read_buffer_test vu32: BEGIN\n"); cbuf_init(&in, &vu32, sizeof(vu32), 0, 0); print_u32(&in, 10); printf("read_buffer_test vu32: END%s\n", !cbuf_eob(&in) ? " (data not consumed)" : ""); cbuf_final(&in); printf("read_buffer_test vu64: BEGIN\n"); cbuf_init(&in, &vu64, sizeof(vu64), 0, 0); print_u64(&in, 10); printf("read_buffer_test vu64: END%s\n", !cbuf_eob(&in) ? " (data not consumed)" : ""); cbuf_final(&in); printf("read_buffer_test vf32: BEGIN\n"); cbuf_init(&in, &vf32, sizeof(vf32), 0, 0); print_f32(&in, 10); printf("read_buffer_test vu32: END%s\n", !cbuf_eob(&in) ? " (data not consumed)" : ""); cbuf_final(&in); printf("read_buffer_test vf64: BEGIN\n"); cbuf_init(&in, &vf64, sizeof(vf64), 0, 0); print_f64(&in, 10); printf("read_buffer_test vf64: END%s\n", !cbuf_eob(&in) ? " (data not consumed)" : ""); cbuf_final(&in); }
static void print_dev_vcpu(struct virt_device *dev, FILE *d) { print_u64(d, "Virtual CPU", dev->dev.vcpu.quantity); }
static void print_dev_mem(struct virt_device *dev, FILE *d) { print_u64(d, "Memory", dev->dev.mem.size); print_u64(d, "Maximum", dev->dev.mem.maxsize); }
static int print_ntable(struct nlmsghdr *n, void *arg) { FILE *fp = (FILE *)arg; struct ndtmsg *ndtm = NLMSG_DATA(n); int len = n->nlmsg_len; struct rtattr *tb[NDTA_MAX+1]; struct rtattr *tpb[NDTPA_MAX+1]; int ret; if (n->nlmsg_type != RTM_NEWNEIGHTBL) { fprintf(stderr, "Not NEIGHTBL: %08x %08x %08x\n", n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); return 0; } len -= NLMSG_LENGTH(sizeof(*ndtm)); if (len < 0) { fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); return -1; } if (preferred_family && preferred_family != ndtm->ndtm_family) return 0; parse_rtattr(tb, NDTA_MAX, NDTA_RTA(ndtm), n->nlmsg_len - NLMSG_LENGTH(sizeof(*ndtm))); if (tb[NDTA_NAME]) { const char *name = rta_getattr_str(tb[NDTA_NAME]); if (filter.name && strcmp(filter.name, name)) return 0; } if (tb[NDTA_PARMS]) { parse_rtattr(tpb, NDTPA_MAX, RTA_DATA(tb[NDTA_PARMS]), RTA_PAYLOAD(tb[NDTA_PARMS])); if (tpb[NDTPA_IFINDEX]) { __u32 ifindex = rta_getattr_u32(tpb[NDTPA_IFINDEX]); if (filter.index && filter.index != ifindex) return 0; } else { if (filter.index && filter.index != NONE_DEV) return 0; } } open_json_object(NULL); print_string(PRINT_ANY, "family", "%s ", family_name(ndtm->ndtm_family)); if (tb[NDTA_NAME]) { const char *name = rta_getattr_str(tb[NDTA_NAME]); print_string(PRINT_ANY, "name", "%s ", name); } print_nl(); ret = (tb[NDTA_THRESH1] || tb[NDTA_THRESH2] || tb[NDTA_THRESH3] || tb[NDTA_GC_INTERVAL]); if (ret) print_string(PRINT_FP, NULL, " ", NULL); if (tb[NDTA_THRESH1]) { __u32 thresh1 = rta_getattr_u32(tb[NDTA_THRESH1]); print_uint(PRINT_ANY, "thresh1", "thresh1 %u ", thresh1); } if (tb[NDTA_THRESH2]) { __u32 thresh2 = rta_getattr_u32(tb[NDTA_THRESH2]); print_uint(PRINT_ANY, "thresh2", "thresh2 %u ", thresh2); } if (tb[NDTA_THRESH3]) { __u32 thresh3 = rta_getattr_u32(tb[NDTA_THRESH3]); print_uint(PRINT_ANY, "thresh3", "thresh3 %u ", thresh3); } if (tb[NDTA_GC_INTERVAL]) { __u64 gc_int = rta_getattr_u64(tb[NDTA_GC_INTERVAL]); print_u64(PRINT_ANY, "gc_interval", "gc_int %llu ", gc_int); } if (ret) print_nl(); if (tb[NDTA_CONFIG] && show_stats) print_ndtconfig(RTA_DATA(tb[NDTA_CONFIG])); if (tb[NDTA_PARMS]) print_ndtparams(tpb); if (tb[NDTA_STATS] && show_stats) print_ndtstats(RTA_DATA(tb[NDTA_STATS])); print_string(PRINT_FP, NULL, "\n", ""); close_json_object(); fflush(fp); return 0; }
static void print_ndtparams(struct rtattr *tpb[]) { if (tpb[NDTPA_IFINDEX]) { __u32 ifindex = rta_getattr_u32(tpb[NDTPA_IFINDEX]); print_string(PRINT_FP, NULL, " dev ", NULL); print_color_string(PRINT_ANY, COLOR_IFNAME, "dev", "%s ", ll_index_to_name(ifindex)); print_nl(); } print_string(PRINT_FP, NULL, " ", NULL); if (tpb[NDTPA_REFCNT]) { __u32 refcnt = rta_getattr_u32(tpb[NDTPA_REFCNT]); print_uint(PRINT_ANY, "refcnt", "refcnt %u ", refcnt); } if (tpb[NDTPA_REACHABLE_TIME]) { __u64 reachable = rta_getattr_u64(tpb[NDTPA_REACHABLE_TIME]); print_u64(PRINT_ANY, "reachable", "reachable %llu ", reachable); } if (tpb[NDTPA_BASE_REACHABLE_TIME]) { __u64 breachable = rta_getattr_u64(tpb[NDTPA_BASE_REACHABLE_TIME]); print_u64(PRINT_ANY, "base_reachable", "base_reachable %llu ", breachable); } if (tpb[NDTPA_RETRANS_TIME]) { __u64 retrans = rta_getattr_u64(tpb[NDTPA_RETRANS_TIME]); print_u64(PRINT_ANY, "retrans", "retrans %llu ", retrans); } print_string(PRINT_FP, NULL, "%s ", _SL_); if (tpb[NDTPA_GC_STALETIME]) { __u64 gc_stale = rta_getattr_u64(tpb[NDTPA_GC_STALETIME]); print_u64(PRINT_ANY, "gc_stale", "gc_stale %llu ", gc_stale); } if (tpb[NDTPA_DELAY_PROBE_TIME]) { __u64 delay_probe = rta_getattr_u64(tpb[NDTPA_DELAY_PROBE_TIME]); print_u64(PRINT_ANY, "delay_probe", "delay_probe %llu ", delay_probe); } if (tpb[NDTPA_QUEUE_LEN]) { __u32 queue = rta_getattr_u32(tpb[NDTPA_QUEUE_LEN]); print_uint(PRINT_ANY, "queue", "queue %u ", queue); } print_string(PRINT_FP, NULL, "%s ", _SL_); if (tpb[NDTPA_APP_PROBES]) { __u32 aprobe = rta_getattr_u32(tpb[NDTPA_APP_PROBES]); print_uint(PRINT_ANY, "app_probes", "app_probes %u ", aprobe); } if (tpb[NDTPA_UCAST_PROBES]) { __u32 uprobe = rta_getattr_u32(tpb[NDTPA_UCAST_PROBES]); print_uint(PRINT_ANY, "ucast_probes", "ucast_probes %u ", uprobe); } if (tpb[NDTPA_MCAST_PROBES]) { __u32 mprobe = rta_getattr_u32(tpb[NDTPA_MCAST_PROBES]); print_uint(PRINT_ANY, "mcast_probes", "mcast_probes %u ", mprobe); } print_string(PRINT_FP, NULL, "%s ", _SL_); if (tpb[NDTPA_ANYCAST_DELAY]) { __u64 anycast_delay = rta_getattr_u64(tpb[NDTPA_ANYCAST_DELAY]); print_u64(PRINT_ANY, "anycast_delay", "anycast_delay %llu ", anycast_delay); } if (tpb[NDTPA_PROXY_DELAY]) { __u64 proxy_delay = rta_getattr_u64(tpb[NDTPA_PROXY_DELAY]); print_u64(PRINT_ANY, "proxy_delay", "proxy_delay %llu ", proxy_delay); } if (tpb[NDTPA_PROXY_QLEN]) { __u32 pqueue = rta_getattr_u32(tpb[NDTPA_PROXY_QLEN]); print_uint(PRINT_ANY, "proxy_queue", "proxy_queue %u ", pqueue); } if (tpb[NDTPA_LOCKTIME]) { __u64 locktime = rta_getattr_u64(tpb[NDTPA_LOCKTIME]); print_u64(PRINT_ANY, "locktime", "locktime %llu ", locktime); } print_nl(); }