Skip to content

Commit

Permalink
process_explorer is now used instead of process::enumerate() + custom…
Browse files Browse the repository at this point in the history
… container

- setup is now using process table instead of investigating the list of process by itself;
- attach_ui now uses process table provided to select and attach to a process (Attach button is now functional - see issue #81), multiple process attachments are possible;
- process_list is now a model-preparing function, rather than an unrelated model class.
  • Loading branch information
tyoma committed Aug 2, 2022
1 parent 8f057f8 commit 6991ace
Show file tree
Hide file tree
Showing 27 changed files with 286 additions and 438 deletions.
7 changes: 6 additions & 1 deletion explorer/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ namespace micro_profiler
unsigned int cycle;
};

class process_explorer : public sdb::table<process_info>
namespace tables
{
typedef sdb::table<process_info> processes;
}

class process_explorer : public tables::processes
{
public:
process_explorer(mt::milliseconds update_interval, scheduler::queue &apartment_queue);
Expand Down
1 change: 1 addition & 0 deletions explorer/src/process_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace micro_profiler
rec.commit();
}
}
invalidate();
_apartment.schedule([this] { update(); }, _update_interval);
}
}
4 changes: 4 additions & 0 deletions explorer/tests/ProcessExplorerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ namespace micro_profiler
{
// INIT
process_explorer e(mt::milliseconds(1), queue);
auto invalidations = 0;
auto conn = e.invalidate += [&] { invalidations++; };
auto &idx = sdb::multi_index(e, pid());

shared_ptr<running_process> child1 = create_process("./guinea_runner", " \"" + controller_id + "\"");
Expand All @@ -164,6 +166,7 @@ namespace micro_profiler
queue.run_one();

// ASSERT
assert_equal(1, invalidations);
size_t n_children[5] = { 0 };
assert_equal(1u, queue.tasks.size());
assert_equal(mt::milliseconds(1), queue.tasks.back().second);
Expand All @@ -180,6 +183,7 @@ namespace micro_profiler
queue.run_one();

// ASSERT
assert_equal(2, invalidations);
assert_equal(1u, queue.tasks.size());
assert_equal(mt::milliseconds(1), queue.tasks.back().second);
assert_equal(n_children[0], count(idx.equal_range(child1->get_pid())));
Expand Down
4 changes: 4 additions & 0 deletions frontend/columns_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
namespace micro_profiler
{
struct call_statistics;
struct process_info;
struct process_model_context;
struct statistics_model_context;

extern const column_definition<call_statistics, statistics_model_context> c_caller_statistics_columns[9];
extern const column_definition<call_statistics, statistics_model_context> c_statistics_columns[9];
extern const column_definition<call_statistics, statistics_model_context> c_callee_statistics_columns[9];

extern const column_definition<process_info, process_model_context> c_processes_columns[3];
}
7 changes: 7 additions & 0 deletions frontend/constructors.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ namespace micro_profiler
return std::shared_ptr<T>(p, &p->second);
}

template <typename T>
inline T initialize()
{
T value = { };
return value;
}

template <typename T, typename F1>
inline T initialize(const F1 &field1)
{
Expand Down
38 changes: 30 additions & 8 deletions frontend/headers_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#pragma once

#include "column_definition.h"
#include "model_context.h"

#include <vector>
#include <wpl/models.h>
Expand All @@ -34,11 +33,8 @@ namespace micro_profiler
class headers_model : public wpl::headers_model
{
public:
typedef column_definition<call_statistics, statistics_model_context> column;

public:
template <size_t N>
headers_model(const column (&columns)[N], index_type sort_column, bool sort_ascending);
template <typename T, size_t N>
headers_model(T (&columns)[N], index_type sort_column, bool sort_ascending);

void store(hive &configuration) const;
void update(const hive &configuration);
Expand All @@ -52,6 +48,19 @@ namespace micro_profiler
virtual void get_caption(index_type index, agge::richtext_t &caption) const override;
virtual void activate_column(index_type column_) override;

private:
struct column
{
template <typename T, typename CtxT>
column(const column_definition<T, CtxT> &from);

std::string id;
agge::richtext_modifier_t caption;
short int width;
agge::text_alignment alignment;
bool compare, ascending;
};

private:
std::vector<column> _columns;
index_type _sort_column;
Expand All @@ -60,8 +69,21 @@ namespace micro_profiler



template <size_t N>
inline headers_model::headers_model(const column (&columns)[N], index_type sort_column, bool sort_ascending)
template <typename T, typename CtxT>
inline headers_model::column::column(const column_definition<T, CtxT> &from)
: caption(agge::style_modifier::empty)
{
id = from.id;
caption = from.caption;
width = from.width;
alignment = from.alignment;
compare = !!from.compare;
ascending = from.ascending;
}


template <typename T, size_t N>
inline headers_model::headers_model(T (&columns)[N], index_type sort_column, bool sort_ascending)
: _columns(columns, columns + N), _sort_column(sort_column), _sort_ascending(sort_ascending)
{ }
}
4 changes: 4 additions & 0 deletions frontend/model_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ namespace micro_profiler
std::shared_ptr<symbol_resolver> resolver;
bool canonical;
};

struct process_model_context
{
};
}
44 changes: 22 additions & 22 deletions frontend/process_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@

#pragma once

#include <injector/process.h>
#include <vector>
#include "constructors.h"
#include "model_context.h"
#include "table_model_impl.h"

#include <explorer/process.h>
#include <wpl/models.h>

namespace micro_profiler
{
class process_list : public wpl::richtext_table_model
template <>
struct key_traits<process_info>
{
public:
typedef std::function<void (const process::enumerate_callback_t &callback)> process_enumerator_t;

public:
void update(const process_enumerator_t &enumerator);

std::shared_ptr<process> get_process(index_type row) const;
void set_order(index_type column, bool ascending);
typedef id_t key_type;

virtual index_type get_count() const throw() override;
virtual void get_text(index_type row, index_type column, agge::richtext_t &text) const override;
static key_type get_key(const process_info &item)
{ return item.pid; }
};

private:
typedef std::vector< std::shared_ptr<process> > process_container_t;
template <typename U, typename ColumnsT>
inline std::shared_ptr< table_model_impl<wpl::richtext_table_model, U, process_model_context, process_info> > process_list(
std::shared_ptr<U> underlying, const ColumnsT &columns)
{
typedef table_model_impl<wpl::richtext_table_model, U, process_model_context, process_info> model_type;
typedef std::tuple<std::shared_ptr<model_type>, wpl::slot_connection> composite_t;

private:
template <typename PredicateT>
void init_sorter(const PredicateT &p);
const auto m = std::make_shared<model_type>(underlying, initialize<process_model_context>());
const auto c = std::make_shared<composite_t>(m, underlying->invalidate += [m] { m->fetch(); });

private:
std::vector< std::shared_ptr<process> > _processes;
std::function<void (process_container_t &processes)> _sorter;
};
m->add_columns(columns);
return std::shared_ptr<model_type>(c, std::get<0>(*c).get());
}
}
1 change: 0 additions & 1 deletion frontend/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ set(FRONTEND_LIB_SOURCES
frontend_patcher.cpp
headers_model.cpp
image_patch_model.cpp
process_list.cpp
profiling_preferences.cpp
representation.cpp
symbol_resolver.cpp
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/columns_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <frontend/columns_layout.h>

#include <common/formatting.h>
#include <common/path.h>
#include <explorer/process.h>
#include <frontend/constructors.h>
#include <frontend/database.h>
#include <frontend/helpers.h>
Expand Down Expand Up @@ -172,6 +174,32 @@ namespace micro_profiler
template <typename T>
inline format_integer_<T> format_integer(const T &underlying)
{ return initialize< format_integer_<T> >(underlying); }


auto by_process_name = [] (const process_model_context &, const process_info &lhs, const process_info &rhs) {
return strcmp((micro_profiler::operator*)(lhs.path), (micro_profiler::operator*)(rhs.path));
};

auto by_process_pid = [] (const process_model_context &, const process_info &lhs, const process_info &rhs) {
return micro_profiler::compare(lhs.pid, rhs.pid);
};

auto by_process_ppid = [] (const process_model_context &, const process_info &lhs, const process_info &rhs) {
return micro_profiler::compare(lhs.parent_pid, rhs.parent_pid);
};


auto process_name = [] (agge::richtext_t &text, const process_model_context &, size_t, const process_info &item) {
text << (micro_profiler::operator*)(item.path);
};

auto process_pid = [] (agge::richtext_t &text, const process_model_context &, size_t, const process_info &item) {
micro_profiler::itoa<10>(text, item.pid);
};

auto process_ppid = [] (agge::richtext_t &text, const process_model_context &, size_t, const process_info &item) {
micro_profiler::itoa<10>(text, item.parent_pid);
};
}


Expand Down Expand Up @@ -210,4 +238,11 @@ namespace micro_profiler
c_statistics_columns[7],
c_statistics_columns[8],
};


const column_definition<process_info, process_model_context> c_processes_columns[] = {
{ "ProcessExe", "Process\n" + secondary + "executable", 384, agge::align_near, process_name, by_process_name, true, },
{ "ProcessID", "PID" + secondary, 50, agge::align_far, process_pid, by_process_pid, true, },
{ "ParentProcessID", "PID\n" + secondary + "parent", 50, agge::align_far, process_ppid, by_process_ppid, true, },
};
}
1 change: 0 additions & 1 deletion frontend/src/frontend.lib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
<ClCompile Include="frontend_patcher.cpp" />
<ClCompile Include="headers_model.cpp" />
<ClCompile Include="image_patch_model.cpp" />
<ClCompile Include="process_list.cpp" />
<ClCompile Include="profiling_preferences.cpp" />
<ClCompile Include="representation.cpp" />
<ClCompile Include="symbol_resolver.cpp" />
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/frontend.lib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<ClCompile Include="frontend_manager.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="process_list.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="untested\file.cpp">
<Filter>src\untested</Filter>
</ClCompile>
Expand Down
86 changes: 0 additions & 86 deletions frontend/src/process_list.cpp

This file was deleted.

3 changes: 2 additions & 1 deletion frontend/src/untested/image_patch_ui.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <frontend/image_patch_ui.h>

#include <frontend/columns_layout.h>
#include <frontend/headers_model.h>
#include <frontend/image_patch_model.h>
#include <frontend/selection_model.h>
Expand All @@ -18,7 +19,7 @@ namespace micro_profiler
const auto dummy_get = [] (agge::richtext_t &, const statistics_model_context &, size_t, const call_statistics &) {};
const auto dummy_compare = [] (const statistics_model_context &, const call_statistics &, const call_statistics &) { return false; };

const headers_model::column c_columns_symbols[] = {
const column_definition<call_statistics, statistics_model_context> c_columns_symbols[] = {
{ "Rva", "RVA" + secondary, 28, agge::align_far, dummy_get, dummy_compare, true, },
{ "Function", "Function\n" + secondary + "qualified name", 384, agge::align_near, dummy_get, dummy_compare, true, },
{ "Status", "Profiling\n" + secondary + "status", 64, agge::align_near, dummy_get, dummy_compare, false, },
Expand Down
Loading

0 comments on commit 6991ace

Please sign in to comment.