Merge pull request #168 from jkriegshauser/improve-import

Improve chrome import
This commit is contained in:
Bartosz Taudul 2021-01-22 14:57:52 +01:00 committed by GitHub
commit ccf441176b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 10 deletions

7
.gitignore vendored
View File

@ -5,6 +5,9 @@
x64 x64
Release Release
Debug Debug
_build
_compiler
tools/*
*.d *.d
*.o *.o
*.so *.so
@ -28,3 +31,7 @@ vcpkg/*
!vcpkg/install_vcpkg_dependencies.bat !vcpkg/install_vcpkg_dependencies.bat
.deps/ .deps/
.dirstamp .dirstamp
.vscode/
/_*/**
/**/__pycache__/**

View File

@ -6,6 +6,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unordered_map>
#include "json.hpp" #include "json.hpp"
@ -56,6 +57,7 @@ int main( int argc, char** argv )
std::vector<tracy::Worker::ImportEventTimeline> timeline; std::vector<tracy::Worker::ImportEventTimeline> timeline;
std::vector<tracy::Worker::ImportEventMessages> messages; std::vector<tracy::Worker::ImportEventMessages> messages;
std::vector<tracy::Worker::ImportEventPlots> plots; std::vector<tracy::Worker::ImportEventPlots> plots;
std::unordered_map<uint64_t, std::string> threadNames;
if( j.is_object() && j.contains( "traceEvents" ) ) if( j.is_object() && j.contains( "traceEvents" ) )
{ {
@ -156,6 +158,13 @@ int main( int argc, char** argv )
} }
} }
} }
else if (type == "M")
{
if (v.contains("name") && v["name"] == "thread_name" && v.contains("args") && v["args"].is_object() && v["args"].contains("name"))
{
threadNames[v["tid"].get<uint64_t>()] = v["args"]["name"].get<std::string>();
}
}
} }
std::stable_sort( timeline.begin(), timeline.end(), [] ( const auto& l, const auto& r ) { return l.timestamp < r.timestamp; } ); std::stable_sort( timeline.begin(), timeline.end(), [] ( const auto& l, const auto& r ) { return l.timestamp < r.timestamp; } );
@ -185,11 +194,15 @@ int main( int argc, char** argv )
printf( "\33[2KProcessing...\r" ); printf( "\33[2KProcessing...\r" );
fflush( stdout ); fflush( stdout );
auto program = input; auto&& getFilename = [](const char* in) {
while( *program ) program++; auto out = in;
program--; while (*out) ++out;
while( program > input && ( *program != '/' || *program != '\\' ) ) program--; --out;
tracy::Worker worker( program, timeline, messages, plots ); while (out > in && (*out != '/' || *out != '\\')) out--;
return out;
};
tracy::Worker worker( getFilename(output), getFilename(input), timeline, messages, plots, threadNames );
auto w = std::unique_ptr<tracy::FileWrite>( tracy::FileWrite::Open( output, clev ) ); auto w = std::unique_ptr<tracy::FileWrite>( tracy::FileWrite::Open( output, clev ) );
if( !w ) if( !w )

View File

@ -275,10 +275,11 @@ Worker::Worker( const char* addr, uint16_t port )
m_threadNet = std::thread( [this] { SetThreadName( "Tracy Network" ); Network(); } ); m_threadNet = std::thread( [this] { SetThreadName( "Tracy Network" ); Network(); } );
} }
Worker::Worker( const std::string& program, const std::vector<ImportEventTimeline>& timeline, const std::vector<ImportEventMessages>& messages, const std::vector<ImportEventPlots>& plots ) Worker::Worker( const char* name, const char* program, const std::vector<ImportEventTimeline>& timeline, const std::vector<ImportEventMessages>& messages, const std::vector<ImportEventPlots>& plots, const std::unordered_map<uint64_t, std::string>& threadNames )
: m_hasData( true ) : m_hasData( true )
, m_delay( 0 ) , m_delay( 0 )
, m_resolution( 0 ) , m_resolution( 0 )
, m_captureName( name )
, m_captureProgram( program ) , m_captureProgram( program )
, m_captureTime( 0 ) , m_captureTime( 0 )
, m_pid( 0 ) , m_pid( 0 )
@ -428,9 +429,19 @@ Worker::Worker( const std::string& program, const std::vector<ImportEventTimelin
for( auto& t : m_threadMap ) for( auto& t : m_threadMap )
{ {
char buf[64]; auto name = threadNames.find(t.first);
sprintf( buf, "%" PRIu64, t.first ); if (name != threadNames.end())
AddThreadString( t.first, buf, strlen( buf ) ); {
char buf[128];
int len = snprintf(buf, sizeof(buf), "(%" PRIu64 ") %s", t.first, name->second.c_str());
AddThreadString(t.first, buf, len);
}
else
{
char buf[64];
sprintf( buf, "%" PRIu64, t.first );
AddThreadString( t.first, buf, strlen( buf ) );
}
} }
m_data.framesBase = m_data.frames.Retrieve( 0, [this] ( uint64_t name ) { m_data.framesBase = m_data.frames.Retrieve( 0, [this] ( uint64_t name ) {
@ -512,6 +523,8 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
char tmp[1024]; char tmp[1024];
f.Read( tmp, sz ); f.Read( tmp, sz );
m_captureName = std::string( tmp, tmp+sz ); m_captureName = std::string( tmp, tmp+sz );
if (m_captureName.empty())
m_captureName = f.GetFilename();
} }
{ {
f.Read( sz ); f.Read( sz );

View File

@ -10,6 +10,7 @@
#include <string> #include <string>
#include <string.h> #include <string.h>
#include <thread> #include <thread>
#include <unordered_map>
#include <vector> #include <vector>
#include "../common/TracyForceInline.hpp" #include "../common/TracyForceInline.hpp"
@ -394,7 +395,7 @@ public:
}; };
Worker( const char* addr, uint16_t port ); Worker( const char* addr, uint16_t port );
Worker( const std::string& program, const std::vector<ImportEventTimeline>& timeline, const std::vector<ImportEventMessages>& messages, const std::vector<ImportEventPlots>& plots ); Worker( const char* name, const char* program, const std::vector<ImportEventTimeline>& timeline, const std::vector<ImportEventMessages>& messages, const std::vector<ImportEventPlots>& plots, const std::unordered_map<uint64_t, std::string>& threadNames );
Worker( FileRead& f, EventType::Type eventMask = EventType::All, bool bgTasks = true ); Worker( FileRead& f, EventType::Type eventMask = EventType::All, bool bgTasks = true );
~Worker(); ~Worker();