mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-22 22:44:34 +00:00
Switch from cxxopts to getopt for csvexport
This commit is contained in:
parent
276e40ab2a
commit
38cf1b8a70
@ -35,3 +35,4 @@
|
|||||||
<ClCompile Include="..\..\..\zstd\zstd_ldm.c" />
|
<ClCompile Include="..\..\..\zstd\zstd_ldm.c" />
|
||||||
<ClCompile Include="..\..\..\zstd\zstd_opt.c" />
|
<ClCompile Include="..\..\..\zstd\zstd_opt.c" />
|
||||||
<ClCompile Include="..\..\src\csvexport.cpp" />
|
<ClCompile Include="..\..\src\csvexport.cpp" />
|
||||||
|
<ClCompile Include="..\..\..\getopt\getopt.c" />
|
||||||
|
@ -11,12 +11,28 @@
|
|||||||
|
|
||||||
#include "../../server/TracyFileRead.hpp"
|
#include "../../server/TracyFileRead.hpp"
|
||||||
#include "../../server/TracyWorker.hpp"
|
#include "../../server/TracyWorker.hpp"
|
||||||
#include "cxxopts.hpp"
|
#include "getopt.h"
|
||||||
|
|
||||||
|
void print_usage_exit(int e)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Extract statistics from a trace to a CSV format\n");
|
||||||
|
fprintf(stderr, "Usage:\n");
|
||||||
|
fprintf(stderr, " extract [OPTION...] <trace file>\n");
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
fprintf(stderr, " -h, --help Print usage\n");
|
||||||
|
fprintf(stderr, " -f, --filter arg Filter zone names (default: "")\n");
|
||||||
|
fprintf(stderr, " -s, --sep arg CSV separator (default: ,)\n");
|
||||||
|
fprintf(stderr, " -c, --case Case sensitive filtering\n");
|
||||||
|
fprintf(stderr, " -e, --self Get self times\n");
|
||||||
|
fprintf(stderr, " -u, --unwrap Report each zone event\n");
|
||||||
|
|
||||||
|
exit(e);
|
||||||
|
}
|
||||||
|
|
||||||
struct Args {
|
struct Args {
|
||||||
std::string filter;
|
const char* filter;
|
||||||
std::string separator;
|
const char* separator;
|
||||||
std::string trace_file;
|
const char* trace_file;
|
||||||
bool case_sensitive;
|
bool case_sensitive;
|
||||||
bool self_time;
|
bool self_time;
|
||||||
bool unwrap;
|
bool unwrap;
|
||||||
@ -24,61 +40,69 @@ struct Args {
|
|||||||
|
|
||||||
Args parse_args(int argc, char** argv)
|
Args parse_args(int argc, char** argv)
|
||||||
{
|
{
|
||||||
cxxopts::Options options(
|
if (argc == 1)
|
||||||
"extract",
|
|
||||||
"Extract statistics from a trace to a CSV format"
|
|
||||||
);
|
|
||||||
|
|
||||||
std::string filter;
|
|
||||||
std::string separator;
|
|
||||||
std::string trace_file;
|
|
||||||
bool case_sensitive = false;
|
|
||||||
bool self_time = false;
|
|
||||||
bool unwrap = false;
|
|
||||||
|
|
||||||
options.add_options()
|
|
||||||
("h,help", "Print usage")
|
|
||||||
("f,filter", "Filter zone names",
|
|
||||||
cxxopts::value(filter)->default_value(""))
|
|
||||||
("s,separator", "CSV separator",
|
|
||||||
cxxopts::value(separator)->default_value(","))
|
|
||||||
("t,trace", "same as <trace file>",
|
|
||||||
cxxopts::value(trace_file))
|
|
||||||
("case", "Case sensitive filtering",
|
|
||||||
cxxopts::value(case_sensitive))
|
|
||||||
("self", "Get self times",
|
|
||||||
cxxopts::value(self_time))
|
|
||||||
("unwrap", "Report each zone event",
|
|
||||||
cxxopts::value(unwrap))
|
|
||||||
;
|
|
||||||
|
|
||||||
options.positional_help("<trace file>");
|
|
||||||
options.parse_positional("trace");
|
|
||||||
auto result = options.parse(argc, argv);
|
|
||||||
if (result.count("help"))
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s\n", options.help().data());
|
print_usage_exit(1);
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.count("trace") == 0)
|
Args args = { "", ",", "", false, false, false };
|
||||||
{
|
|
||||||
fprintf(stderr, "Requires a trace file");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Args {
|
struct option long_opts[] = {
|
||||||
filter, separator, trace_file, case_sensitive, self_time, unwrap
|
{ "help", no_argument, NULL, 'h' },
|
||||||
|
{ "filter", optional_argument, NULL, 'f' },
|
||||||
|
{ "sep", optional_argument, NULL, 's' },
|
||||||
|
{ "case", no_argument, NULL, 'c' },
|
||||||
|
{ "self", no_argument, NULL, 'e' },
|
||||||
|
{ "unwrap", no_argument, NULL, 'u' },
|
||||||
|
{ NULL, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int c;
|
||||||
|
while ((c = getopt_long(argc, argv, "hf:s:ceu", long_opts, NULL)) != -1)
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case 'h':
|
||||||
|
print_usage_exit(0);
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
args.filter = optarg;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
args.separator = optarg;
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
args.case_sensitive = true;
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
args.self_time = true;
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
args.unwrap = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
print_usage_exit(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc != optind + 1)
|
||||||
|
{
|
||||||
|
print_usage_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
args.trace_file = argv[optind];
|
||||||
|
|
||||||
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_substring(
|
bool is_substring(
|
||||||
const std::string term,
|
const char* term,
|
||||||
const std::string s,
|
const char* s,
|
||||||
bool case_sensitive = false
|
bool case_sensitive = false
|
||||||
){
|
){
|
||||||
std::string new_term = term;
|
auto new_term = std::string(term);
|
||||||
std::string new_s = s;
|
auto new_s = std::string(s);
|
||||||
|
|
||||||
if (!case_sensitive) {
|
if (!case_sensitive) {
|
||||||
std::transform(
|
std::transform(
|
||||||
@ -106,7 +130,7 @@ const char* get_name(int32_t id, const tracy::Worker& worker)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::string join(const T& v, std::string sep) {
|
std::string join(const T& v, const char* sep) {
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
for (const auto& i : v) {
|
for (const auto& i : v) {
|
||||||
if (&i != &v[0]) {
|
if (&i != &v[0]) {
|
||||||
@ -152,11 +176,11 @@ int main(int argc, char** argv)
|
|||||||
Args args = parse_args(argc, argv);
|
Args args = parse_args(argc, argv);
|
||||||
|
|
||||||
auto f = std::unique_ptr<tracy::FileRead>(
|
auto f = std::unique_ptr<tracy::FileRead>(
|
||||||
tracy::FileRead::Open(args.trace_file.data())
|
tracy::FileRead::Open(args.trace_file)
|
||||||
);
|
);
|
||||||
if (!f)
|
if (!f)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Could not open file %s\n", args.trace_file.data());
|
fprintf(stderr, "Could not open file %s\n", args.trace_file);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +201,7 @@ int main(int argc, char** argv)
|
|||||||
if(it->second.total != 0)
|
if(it->second.total != 0)
|
||||||
{
|
{
|
||||||
++total_cnt;
|
++total_cnt;
|
||||||
if(args.filter.empty())
|
if(args.filter[0] == '\0')
|
||||||
{
|
{
|
||||||
slz_selected.push_back_no_space_check(it);
|
slz_selected.push_back_no_space_check(it);
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user