Instead of converting each byte one-at-a-time and then sending each byte
over the wire, use sprintf() to pre-compute all of the hex nibs into a
single buffer, then send the entire buffer all at once.
This gives a moderate speed boost to memread() and memwrite() functions.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-id:
1431021095-7558-2-git-send-email-jsnow@redhat.com
} else if (strcmp(words[0], "read") == 0) {
uint64_t addr, len, i;
uint8_t *data;
} else if (strcmp(words[0], "read") == 0) {
uint64_t addr, len, i;
uint8_t *data;
g_assert(words[1] && words[2]);
addr = strtoull(words[1], NULL, 0);
g_assert(words[1] && words[2]);
addr = strtoull(words[1], NULL, 0);
data = g_malloc(len);
cpu_physical_memory_read(addr, data, len);
data = g_malloc(len);
cpu_physical_memory_read(addr, data, len);
- qtest_send_prefix(chr);
- qtest_send(chr, "OK 0x");
+ enc = g_malloc(2 * len + 1);
for (i = 0; i < len; i++) {
for (i = 0; i < len; i++) {
- qtest_sendf(chr, "%02x", data[i]);
+ sprintf(&enc[i * 2], "%02x", data[i]);
+
+ qtest_send_prefix(chr);
+ qtest_sendf(chr, "OK 0x%s\n", enc);
} else if (strcmp(words[0], "b64read") == 0) {
uint64_t addr, len;
uint8_t *data;
} else if (strcmp(words[0], "b64read") == 0) {
uint64_t addr, len;
uint8_t *data;
{
const uint8_t *ptr = data;
size_t i;
{
const uint8_t *ptr = data;
size_t i;
+ char *enc = g_malloc(2 * size + 1);
- qtest_sendf(s, "write 0x%" PRIx64 " 0x%zx 0x", addr, size);
for (i = 0; i < size; i++) {
for (i = 0; i < size; i++) {
- qtest_sendf(s, "%02x", ptr[i]);
+ sprintf(&enc[i * 2], "%02x", ptr[i]);
+
+ qtest_sendf(s, "write 0x%" PRIx64 " 0x%zx 0x%s\n", addr, size, enc);
}
void qtest_memset(QTestState *s, uint64_t addr, uint8_t pattern, size_t size)
}
void qtest_memset(QTestState *s, uint64_t addr, uint8_t pattern, size_t size)