Skip to content

chaosblade 1.7.4 not work for c++ application function Delay #1253

Description

@perrynzhou

Issue Description

Type: bug report , feature request or question

Describe what happened (or what feature you want)

  • when i inject delay for c++ method ,it not work.my command such as
./blade  prepare cplus -i 127.0.0.1  -p 9703
./blade create cplus delay \
  --fileLocateAndName /nvm_pool/data/cplus/example_server \
  --breakLine example_server.cc:24 \
  --delayDuration 2000 \
  --processName example_server \
  --forkMode parent
  • example_server.cc
#include <iostream>
#include <unistd.h>
#include <sys/time.h>
#include <cstring>
#include <ctime>
#include <fcntl.h>
#include <string.h>
void time_to_str(const char *str, int fd)
{
    std::time_t now = std::time(nullptr);

    std::tm *local_time = std::localtime(&now);
    char time_str[128] = {'\0'};
    snprintf((char *)&time_str, 128, "%s", str);
    size_t len = strlen((char *)&time_str);
    std::strftime((char *)&time_str + len, sizeof(time_str) - len, "%Y-%m-%d %H:%M:%S\n", local_time);

    write(fd, &time_str, 128);
    // std::cout << str << time_str << std::endl;
}
void handleRequest(int *requestId, int fd)
{
    // 模拟一些处理时间
    usleep(100000); // 0.1秒
    char done_str[128] = {'\0'};
    sprintf((char *)&done_str, "done  request-%ld", *requestId);
    write(fd, &done_str, 128);
    // std::cout << done_str << std::endl;
}

int main()
{

    int fd = open("/tmp/1.log", O_CREAT | O_TRUNC | O_RDWR | O_SYNC | O_APPEND);
    int requestCount = 0;
    while (true)
    {
        requestCount++;
        time_to_str("***handleRequest开始处理时间:", fd);
        handleRequest(&requestCount, fd);
        time_to_str("***handleRequest结束处理时间:", fd);
    }
    return 0;
}

Describe what you expected to happen

How to reproduce it (as minimally and precisely as possible)

Tell us your environment

Anything else we need to know?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions