some fixes for gstrace
This commit is contained in:
@ -59,7 +59,43 @@
|
||||
#define GS_TRC_FUNC_MASK_SZ (GS_TRC_FUNC_MAX / GS_TRC_NUM_BITS) // 8192
|
||||
|
||||
#define TRACE_COMMON_ERROR (-1)
|
||||
#define TRACE_OK (0)
|
||||
|
||||
typedef enum trace_msg_code {
|
||||
TRACE_OK,
|
||||
TRACE_ALREADY_START,
|
||||
TRACE_ALREADY_STOP,
|
||||
TRACE_PARAMETER_ERR,
|
||||
TRACE_BUFFER_SIZE_ERR,
|
||||
TRACE_ATTACH_CFG_SHARE_MEMORY_ERR,
|
||||
TRACE_ATTACH_BUFFER_SHARE_MEMORY_ERR,
|
||||
TRACE_OPEN_SHARE_MEMORY_ERR,
|
||||
TRACE_TRUNCATE_ERR,
|
||||
TRACE_MMAP_ERR,
|
||||
TRACE_UNLINK_SHARE_MEMORY_ERR,
|
||||
TRACE_DISABLE_ERR,
|
||||
TRACE_OPEN_OUTPUT_FILE_ERR,
|
||||
TRACE_OPEN_INPUT_FILE_ERR,
|
||||
TRACE_WRITE_BUFFER_HEADER_ERR,
|
||||
TRACE_WRITE_CFG_HEADER_ERR,
|
||||
TRACE_WRITE_BUFFER_ERR,
|
||||
TRACE_READ_CFG_FROM_FILE_ERR,
|
||||
TRACE_BUFFER_SIZE_FROM_FILE_ERR,
|
||||
TRACE_MAGIC_FROM_FILE_ERR,
|
||||
TRACE_READ_INFRA_FROM_FILE_ERR,
|
||||
TRACE_NO_RECORDS_ERR,
|
||||
TRACE_READ_SLOT_HEADER_ERR,
|
||||
TRACE_NUM_SLOT_ERR,
|
||||
TRACE_SLOT_MAGIC_ERR,
|
||||
TRACE_READ_SLOT_DATA_ERR,
|
||||
TRACE_WRITE_FORMATTED_RECORD_ERR,
|
||||
TRACE_MSG_MAX,
|
||||
} trace_msg_code;
|
||||
|
||||
typedef struct trace_msg {
|
||||
trace_msg_code msg_code;
|
||||
const char* msg_string;
|
||||
} trace_msg_t;
|
||||
|
||||
|
||||
#define securec_check(errno, charList, ...) \
|
||||
do { \
|
||||
@ -190,10 +226,10 @@ typedef struct trace_record {
|
||||
uint32_t user_data_len;
|
||||
} trace_record;
|
||||
|
||||
extern int gstrace_start(int pid, const char* mask, uint64_t bufferSize, const char* trcFile);
|
||||
extern int gstrace_stop(int pid);
|
||||
extern int gstrace_dump(int pid, const char* outPath);
|
||||
extern int gstrace_config(int pid);
|
||||
extern trace_msg_code gstrace_start(int pid, const char* mask, uint64_t bufferSize, const char* trcFile);
|
||||
extern trace_msg_code gstrace_stop(int pid);
|
||||
extern trace_msg_code gstrace_dump(int pid, const char* outPath);
|
||||
extern trace_msg_code gstrace_config(int pid);
|
||||
extern bool isNumeric(const char* str);
|
||||
|
||||
extern uint32_t getFunctionIdxByName(const char* funcName, uint32_t* comp);
|
||||
|
@ -449,7 +449,7 @@ int gstrace_init(int key)
|
||||
return TRACE_OK;
|
||||
}
|
||||
|
||||
static int createAndAttachTraceBuffer(int key, uint64_t bufferSize)
|
||||
static trace_msg_code createAndAttachTraceBuffer(int key, uint64_t bufferSize)
|
||||
{
|
||||
trace_context* pTrcCxt = getTraceContext();
|
||||
char sBufMemName[TRC_SHARED_MEM_NAME_MAX] = {0};
|
||||
@ -459,21 +459,21 @@ static int createAndAttachTraceBuffer(int key, uint64_t bufferSize)
|
||||
int fdTrc = shm_open(sBufMemName, O_RDWR | O_CREAT, S_IRWXU);
|
||||
if (fdTrc == -1) {
|
||||
// Failed to initialize trace shared memory buffer
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_OPEN_SHARE_MEMORY_ERR;
|
||||
}
|
||||
|
||||
ret = ftruncate(fdTrc, bufferSize + sizeof(trace_infra));
|
||||
if (ret == -1) {
|
||||
close(fdTrc);
|
||||
// Failed to set size of trace shared memory buffer
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_TRUNCATE_ERR;
|
||||
}
|
||||
|
||||
void* pTrcBufAddress = mmap(NULL, bufferSize + sizeof(trace_infra), PROT_READ | PROT_WRITE, MAP_SHARED, fdTrc, 0);
|
||||
close(fdTrc);
|
||||
if (pTrcBufAddress == MAP_FAILED) {
|
||||
// "failed to map memory for trace buffer
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_MMAP_ERR;
|
||||
}
|
||||
// Anchor our shared memory address in our global variable
|
||||
pTrcCxt->pTrcInfra = (trace_infra*)pTrcBufAddress;
|
||||
@ -493,26 +493,25 @@ static int createAndAttachTraceBuffer(int key, uint64_t bufferSize)
|
||||
* shared memory buffers, one for the trace
|
||||
* config and one for the trace infra.
|
||||
*/
|
||||
int gstrace_start(int key, const char* mask, uint64_t bufferSize, const char* trcFile)
|
||||
trace_msg_code gstrace_start(int key, const char* mask, uint64_t bufferSize, const char* trcFile)
|
||||
{
|
||||
int ret;
|
||||
trace_msg_code ret;
|
||||
bool bTrcToFile = (trcFile != NULL);
|
||||
trace_context* pTrcCxt = getTraceContext();
|
||||
|
||||
if (!bTrcToFile && bufferSize <= 0) {
|
||||
/* Buffer size of Shared memory should be greater than 0. */
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_BUFFER_SIZE_ERR;
|
||||
}
|
||||
bufferSize = bTrcToFile ? MIN_BUF_SIZE : roundToNearestPowerOfTwo(bufferSize);
|
||||
|
||||
if (attachTraceCfgSharedMem(key) != 0) {
|
||||
/* Failed to attached to shared memory. */
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_ATTACH_CFG_SHARE_MEMORY_ERR;
|
||||
}
|
||||
|
||||
if (pTrcCxt->pTrcCfg->bEnabled) {
|
||||
printf("Trace has already been activated.\n");
|
||||
return TRACE_OK;
|
||||
return TRACE_ALREADY_START;
|
||||
}
|
||||
|
||||
/* set the mask if it's passed in */
|
||||
@ -520,8 +519,8 @@ int gstrace_start(int key, const char* mask, uint64_t bufferSize, const char* tr
|
||||
trace_mask st_mask = {0};
|
||||
|
||||
parseMask(mask, &st_mask);
|
||||
ret = memcpy_s(&pTrcCxt->pTrcCfg->gs_trc_mask, sizeof(trace_mask), &st_mask, sizeof(trace_mask));
|
||||
securec_check(ret, "\0", "\0");
|
||||
errno_t rcs = memcpy_s(&pTrcCxt->pTrcCfg->gs_trc_mask, sizeof(trace_mask), &st_mask, sizeof(trace_mask));
|
||||
securec_check(rcs, "\0", "\0");
|
||||
pTrcCxt->pTrcCfg->options |= GS_TRC_CFG_MASK_OPTION;
|
||||
}
|
||||
|
||||
@ -531,8 +530,8 @@ int gstrace_start(int key, const char* mask, uint64_t bufferSize, const char* tr
|
||||
pTrcCxt->pTrcCfg->size = bufferSize;
|
||||
pTrcCxt->pTrcCfg->bTrcToFile = bTrcToFile;
|
||||
if (bTrcToFile) {
|
||||
ret = snprintf_s(pTrcCxt->pTrcCfg->filePath, MAX_PATH_LEN, MAX_PATH_LEN - 1, "%s", trcFile);
|
||||
securec_check_ss_c(ret, "\0", "\0");
|
||||
int rc = snprintf_s(pTrcCxt->pTrcCfg->filePath, MAX_PATH_LEN, MAX_PATH_LEN - 1, "%s", trcFile);
|
||||
securec_check_ss_c(rc, "\0", "\0");
|
||||
ret = TRACE_OK;
|
||||
}
|
||||
pTrcCxt->pTrcCfg->status = TRACE_STATUS_RECORDING;
|
||||
@ -545,19 +544,17 @@ int gstrace_start(int key, const char* mask, uint64_t bufferSize, const char* tr
|
||||
return ret;
|
||||
}
|
||||
|
||||
int gstrace_stop(int key)
|
||||
trace_msg_code gstrace_stop(int key)
|
||||
{
|
||||
char sBufMemName[TRC_SHARED_MEM_NAME_MAX] = {0};
|
||||
trace_context* pTrcCxt = getTraceContext();
|
||||
|
||||
if (attachTraceCfgSharedMem(key) != TRACE_OK) {
|
||||
printf("Failed to attached to shared memory.\n");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_ATTACH_CFG_SHARE_MEMORY_ERR;
|
||||
}
|
||||
|
||||
if (!pTrcCxt->pTrcCfg->bEnabled || pTrcCxt->pTrcCfg->status != TRACE_STATUS_RECORDING) {
|
||||
printf("Trace had already been deactived.\n");
|
||||
return TRACE_OK;
|
||||
return TRACE_ALREADY_STOP;
|
||||
}
|
||||
|
||||
pTrcCxt->pTrcCfg->status = TRACE_STATUS_PREPARE_STOP;
|
||||
@ -572,8 +569,7 @@ int gstrace_stop(int key)
|
||||
|
||||
if (shm_unlink(sBufMemName) == -1) {
|
||||
perror("shm_unlink");
|
||||
printf("Failed to delete shared memory.\n");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_UNLINK_SHARE_MEMORY_ERR;
|
||||
}
|
||||
|
||||
pTrcCxt->pTrcCfg->size = 0;
|
||||
@ -877,7 +873,7 @@ void gstrace_tryblock_exit(bool inCatch, int* oldTryCounter)
|
||||
gtCurTryCounter = oldTryCounter;
|
||||
}
|
||||
|
||||
static int dump_trace_context(int fd)
|
||||
static trace_msg_code dump_trace_context(int fd)
|
||||
{
|
||||
trace_context* pTrcCxt = getTraceContext();
|
||||
size_t bytesWritten;
|
||||
@ -885,21 +881,19 @@ static int dump_trace_context(int fd)
|
||||
// Write the trace config header first
|
||||
bytesWritten = write(fd, (void*)pTrcCxt->pTrcCfg, sizeof(trace_config));
|
||||
if (bytesWritten != sizeof(trace_config)) {
|
||||
printf("Failed to write trace config header\n");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_WRITE_CFG_HEADER_ERR;
|
||||
}
|
||||
|
||||
// Write the trace buffer header next
|
||||
bytesWritten = write(fd, (void*)pTrcCxt->pTrcInfra, sizeof(trace_infra));
|
||||
if (bytesWritten != sizeof(trace_infra)) {
|
||||
printf("Failed to write trace header\n");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_WRITE_BUFFER_HEADER_ERR;
|
||||
} else {
|
||||
return TRACE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
static int dump_trace_buffer(int fd, const char* outPath)
|
||||
static trace_msg_code dump_trace_buffer(int fd, const char* outPath)
|
||||
{
|
||||
trace_context* pTrcCxt = getTraceContext();
|
||||
size_t bytesWritten, bytesToWrite;
|
||||
@ -911,8 +905,7 @@ static int dump_trace_buffer(int fd, const char* outPath)
|
||||
bytesToWrite = pTrcCxt->pTrcInfra->total_size - sizeof(trace_infra);
|
||||
bytesWritten = write(fd, pBuf, bytesToWrite);
|
||||
if (bytesWritten != bytesToWrite) {
|
||||
printf("Failed to write trace buffer \n");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_WRITE_BUFFER_ERR;
|
||||
} else {
|
||||
printf("Shared memory buffer has been dumped to file: %s.\n", outPath);
|
||||
return TRACE_OK;
|
||||
@ -929,31 +922,27 @@ static int dump_trace_buffer(int fd, const char* outPath)
|
||||
// this function will put the dump in
|
||||
// "tmp/trace_dump"
|
||||
// -------------------------------------------
|
||||
int gstrace_dump(int key, const char* outPath)
|
||||
trace_msg_code gstrace_dump(int key, const char* outPath)
|
||||
{
|
||||
trace_context* pTrcCxt = getTraceContext();
|
||||
int ret;
|
||||
trace_msg_code ret;
|
||||
|
||||
if (attachTraceCfgSharedMem(key) != TRACE_OK) {
|
||||
printf("Failed to attached to shared memory.\n");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_ATTACH_CFG_SHARE_MEMORY_ERR;
|
||||
}
|
||||
|
||||
if (!pTrcCxt->pTrcCfg->bEnabled) {
|
||||
printf("trace is disable.\n");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_DISABLE_ERR;
|
||||
}
|
||||
|
||||
if (attachTraceBufferSharedMem(key) != TRACE_OK) {
|
||||
printf("failed to attach to trace buffer shared mem\n");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_ATTACH_BUFFER_SHARE_MEMORY_ERR;
|
||||
}
|
||||
|
||||
// open output file
|
||||
int fd = trace_open_filedesc(outPath, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU);
|
||||
if (fd == -1) {
|
||||
printf("Failed to open file\n");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_OPEN_OUTPUT_FILE_ERR;
|
||||
}
|
||||
|
||||
ret = dump_trace_context(fd);
|
||||
@ -981,7 +970,7 @@ static char* getStatusString(int status)
|
||||
}
|
||||
}
|
||||
|
||||
int gstrace_config(int key)
|
||||
trace_msg_code gstrace_config(int key)
|
||||
{
|
||||
int rc;
|
||||
trace_context* pTrcCxt = getTraceContext();
|
||||
@ -989,7 +978,7 @@ int gstrace_config(int key)
|
||||
rc = attachTraceCfgSharedMem(key);
|
||||
if (rc != TRACE_OK) {
|
||||
printf("Failed to attached to shared memory.\n");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_ATTACH_CFG_SHARE_MEMORY_ERR;
|
||||
}
|
||||
|
||||
if (pTrcCxt->pTrcCfg->bEnabled) {
|
||||
|
@ -1103,41 +1103,38 @@ static void gsTrcFormatOneTraceRecord(
|
||||
}
|
||||
}
|
||||
|
||||
static int readAndCheckTrcMeta(int fdInput, trace_config* trc_cfg, trace_infra* trc_infra)
|
||||
static trace_msg_code readAndCheckTrcMeta(int fdInput, trace_config* trc_cfg, trace_infra* trc_infra)
|
||||
{
|
||||
size_t bytesRead;
|
||||
|
||||
bytesRead = read(fdInput, (void*)trc_cfg, sizeof(trace_config));
|
||||
if (bytesRead != sizeof(trace_config)) {
|
||||
perror("Failed to read trace config.");
|
||||
return TRACE_COMMON_ERROR;
|
||||
perror("read err.");
|
||||
return TRACE_READ_CFG_FROM_FILE_ERR;
|
||||
}
|
||||
|
||||
if ((trc_cfg->size & (trc_cfg->size - 1)) != 0) {
|
||||
perror("invalid buffer size in trace file.");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_BUFFER_SIZE_FROM_FILE_ERR;
|
||||
}
|
||||
|
||||
if (trc_cfg->trc_cfg_magic_no != GS_TRC_CFG_MAGIC_N) {
|
||||
perror("invalid magic number in trace file.");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_MAGIC_FROM_FILE_ERR;
|
||||
}
|
||||
|
||||
bytesRead = read(fdInput, (void*)trc_infra, sizeof(trace_infra));
|
||||
if (bytesRead != sizeof(trace_infra)) {
|
||||
perror("Failed to read trace infra.");
|
||||
return TRACE_COMMON_ERROR;
|
||||
perror("read err.");
|
||||
return TRACE_READ_INFRA_FROM_FILE_ERR;
|
||||
}
|
||||
|
||||
if (trc_infra->g_Counter == 0) {
|
||||
perror("No trace records were captured");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_NO_RECORDS_ERR;
|
||||
}
|
||||
|
||||
return TRACE_OK;
|
||||
}
|
||||
|
||||
static int readAndFormatTrcRec(int fdInput, int fdOutput, uint64_t counter)
|
||||
static trace_msg_code readAndFormatTrcRec(int fdInput, int fdOutput, uint64_t counter)
|
||||
{
|
||||
uint64_t totalNumRecs = 0;
|
||||
char rec_tmp_buf[MAX_TRC_RC_SZ] = {'\0'};
|
||||
@ -1147,20 +1144,18 @@ static int readAndFormatTrcRec(int fdInput, int fdOutput, uint64_t counter)
|
||||
// Read the contents of a the header slot
|
||||
size_t bytesRead = read(fdInput, (void*)&rec_tmp_buf, SLOT_SIZE);
|
||||
if (bytesRead != SLOT_SIZE) {
|
||||
perror("Invalid trace file - faild to read trace slot header");
|
||||
return TRACE_COMMON_ERROR;
|
||||
perror("Invalid trace file");
|
||||
return TRACE_READ_SLOT_HEADER_ERR;
|
||||
}
|
||||
trace_slot_head* pHdr = (trace_slot_head*)rec_tmp_buf;
|
||||
|
||||
// since slots for one record is contiguous, we can do following check.
|
||||
if (pHdr->num_slots_in_area == 0 || pHdr->num_slots_in_area > MAX_TRC_SLOTS) {
|
||||
perror("Invalid trace file - num slot in header is zero.");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_NUM_SLOT_ERR;
|
||||
}
|
||||
|
||||
if (pHdr->hdr_magic_number != SLOT_AREAD_HEADER_MAGIC_NO) {
|
||||
perror("Invalid trace file - num slot in header is zero.");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_SLOT_MAGIC_ERR;
|
||||
}
|
||||
|
||||
if (pHdr->num_slots_in_area > 1 && pHdr->num_slots_in_area <= MAX_TRC_SLOTS) {
|
||||
@ -1169,8 +1164,8 @@ static int readAndFormatTrcRec(int fdInput, int fdOutput, uint64_t counter)
|
||||
|
||||
bytesRead = read(fdInput, (void*)&rec_tmp_buf[SLOT_SIZE], size_to_read);
|
||||
if (bytesRead != size_to_read) {
|
||||
perror("Invalid trace file - faild to read trace slot data.");
|
||||
return TRACE_COMMON_ERROR;
|
||||
perror("Invalid trace file.");
|
||||
return TRACE_READ_SLOT_DATA_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1190,8 +1185,8 @@ static int readAndFormatTrcRec(int fdInput, int fdOutput, uint64_t counter)
|
||||
// now write the buffer to the file
|
||||
size_t bytesWritten = write(fdOutput, rec_out_buf, strlen(rec_out_buf));
|
||||
if (bytesWritten != strlen(rec_out_buf)) {
|
||||
perror("Error while writing formatted trace record");
|
||||
return TRACE_COMMON_ERROR;
|
||||
perror("write error");
|
||||
return TRACE_WRITE_FORMATTED_RECORD_ERR;
|
||||
}
|
||||
totalNumRecs++;
|
||||
}
|
||||
@ -1209,9 +1204,9 @@ static int readAndFormatTrcRec(int fdInput, int fdOutput, uint64_t counter)
|
||||
// the formatted file will be the same name
|
||||
// as the binary file with the extension .fmt
|
||||
// -------------------------------------------
|
||||
static int formatTrcDumpFile(const char* inputPath, const char* outputPath)
|
||||
static trace_msg_code formatTrcDumpFile(const char* inputPath, const char* outputPath)
|
||||
{
|
||||
int ret;
|
||||
trace_msg_code ret;
|
||||
trace_infra trc_infra;
|
||||
trace_config trc_cfg;
|
||||
|
||||
@ -1219,7 +1214,7 @@ static int formatTrcDumpFile(const char* inputPath, const char* outputPath)
|
||||
int fdInput = trace_open_filedesc(inputPath, O_RDONLY, 0);
|
||||
if (fdInput == -1) {
|
||||
perror("Failed to open input file");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_OPEN_INPUT_FILE_ERR;
|
||||
}
|
||||
|
||||
/* Read config header to validate the file and buffer size */
|
||||
@ -1230,7 +1225,7 @@ static int formatTrcDumpFile(const char* inputPath, const char* outputPath)
|
||||
if (fdOutput == -1) {
|
||||
close(fdInput);
|
||||
perror("Failed to open output file");
|
||||
return TRACE_COMMON_ERROR;
|
||||
return TRACE_OPEN_OUTPUT_FILE_ERR;
|
||||
}
|
||||
|
||||
uint64_t maxSlots = trc_cfg.size / SLOT_SIZE;
|
||||
@ -1402,9 +1397,61 @@ static void printUsage(int argc, char** argv)
|
||||
printf("\t-t get statistics for every n seconds, file name will be {global file name}.step\n");
|
||||
}
|
||||
|
||||
trace_msg_t trace_message[] = {
|
||||
{TRACE_OK, "Success!\n"},
|
||||
{TRACE_ALREADY_START, "Trace has already been activated.\n"},
|
||||
{TRACE_ALREADY_STOP, "Trace has already been deactived.\n"},
|
||||
{TRACE_PARAMETER_ERR, "Parameter not correct.\n"},
|
||||
{TRACE_BUFFER_SIZE_ERR, "Invalid share memory buffer size.\n"},
|
||||
{TRACE_ATTACH_CFG_SHARE_MEMORY_ERR, "Attached to trace config failed.\n"},
|
||||
{TRACE_ATTACH_BUFFER_SHARE_MEMORY_ERR, "Attached to trace buffer failed.\n"},
|
||||
{TRACE_OPEN_SHARE_MEMORY_ERR, "Failed to initialize trace buffer.\n"},
|
||||
{TRACE_TRUNCATE_ERR, "Failed to set size of trace buffer.\n"},
|
||||
{TRACE_MMAP_ERR, "Failed to map memory for trace buffer.\n"},
|
||||
{TRACE_UNLINK_SHARE_MEMORY_ERR, "Failed to delete trace buffer.\n"},
|
||||
{TRACE_DISABLE_ERR, "Trace is disable.\n"},
|
||||
{TRACE_OPEN_OUTPUT_FILE_ERR, "Failed to open trace output file.\n"},
|
||||
{TRACE_OPEN_INPUT_FILE_ERR, "Failed to open trace input file.\n"},
|
||||
{TRACE_WRITE_BUFFER_HEADER_ERR, "Failed to write trace buffer header.\n"},
|
||||
{TRACE_WRITE_CFG_HEADER_ERR, "Failed to write trace config header.\n"},
|
||||
{TRACE_WRITE_BUFFER_ERR, "Failed to write trace buffer.\n"},
|
||||
{TRACE_READ_CFG_FROM_FILE_ERR, "Failed to read trace config.\n"},
|
||||
{TRACE_BUFFER_SIZE_FROM_FILE_ERR, "Invalid buffer size in trace file.\n"},
|
||||
{TRACE_MAGIC_FROM_FILE_ERR, "Invalid magic number in trace file.\n"},
|
||||
{TRACE_READ_INFRA_FROM_FILE_ERR, "Failed to read trace infra.\n"},
|
||||
{TRACE_NO_RECORDS_ERR, "No trace records were captured.\n"},
|
||||
{TRACE_READ_SLOT_HEADER_ERR, "Faild to read trace slot header.\n"},
|
||||
{TRACE_NUM_SLOT_ERR, "Invalid trace file, num slot in header is zero.\n"},
|
||||
{TRACE_SLOT_MAGIC_ERR, "Invalid trace file, magic number is not correct.\n"},
|
||||
{TRACE_READ_SLOT_DATA_ERR, "Faild to read trace slot data.\n"},
|
||||
{TRACE_WRITE_FORMATTED_RECORD_ERR, "Failed to write formatted trace record.\n"},
|
||||
{TRACE_MSG_MAX, "Failed!\n"},
|
||||
};
|
||||
|
||||
static void print_result_message(trace_msg_code rc, int argc, char** argv)
|
||||
{
|
||||
if (rc == TRACE_OK) {
|
||||
(void)printf("[GAUSS-TRACE] %s %s", argv[1], trace_message[rc].msg_string);
|
||||
} else if ((rc > TRACE_OK) && (rc < TRACE_MSG_MAX)) {
|
||||
if (rc == trace_message[rc].msg_code) {
|
||||
(void)printf("[GAUSS-TRACE] %s", trace_message[rc].msg_string);
|
||||
} else {
|
||||
(void)printf("[GAUSS-TRACE] Trace failed for error %05d.\n", rc);
|
||||
}
|
||||
} else {
|
||||
(void)printf("[GAUSS-TRACE] %s %s\n", argv[1], trace_message[TRACE_MSG_MAX].msg_string);
|
||||
}
|
||||
|
||||
if (rc == TRACE_PARAMETER_ERR) {
|
||||
printUsage(argc, argv);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int rc = TRACE_OK;
|
||||
trace_msg_code rc = TRACE_OK;
|
||||
int pid;
|
||||
char* trcFile = NULL;
|
||||
char* outputFile = NULL;
|
||||
@ -1414,8 +1461,7 @@ int main(int argc, char** argv)
|
||||
char* mask = NULL;
|
||||
|
||||
if (argc < 2) {
|
||||
printUsage(argc, argv);
|
||||
rc = TRACE_COMMON_ERROR;
|
||||
rc = TRACE_PARAMETER_ERR;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -1433,7 +1479,7 @@ int main(int argc, char** argv)
|
||||
rc = gstrace_start(pid, mask, uBufferSize, trcFile);
|
||||
} else if (0 == strcmp(argv[1], "stop") && pid != -1) {
|
||||
// Stop will disable tracing and delete the shared memory buffer
|
||||
gstrace_stop(pid);
|
||||
rc = gstrace_stop(pid);
|
||||
} else if (0 == strcmp(argv[1], "config") && pid != -1) {
|
||||
rc = gstrace_config(pid);
|
||||
} else if (0 == strcmp(argv[1], "dump") && pid != -1 && outputFile != NULL) {
|
||||
@ -1451,10 +1497,10 @@ int main(int argc, char** argv)
|
||||
/* step stats file will be {outputFile}.step */
|
||||
anlyzeDumpFile(trcFile, strlen(trcFile), outputFile, strlen(outputFile), stepSize);
|
||||
} else {
|
||||
printUsage(argc, argv);
|
||||
rc = TRACE_COMMON_ERROR;
|
||||
rc = TRACE_PARAMETER_ERR;
|
||||
}
|
||||
|
||||
exit:
|
||||
return rc;
|
||||
print_result_message(rc, argc, argv);
|
||||
return (int)rc;
|
||||
}
|
||||
|
Reference in New Issue
Block a user