return msg;
}
+static size_t str_array_getsize(const char **strings, size_t len)
+{
+ /*!
+ * Calculate about of memory to place array
+ * of \0 delimited strings
+ */
+ size_t size = 0;
+ unsigned int index;
+ for (index = 0; index != len; ++index)
+ size += strlen(strings[index]) + 1;
+ return size;
+}
+
+
static struct msg_t *gen_target_info_reply(struct target_info_t *target_info)
{
struct msg_t *msg;
uint32_t ret_id = ERR_NO;
msg = malloc(sizeof(*msg) +
- sizeof(ret_id) +
- sizeof(*target_info) -
- sizeof(target_info->network_type) +
- strlen(target_info->network_type) + 1);
+ sizeof(ret_id) +
+ sizeof(*target_info) -
+ sizeof(target_info->network_type) +
+ strlen(target_info->network_type) + 1 +
+ sizeof(uint32_t) + /* devices count */
+ str_array_getsize(supported_devices_strings,
+ supported_devices_count));
if (!msg) {
LOGE("Cannot alloc target info msg\n");
free(msg);
pack_str(p, target_info->network_type);
pack_int(p, target_info->max_brightness);
pack_int(p, target_info->cpu_core_count);
+ pack_int32(p, supported_devices_count);
+ p = pack_str_array(p, supported_devices_strings,
+ supported_devices_count);
msg->len = p - msg->payload;
AT_LAUNCHED =0x02,
AT_COMMON =0x03
};
+enum supported_device {
+ DEVICE_FLASH,
+ DEVICE_CPU
+};
+static const char *supported_devices_strings[] = {
+ "FLASH",
+ "CPU"
+};
+#define array_size(x) (sizeof(x)/sizeof((x)[0]))
+enum { supported_devices_count = array_size(supported_devices_strings) };
#define MAX_FILENAME 128
uint32_t disk_sectors_write;
uint32_t network_send_size;
uint32_t network_receive_size;
+ uint32_t energy_per_device[supported_devices_count];
+ uint32_t app_energy_per_device[supported_devices_count];
};
struct recorded_event_t{
to += strlen(n) + 1; \
} while (0)
+static inline void* pack_str_array(void *buffer, const char **strings,
+ size_t count)
+{
+ int index;
+ for (index = 0; index != count; ++index)
+ pack_str(buffer, strings[index]);
+ return buffer;
+}
+
struct msg_data_t *pack_system_info(struct system_info_t *sys_info);
int write_to_buf(struct msg_data_t *msg);
void free_msg_data(struct msg_data_t *msg);
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
-
+#include <assert.h>
#include <inttypes.h>
#include <stdint.h>
return 100.0f / ((float)Hertz * elapsed * num_of_cpu);
}
+static uint32_t read_int_from_file(const char *fname)
+{
+ FILE *fp = fopen(fname, "r");
+ int value;
+ if (!fp)
+ return 0;
+ if (fscanf(fp, "%d", &value) != 1)
+ value = 0;
+ fclose(fp);
+ return value;
+}
+
+#define swap_sysfs_relpath(x) ("/sys/kernel/debug/swap/energy/" #x)
+#define swap_read_int(x) (read_int_from_file(swap_sysfs_relpath(x)))
+
+static uint32_t get_energy_per_device(enum supported_device dev)
+{
+ switch (dev) {
+ case DEVICE_CPU:
+ return swap_read_int(cpu_idle/system) +
+ swap_read_int(cpu_running/system);
+
+ case DEVICE_FLASH:
+ return swap_read_int(flash_read/system) +
+ swap_read_int(flash_write/system);
+ default:
+ assert(0 && "Unknown device. This should not happen");
+ return -41;
+ }
+}
+
+static uint32_t app_get_energy_per_device(enum supported_device dev)
+{
+ switch (dev) {
+ case DEVICE_CPU:
+ return swap_read_int(cpu_running/apps);
+ case DEVICE_FLASH:
+ return swap_read_int(flash_read/apps) +
+ swap_read_int(flash_write/apps);
+ default:
+ assert(0 && "Unknown device. This should not happen");
+ return -41;
+ }
+}
+
// return log length (>0) for normal case
// return negative value for error
int get_system_info(struct system_info_t *sys_info, int* pidarray, int pidcount)
}
#endif /* LOCALTEST */
// energy
- if (IS_OPT_SET(FL_ENERGY))
+ if (IS_OPT_SET(FL_ENERGY)) {
+ int i;
sys_info->energy = 0; // not implemented
+ for (i = 0; i != supported_devices_count; ++i) {
+ sys_info->energy_per_device[i] =
+ get_energy_per_device(i);
+ sys_info->app_energy_per_device[i] =
+ app_get_energy_per_device(i);
+ }
+ }
#ifdef THREAD_SAMPLING_DEBUG
print_sys_info(sys_info);
pack_int(p, sys_info->call_status);
pack_int(p, sys_info->dnet_status);
pack_int(p, sys_info->energy);
-
+ for (i = 0; i != supported_devices_count; ++i)
+ pack_int(p, sys_info->energy_per_device[i]);
+ for (i = 0; i != supported_devices_count; ++i)
+ pack_int(p, sys_info->app_energy_per_device[i]);
// pack_int(p, sys_info->total_used_drive);