Update reporter files
This commit is contained in:
Родитель
6b30f92ce9
Коммит
77a2e93ad7
|
@ -22,23 +22,30 @@
|
|||
static const char* BINARY_UL_PATH_FMT = "%s/binary_info/upper_layer/%s%s_%s/%s%s_%s%s";
|
||||
#endif
|
||||
|
||||
static const char* const MQTT_BINARY_NAME = "mqtt_transport";
|
||||
static const char* const MQTT_WS_BINARY_NAME = "mqtt_ws_transport";
|
||||
static const char* const AMQP_BINARY_NAME = "amqp_transport";
|
||||
static const char* const AMQP_WS_BINARY_NAME = "amqp_ws_transport";
|
||||
static const char* const HTTP_BINARY_NAME = "http_transport";
|
||||
static const char* const REPORT_TYPE_JSON = "json";
|
||||
static const char* const REPORT_TYPE_CVS = "csv";
|
||||
static const char* const REPORT_TYPE_MD = "md";
|
||||
|
||||
static const char* const MQTT_BINARY_NAME = "mqtt_transport";
|
||||
static const char* const MQTT_WS_BINARY_NAME = "mqtt_ws_transport";
|
||||
static const char* const AMQP_BINARY_NAME = "amqp_transport";
|
||||
static const char* const AMQP_WS_BINARY_NAME = "amqp_ws_transport";
|
||||
static const char* const HTTP_BINARY_NAME = "http_transport";
|
||||
|
||||
static const char* const PROV_BINARY_NAME = "prov_";
|
||||
|
||||
static const char* UPPER_LAYER_SUFFIX = "ul";
|
||||
static const char* LOWER_LAYER_SUFFIX = "ll";
|
||||
|
||||
#define TOLOWER(c) (((c>='A') && (c<='Z'))?c-'A'+'a':c)
|
||||
|
||||
typedef enum ARGUEMENT_TYPE_TAG
|
||||
{
|
||||
ARGUEMENT_TYPE_UNKNOWN,
|
||||
ARGUEMENT_TYPE_CMAKE_DIR,
|
||||
ARGUEMENT_TYPE_OUTPUT_FILE,
|
||||
ARGUEMENT_TYPE_SKIP_UPPER_LAYER
|
||||
ARGUEMENT_TYPE_SKIP_UPPER_LAYER,
|
||||
ARGUEMENT_TYPE_OUTPUT_TYPE
|
||||
} ARGUEMENT_TYPE;
|
||||
|
||||
static const char* get_binary_file(PROTOCOL_TYPE type)
|
||||
|
@ -147,6 +154,7 @@ static int calculate_filesize(BINARY_INFO* bin_info, REPORT_HANDLE report_handle
|
|||
return result;
|
||||
}
|
||||
|
||||
// -c "<CMAKE DIRECTORY>" -t <report type - json, csv> -l
|
||||
static int parse_command_line(int argc, char* argv[], BINARY_INFO* bin_info)
|
||||
{
|
||||
int result = 0;
|
||||
|
@ -156,7 +164,26 @@ static int parse_command_line(int argc, char* argv[], BINARY_INFO* bin_info)
|
|||
{
|
||||
if (argument_type == ARGUEMENT_TYPE_UNKNOWN)
|
||||
{
|
||||
if (argv[index][0] == '-' && (argv[index][1] == 'c' || argv[index][1] == 'C'))
|
||||
if (argv[index][0] == '-')
|
||||
{
|
||||
switch (TOLOWER(argv[index][1]))
|
||||
{
|
||||
case 'c':
|
||||
argument_type = ARGUEMENT_TYPE_CMAKE_DIR;
|
||||
break;
|
||||
case 'o':
|
||||
argument_type = ARGUEMENT_TYPE_OUTPUT_FILE;
|
||||
break;
|
||||
case 'l':
|
||||
bin_info->skip_ul = argv[index];
|
||||
argument_type = ARGUEMENT_TYPE_UNKNOWN;
|
||||
break;
|
||||
case 't':
|
||||
argument_type = ARGUEMENT_TYPE_OUTPUT_TYPE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*if (argv[index][0] == '-' && (argv[index][1] == 'c' || argv[index][1] == 'C'))
|
||||
{
|
||||
argument_type = ARGUEMENT_TYPE_CMAKE_DIR;
|
||||
}
|
||||
|
@ -168,7 +195,7 @@ static int parse_command_line(int argc, char* argv[], BINARY_INFO* bin_info)
|
|||
{
|
||||
bin_info->skip_ul = argv[index];
|
||||
argument_type = ARGUEMENT_TYPE_UNKNOWN;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -180,6 +207,25 @@ static int parse_command_line(int argc, char* argv[], BINARY_INFO* bin_info)
|
|||
case ARGUEMENT_TYPE_OUTPUT_FILE:
|
||||
bin_info->output_file = argv[index];
|
||||
break;
|
||||
case ARGUEMENT_TYPE_OUTPUT_TYPE:
|
||||
if (strcmp(argv[index], REPORT_TYPE_JSON) == 0)
|
||||
{
|
||||
bin_info->rpt_type = REPORTER_TYPE_JSON;
|
||||
}
|
||||
else if (strcmp(argv[index], REPORT_TYPE_CVS) == 0)
|
||||
{
|
||||
bin_info->rpt_type = REPORTER_TYPE_CSV;
|
||||
}
|
||||
/*else if (strcmp(argv[index], REPORT_TYPE_MD) == 0)
|
||||
{
|
||||
bin_info->rpt_type = REPORTER_TYPE_MD;
|
||||
}*/
|
||||
else
|
||||
{
|
||||
// Not supported
|
||||
result = __LINE__;
|
||||
}
|
||||
break;
|
||||
case ARGUEMENT_TYPE_UNKNOWN:
|
||||
default:
|
||||
result = __LINE__;
|
||||
|
@ -208,7 +254,7 @@ int main(int argc, char* argv[])
|
|||
(void)printf("Failure cmake directory command line option not supplied\r\n");
|
||||
result = __LINE__;
|
||||
}
|
||||
else if ((report_handle = report_initialize(REPORTER_TYPE_JSON)) == NULL)
|
||||
else if ((report_handle = report_initialize(bin_info.rpt_type)) == NULL)
|
||||
{
|
||||
(void)printf("Failure creating report handle\r\n");
|
||||
result = __LINE__;
|
||||
|
@ -258,7 +304,7 @@ int main(int argc, char* argv[])
|
|||
(void)calculate_filesize(&bin_info, report_handle, PROTOCOL_AMQP, BINARY_UL_PATH_FMT);
|
||||
(void)calculate_filesize(&bin_info, report_handle, PROTOCOL_AMQP_WS, BINARY_UL_PATH_FMT);
|
||||
#endif
|
||||
report_write(report_handle);
|
||||
report_write(report_handle, bin_info.output_file);
|
||||
|
||||
report_deinitialize(report_handle);
|
||||
result = 0;
|
||||
|
|
127
mem_reporter.c
127
mem_reporter.c
|
@ -38,9 +38,9 @@ static const char* const BINARY_SIZE_JSON_FMT = "{ \"type\": \"ROM\", \"dateTime
|
|||
static const char* const HEAP_ANALYSIS_JSON_FMT = "{ \"type\": \"RAM\", \"dateTime\": \"%s\", \"feature\": \"%s\", \"layer\": \"%s\", \"version\": \"%s\", \"transport\" : \"%s\", \"msgCount\" : %d, \"maxMemory\" : \"%s\", \"currMemory\" : \"%s\", \"numAlloc\" : \"%s\" } }";
|
||||
static const char* const NETWORK_ANALYSIS_JSON_FMT = "{ \"type\": \"NETWORK\", \"dateTime\": \"%s\", \"feature\": \"%s\", \"version\": \"%s\", \"transport\" : \"%s\", \"msgPayload\" : %d, \"bytesSent\" : \"%s\", \"numSends\" : \"%s\", \"recvBytes\" : \"%s\", \"numRecv\" : \"%s\" } }";
|
||||
|
||||
static const char* const BINARY_SIZE_CVS_FMT = "%s, %s, %s, %s, %s, %s, %s, %ld";
|
||||
static const char* const HEAP_ANALYSIS_CVS_FMT = "%s, %s, %s, %s, %s, %s, %s, %d, %zu, %zu, %zu";
|
||||
static const char* const NETWORK_ANALYSIS_CVS_FMT = "%s, %s, %s, %s, %s, %s, %d, %" PRIu64 ", %ld, %" PRIu64 ", %ld";
|
||||
static const char* const BINARY_SIZE_CSV_FMT = "%s, %s, %s, %s, %s, %s";
|
||||
static const char* const HEAP_ANALYSIS_CSV_FMT = "%s, %s, %s, %s, %s, %s, %s, %d, %zu, %zu, %zu";
|
||||
static const char* const NETWORK_ANALYSIS_CSV_FMT = "%s, %s, %s, %s, %s, %s, %d, %" PRIu64 ", %ld, %" PRIu64 ", %ld";
|
||||
|
||||
#ifdef NO_LOGGING
|
||||
static const char* const LOGGING_INCLUDED = "false";
|
||||
|
@ -53,11 +53,25 @@ static const char* const UPLOAD_INCLUDED = "false";
|
|||
static const char* const UPLOAD_INCLUDED = "true";
|
||||
#endif
|
||||
|
||||
typedef struct JSON_REPORT_INFO_TAG
|
||||
{
|
||||
JSON_Value* root_value;
|
||||
JSON_Object* analysis_node;
|
||||
} JSON_REPORT_INFO;
|
||||
|
||||
typedef struct CSV_REPORT_INFO_TAG
|
||||
{
|
||||
STRING_HANDLE csv_list;
|
||||
} CSV_REPORT_INFO;
|
||||
|
||||
typedef struct REPORT_INFO_TAG
|
||||
{
|
||||
REPORTER_TYPE type;
|
||||
JSON_Value* root_value;
|
||||
JSON_Object* analysis_node;
|
||||
union
|
||||
{
|
||||
JSON_REPORT_INFO json_info;
|
||||
CSV_REPORT_INFO csv_info;
|
||||
} rpt_value;
|
||||
} REPORT_INFO;
|
||||
|
||||
static void format_value(uint64_t value, char formatting[FORMAT_MAX_LEN])
|
||||
|
@ -112,6 +126,15 @@ static void format_bytes(long bytes, char formatting[FORMAT_MAX_LEN])
|
|||
}
|
||||
}
|
||||
|
||||
static void add_node_to_csv(const char* field_data, const REPORT_INFO* report_info)
|
||||
{
|
||||
if (STRING_sprintf(report_info->rpt_value.csv_info.csv_list, "%s\r\n", field_data) != 0)
|
||||
//if (STRING_concat(report_info->rpt_value.csv_info.csv_list, field_data) != 0)
|
||||
{
|
||||
(void)printf("ERROR: Failed setting field value\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void add_node_to_json(const char* node_data, const REPORT_INFO* report_info)
|
||||
{
|
||||
JSON_Value* json_value;
|
||||
|
@ -121,7 +144,7 @@ static void add_node_to_json(const char* node_data, const REPORT_INFO* report_in
|
|||
JSON_Array* base_array;
|
||||
JSON_Value* json_analysis;
|
||||
|
||||
if ((json_analysis = json_object_get_value(report_info->analysis_node, NODE_SDK_ANALYSIS)) == NULL)
|
||||
if ((json_analysis = json_object_get_value(report_info->rpt_value.json_info.analysis_node, NODE_SDK_ANALYSIS)) == NULL)
|
||||
{
|
||||
(void)printf("ERROR: Failed getting node object value\r\n");
|
||||
}
|
||||
|
@ -150,6 +173,33 @@ static void upload_to_azure(const char* data)
|
|||
// TODO upload to azure iot
|
||||
}
|
||||
|
||||
static int write_to_storage(const char* report_data, const char* output_file, REPORTER_TYPE type)
|
||||
{
|
||||
int result;
|
||||
if (output_file == NULL)
|
||||
{
|
||||
(void)printf("%s\r\n", report_data);
|
||||
result = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* filemode = "a";
|
||||
if (type == REPORTER_TYPE_JSON)
|
||||
{
|
||||
filemode = "w";
|
||||
}
|
||||
FILE* file = fopen(output_file, filemode);
|
||||
if (file != NULL)
|
||||
{
|
||||
size_t len = strlen(report_data);
|
||||
fwrite(report_data, sizeof(char), len, file);
|
||||
fclose(file);
|
||||
}
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void get_report_date(char* date, size_t length)
|
||||
{
|
||||
time_t curr_time = get_time(NULL);
|
||||
|
@ -273,9 +323,9 @@ static const char* get_format_value(const REPORT_INFO* report_info, OPERATION_TY
|
|||
switch (type)
|
||||
{
|
||||
case OPERATION_MEMORY:
|
||||
if (report_info->type == REPORTER_TYPE_CVS)
|
||||
if (report_info->type == REPORTER_TYPE_CSV)
|
||||
{
|
||||
result = HEAP_ANALYSIS_CVS_FMT;
|
||||
result = HEAP_ANALYSIS_CSV_FMT;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -283,9 +333,9 @@ static const char* get_format_value(const REPORT_INFO* report_info, OPERATION_TY
|
|||
}
|
||||
break;
|
||||
case OPERATION_NETWORK:
|
||||
if (report_info->type == REPORTER_TYPE_CVS)
|
||||
if (report_info->type == REPORTER_TYPE_CSV)
|
||||
{
|
||||
result = NETWORK_ANALYSIS_CVS_FMT;
|
||||
result = NETWORK_ANALYSIS_CSV_FMT;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -293,9 +343,9 @@ static const char* get_format_value(const REPORT_INFO* report_info, OPERATION_TY
|
|||
}
|
||||
break;
|
||||
case OPERATION_BINARY_SIZE:
|
||||
if (report_info->type == REPORTER_TYPE_CVS)
|
||||
if (report_info->type == REPORTER_TYPE_CSV)
|
||||
{
|
||||
result = BINARY_SIZE_CVS_FMT;
|
||||
result = BINARY_SIZE_CSV_FMT;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -332,14 +382,14 @@ REPORT_HANDLE report_initialize(REPORTER_TYPE type)
|
|||
}
|
||||
else
|
||||
{
|
||||
result->root_value = json_parse_string(STRING_c_str(json_node));
|
||||
if (result->root_value == NULL)
|
||||
result->rpt_value.json_info.root_value = json_parse_string(STRING_c_str(json_node));
|
||||
if (result->rpt_value.json_info.root_value == NULL)
|
||||
{
|
||||
(void)printf("Failure parsing value node\r\n");
|
||||
free(result);
|
||||
result = NULL;
|
||||
}
|
||||
else if ((result->analysis_node = json_value_get_object(result->root_value)) == NULL)
|
||||
else if ((result->rpt_value.json_info.analysis_node = json_value_get_object(result->rpt_value.json_info.root_value)) == NULL)
|
||||
{
|
||||
(void)printf("Failure getting value node\r\n");
|
||||
free(result);
|
||||
|
@ -347,14 +397,26 @@ REPORT_HANDLE report_initialize(REPORTER_TYPE type)
|
|||
}
|
||||
/*else
|
||||
{
|
||||
char* test = json_serialize_to_string_pretty(result->root_value);
|
||||
char* test = json_serialize_to_string_pretty(result->json_info.root_value);
|
||||
(void)printf("Debug:\r\n%s\r\n", test);
|
||||
}*/
|
||||
}
|
||||
STRING_delete(json_node);
|
||||
}
|
||||
else if (result->type == REPORTER_TYPE_CSV)
|
||||
{
|
||||
if ((result->rpt_value.csv_info.csv_list = STRING_new()) == NULL)
|
||||
{
|
||||
(void)printf("Failure creating string value for csv\r\n");
|
||||
free(result);
|
||||
result = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)printf("Failure report mode not supported\r\n");
|
||||
free(result);
|
||||
result = NULL;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -365,7 +427,14 @@ void report_deinitialize(REPORT_HANDLE handle)
|
|||
// Close the file
|
||||
if (handle != NULL)
|
||||
{
|
||||
json_value_free(handle->root_value);
|
||||
if (handle->type == REPORTER_TYPE_JSON)
|
||||
{
|
||||
json_value_free(handle->rpt_value.json_info.root_value);
|
||||
}
|
||||
else if (handle->type == REPORTER_TYPE_CSV)
|
||||
{
|
||||
STRING_delete(handle->rpt_value.csv_info.csv_list);
|
||||
}
|
||||
free(handle);
|
||||
}
|
||||
}
|
||||
|
@ -388,7 +457,14 @@ void report_binary_sizes(REPORT_HANDLE handle, const BINARY_INFO* bin_info)
|
|||
}
|
||||
else
|
||||
{
|
||||
add_node_to_json(STRING_c_str(binary_data), handle);
|
||||
if (bin_info->rpt_type == REPORTER_TYPE_CSV)
|
||||
{
|
||||
add_node_to_csv(STRING_c_str(binary_data), handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
add_node_to_json(STRING_c_str(binary_data), handle);
|
||||
}
|
||||
STRING_delete(binary_data);
|
||||
}
|
||||
}
|
||||
|
@ -452,7 +528,7 @@ void report_network_usage(REPORT_HANDLE handle, const MEM_ANALYSIS_INFO* iot_mem
|
|||
}
|
||||
}
|
||||
|
||||
bool report_write(REPORT_HANDLE handle)
|
||||
bool report_write(REPORT_HANDLE handle, const char* output_file)
|
||||
{
|
||||
bool result;
|
||||
if (handle == NULL)
|
||||
|
@ -461,9 +537,16 @@ bool report_write(REPORT_HANDLE handle)
|
|||
}
|
||||
else
|
||||
{
|
||||
char* test = json_serialize_to_string_pretty(handle->root_value);
|
||||
(void)printf("\r\n%s\r\n", test);
|
||||
json_free_serialized_string(test);
|
||||
if (handle->type == REPORTER_TYPE_JSON)
|
||||
{
|
||||
char* report_data = json_serialize_to_string_pretty(handle->rpt_value.json_info.root_value);
|
||||
write_to_storage(report_data, output_file, handle->type);
|
||||
json_free_serialized_string(report_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
write_to_storage(STRING_c_str(handle->rpt_value.csv_info.csv_list), output_file, handle->type);
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -60,8 +60,8 @@ typedef struct REPORT_INFO_TAG* REPORT_HANDLE;
|
|||
typedef enum REPORTER_TYPE_TAG
|
||||
{
|
||||
REPORTER_TYPE_JSON,
|
||||
REPORTER_TYPE_CVS,
|
||||
REPORTER_TYPE_MD,
|
||||
REPORTER_TYPE_CSV,
|
||||
REPORTER_TYPE_MD
|
||||
} REPORTER_TYPE;
|
||||
|
||||
typedef struct CONNECTION_INFO_TAG
|
||||
|
@ -85,6 +85,7 @@ typedef struct REPORT_INFO_TAG* REPORT_HANDLE;
|
|||
PROTOCOL_TYPE iothub_protocol;
|
||||
OPERATION_TYPE operation_type;
|
||||
FEATURE_TYPE feature_type;
|
||||
REPORTER_TYPE rpt_type;
|
||||
const char* cmake_dir;
|
||||
long binary_size;
|
||||
const char* output_file;
|
||||
|
@ -98,7 +99,7 @@ typedef struct REPORT_INFO_TAG* REPORT_HANDLE;
|
|||
extern void report_binary_sizes(REPORT_HANDLE handle, const BINARY_INFO* bin_info);
|
||||
extern void report_network_usage(REPORT_HANDLE handle, const MEM_ANALYSIS_INFO* iot_mem_info);
|
||||
|
||||
extern bool report_write(REPORT_HANDLE handle);
|
||||
extern bool report_write(REPORT_HANDLE handle, const char* output_file);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -360,7 +360,7 @@ int main(int argc, char* argv[])
|
|||
platform_deinit();
|
||||
gbnetwork_deinit();
|
||||
|
||||
report_write(report_handle);
|
||||
report_write(report_handle, NULL);
|
||||
|
||||
report_deinitialize(report_handle);
|
||||
|
||||
|
|
|
@ -334,7 +334,7 @@ int main(int argc, char* argv[])
|
|||
platform_deinit();
|
||||
gbnetwork_deinit();
|
||||
|
||||
report_write(report_handle);
|
||||
report_write(report_handle, NULL);
|
||||
|
||||
report_deinitialize(report_handle);
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
name: $(BuildID)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
|
||||
resources:
|
||||
- repo: self
|
||||
clean: true
|
||||
phases:
|
||||
- phase: linux
|
||||
variables:
|
||||
_PREVIEW_VSTS_DOCKER_IMAGE: "aziotbld/linux-c-ubuntu-16.04:latest"
|
||||
queue: aziotbld-lin01
|
||||
displayName: 'dynamic'
|
||||
steps:
|
||||
- script: 'sudo ./script/execute_analysis.sh'
|
||||
- task: DeleteFiles@1
|
||||
displayName: 'Delete files from $(Agent.BuildDirectory)'
|
||||
inputs:
|
||||
SourceFolder: '$(Agent.BuildDirectory)'
|
||||
condition: always()
|
Загрузка…
Ссылка в новой задаче