将编写 C 代码的文件从 IDE 迁移到 LoadRunner 时,我们需要进行哪些修改?

What are the modifications that we need to make while migrating a file writing C code from IDE to LoadRunner?

以下代码在 Codeblocks IDE 中运行良好。当我将它粘贴到 LoadRunner 的 action() 中时,出现以下编译错误:

Action.c (7): undeclared identifier FILE'

Action.c (7): undeclared identifier fptr' d:\bits\heyo\

combined_heyo.c (5): 2 errors, not writing pre_cci.ci

这是我的代码:

#include "stdio.h"

int main() {
    char c[1000] = {"abcd"}; //Initialize a character array
    FILE *fptr;
    fptr=fopen("c:\program.txt","w");
    if(fptr==NULL){
        printf("Error!");
        exit(1);
    }
    fprintf(fptr,"%s",c);
    fclose(fptr);
    return 0;
}

在负载下从您的虚拟用户写入文件是一个非常糟糕的主意。不仅是这个用户,所有用户 运行 都是这个虚拟用户。您将对来自 tens/dozens/hundreds 用户的写头访问进行大量争用。这也会将本地文件系统变成负载生成器的瓶颈。

考虑将您写入的数据放在基于外部服务的存储库中,例如队列,如果需要,您可以从中提取数据。在测试期间导致写出数据的最常见愿望是将数据传递给另一个用户。如果这是你的愿望,那么请考虑 RabbitMQ 或类似的

/*my mistake was that i used FILE instead of long, this is because the structure file is included in "stdio.h" file which cant be included by typing # include statement in loadrunner , this was caught when i saw th function reference for fprintf() in loadrunner help. Although this code works but should be avoided running with multiple users (see james pulley answer for more details)*/

/*corrected code*/




vuser_init()
{
char *filename = "c:\helloworld.txt";
char c[1000] = {"abcd"};

long file;

   file=fopen(filename,"w");



   fprintf(file,"%s",c);

   fclose(file);

return 0;
}