Bug 108323 - Admin: display up-time ...
Summary: Admin: display up-time ...
Status: NEW
Alias: None
Product: LibreOffice Online
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Depends on:
Blocks: LOOL-Admin-Console
  Show dependency treegraph
 
Reported: 2017-06-03 12:08 UTC by Michael Meeks
Modified: 2019-05-15 02:55 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Meeks 2017-06-03 12:08:06 UTC
It would be great to show the up-time in the admin-console. To do that we should add:

wsd/Admin.cpp:

    else if (tokens[0] == "documents" ||
...
             tokens[0] == "cpu_stats")

    After this an 'if (tokens[0] == "uptime") ...

    We should set a timestamp in the Admin::Admin constructor, and return an offset from that cf.

    std::time_t getElapsedTime() const { return std::time(nullptr) - _start; }

To return some data to this command (update wsd/protocol.txt to document it).

Then we need to hack:

It would be great to show the up-time in the admin-console. To do that we should add:

wsd/Admin.cpp:

    else if (tokens[0] == "documents" ||
...
             tokens[0] == "cpu_stats")

    After this an 'if (tokens[0] == "uptime") ...

    We should set a timestamp in the Admin::Admin constructor, and return an offset from that cf.

    std::time_t getElapsedTime() const { return std::time(nullptr) - _start; }

To return some data to this command (update wsd/protocol.txt to document it).

Then we need to hack:

loleaflet/src/admin/*.js

to emit the request, and also to provide a counting time display - as we have for the existing busy/idle time for documents at the top of the default admin page.

Thanks ! =)
Comment 1 elshreif 2019-03-03 04:42:58 UTC
(In reply to Michael Meeks from comment #0)
> It would be great to show the up-time in the admin-console. To do that we
> should add:
> 
> wsd/Admin.cpp:
> 
>     After this an 'if (tokens[0] == "uptime") ...
> 
>     We should set a timestamp in the Admin::Admin constructor, and return an
> offset from that cf.
> 
>     std::time_t getElapsedTime() const { return std::time(nullptr) - _start;
> }
> 
> To return some data to this command (update wsd/protocol.txt to document it). 
> loleaflet/src/admin/*.js
> 
> to emit the request, and also to provide a counting time display - as we
> have for the existing busy/idle time for documents at the top of the default
> admin page.
> 
> Thanks ! =)

I can't understand the difference btween this task and the Elapsed time which is already implemented in admin consol
Comment 2 Michael Meeks 2019-03-04 09:59:02 UTC
Uptime is much simpler - and is not per document =) "how long has the server been running". Should be trivial to add that to a line above the "Documents opened" tab.
Comment 3 Komal 2019-03-08 20:12:14 UTC
(In reply to Michael Meeks from comment #0)
> It would be great to show the up-time in the admin-console. To do that we
> should add:
> 
> wsd/Admin.cpp:
> 
>     else if (tokens[0] == "documents" ||
> ...
>              tokens[0] == "cpu_stats")
> 
>     After this an 'if (tokens[0] == "uptime") ...
> 
>     We should set a timestamp in the Admin::Admin constructor, and return an
> offset from that cf.
> 
>     std::time_t getElapsedTime() const { return std::time(nullptr) - _start;
> }
> 
> To return some data to this command (update wsd/protocol.txt to document it).
> 
> Then we need to hack:
> 
> It would be great to show the up-time in the admin-console. To do that we
> should add:
> 
> wsd/Admin.cpp:
> 
>     else if (tokens[0] == "documents" ||
> ...
>              tokens[0] == "cpu_stats")
> 
>     After this an 'if (tokens[0] == "uptime") ...
> 
>     We should set a timestamp in the Admin::Admin constructor, and return an
> offset from that cf.
> 
>     std::time_t getElapsedTime() const { return std::time(nullptr) - _start;
> }
> 
> To return some data to this command (update wsd/protocol.txt to document it).
> 
> Then we need to hack:
> 
> loleaflet/src/admin/*.js
> 
> to emit the request, and also to provide a counting time display - as we
> have for the existing busy/idle time for documents at the top of the default
> admin page.
> 
> Thanks ! =)

Hey Michael, I went through the files. So, do I have to define "uptime", same like how elapsed time is defined in AdminModel.hpp? And how is server time calculated?
Comment 4 Michael Meeks 2019-03-09 17:42:38 UTC
Hey - so, you'll need to come up with a patch that does something here before getting more input. I think you have everything you need. I would look at the std::chrono::steady_time and its conversions and how they are used in the code elsewhere for timestamps - and re-apply that to this problem. More questions ? - lets discuss a prototype patch - even if it doesn't compile.
Comment 5 Komal 2019-03-12 12:50:23 UTC
(In reply to Michael Meeks from comment #4)
> Hey - so, you'll need to come up with a patch that does something here
> before getting more input. I think you have everything you need. I would
> look at the std::chrono::steady_time and its conversions and how they are
> used in the code elsewhere for timestamps - and re-apply that to this
> problem. More questions ? - lets discuss a prototype patch - even if it
> doesn't compile.

Hey Michael, So as far as I went through the files, I feel struct MonitorConnectRecord in Admin.hpp should be the start counter for Uptime. We set some variable say 't1'of type time_point here.We store the time returned from now() in it. And same like how getElapsedTime() is defined in AdminModel.hpp, we define getUptime().While defining we take another variable 't2' and take its value same like t1. The uptime then will be (t2-t1). And about the display part. I coudn't figure how the display file for this in front-end. How do I go about next? Like exact implementation...??
Thanks in advance.
Comment 6 Michael Meeks 2019-03-12 16:41:36 UTC
> Hey Michael, So as far as I went through the files, I feel struct
> MonitorConnectRecord in Admin.hpp should be the start counter for Uptime.

	Why ? did you read what the MonitorConnectRecord is used for ?

> We set some variable say 't1'of type time_point here.We store the
> time returned from now() in it. And same like how getElapsedTime()
> is defined in AdminModel.hpp, we define getUptime().

	Well - you should be able to re-use something like the code
you point at for the server as a whole:

_start(std::time(nullptr)),
std::time_t getElapsedTime() const { return std::time(nullptr) - _start;

> While defining we take another variable 't2' and take its value same
> like t1. The uptime then will be (t2-t1). And about the display
> part.

	Sounds reasonable if you mean what I wrote above.

> I coudn't figure how the display file for this in front-end. How do
> I go about next? Like exact implementation...??  Thanks in advance.

	git grep for some string you see in the Javascript UI.

	But look at: loleaflet/admin/admin.html and
admin/src/AdminSocketOverview.js

        However these were the files I pointed at in the 1st comment. Also - wrt. questions - please read:

https://people.gnome.org/~michael/data/2016-04-29-solving-problems.pdf

	And start writing notes as you read code =)
Comment 7 Komal 2019-03-17 07:40:23 UTC
(In reply to Michael Meeks from comment #6)
> > Hey Michael, So as far as I went through the files, I feel struct
> > MonitorConnectRecord in Admin.hpp should be the start counter for Uptime.
> 
> 	Why ? did you read what the MonitorConnectRecord is used for ?
> 
> > We set some variable say 't1'of type time_point here.We store the
> > time returned from now() in it. And same like how getElapsedTime()
> > is defined in AdminModel.hpp, we define getUptime().
> 
> 	Well - you should be able to re-use something like the code
> you point at for the server as a whole:
> 
> _start(std::time(nullptr)),
> std::time_t getElapsedTime() const { return std::time(nullptr) - _start;
> 
> > While defining we take another variable 't2' and take its value same
> > like t1. The uptime then will be (t2-t1). And about the display
> > part.
> 
> 	Sounds reasonable if you mean what I wrote above.
> 
> > I coudn't figure how the display file for this in front-end. How do
> > I go about next? Like exact implementation...??  Thanks in advance.
> 
> 	git grep for some string you see in the Javascript UI.
> 
> 	But look at: loleaflet/admin/admin.html and
> admin/src/AdminSocketOverview.js
> 
>         However these were the files I pointed at in the 1st comment. Also -
> wrt. questions - please read:
> 
> https://people.gnome.org/~michael/data/2016-04-29-solving-problems.pdf
> 
> 	And start writing notes as you read code =)

Hey Michael,
Sorry for being so haphazard.
1.First of all my consideration that, MonitorConnectRecord is a structure which could calculate Uptime is wrong. It was just a assumption/intuition.
2.I tried tracking code systematically. Although, still not clear.
3.Actually I wanted to understand what "tokens" does in the code?
4.Apart from that, I just found few things. I hope I'm on correct path.
  i) Declare an object of say 'doc' of Document class in Admin Class.(Since Document class has--
      std::time_t getElapsedTime() const { return std::time(nullptr) - _start; } )
  ii) Using this object we write --
        else if (tokens[0] == "uptime")
         {
            std::time_t doc.getElapsedTime() const { return std::time(nullptr) - _start; }
         }
Can it be rough idea? But I have considered uptime and elapsed time same. Is that wrong?
Comment 8 Michael Meeks 2019-03-18 12:03:54 UTC
Hi Komal,

> Sorry for being so haphazard.

Please read my PDF slides. You are deeply into the 'chatty' anti-pattern currently: please work harder.

> 1.First of all my consideration that, MonitorConnectRecord is a structure
> which could calculate Uptime is wrong. It was just a assumption/intuition.

Right. So of course you should code-read, and do your research to make sure that your intuitions are correct. You fall into the same hole several times below: you need to fix this. Correcting erroneous assumptions is very time consuming.

> 2.I tried tracking code systematically. Although, still not clear.

So - read more of it =) read the trace files that come out - try to follow the code flow.

> 3.Actually I wanted to understand what "tokens" does in the code?

Seriously ? please read the code. Read the README files, and the protocol.txt may help you too. Can you run 'online' and does it work for you ? if so you can add your own debug / trace printouts to follow and undersatnd the code and data flow.

> 4.Apart from that, I just found few things. I hope I'm on correct path.
>  i) Declare an object of say 'doc' of Document class in Admin Class.(Since Document class has--

What do you think this class represents ? in what way is it related to the concept of up-time. Some of that code does something like what you want which is why I pointed you at it.

> Can it be rough idea? But I have considered uptime and elapsed time
> same. Is that wrong?

https://en.wikipedia.org/wiki/Uptime

Worth grasping the concept of uptime I think. This is an easy-ish hack.

Before asking the next question - please attach your log of all of your notes from code-reading, fragments of log-file, and break-down of the problem description and so on so I can verify your work to date.

Thanks,

Michael.
Comment 9 Komal 2019-03-24 01:07:48 UTC
(In reply to Michael Meeks from comment #8)
> Hi Komal,
> 
> > Sorry for being so haphazard.
> 
> Please read my PDF slides. You are deeply into the 'chatty' anti-pattern
> currently: please work harder.
> 
> > 1.First of all my consideration that, MonitorConnectRecord is a structure
> > which could calculate Uptime is wrong. It was just a assumption/intuition.
> 
> Right. So of course you should code-read, and do your research to make sure
> that your intuitions are correct. You fall into the same hole several times
> below: you need to fix this. Correcting erroneous assumptions is very time
> consuming.
> 
> > 2.I tried tracking code systematically. Although, still not clear.
> 
> So - read more of it =) read the trace files that come out - try to follow
> the code flow.
> 
> > 3.Actually I wanted to understand what "tokens" does in the code?
> 
> Seriously ? please read the code. Read the README files, and the
> protocol.txt may help you too. Can you run 'online' and does it work for you
> ? if so you can add your own debug / trace printouts to follow and
> undersatnd the code and data flow.
> 
> > 4.Apart from that, I just found few things. I hope I'm on correct path.
> >  i) Declare an object of say 'doc' of Document class in Admin Class.(Since Document class has--
> 
> What do you think this class represents ? in what way is it related to the
> concept of up-time. Some of that code does something like what you want
> which is why I pointed you at it.
> 
> > Can it be rough idea? But I have considered uptime and elapsed time
> > same. Is that wrong?
> 
> https://en.wikipedia.org/wiki/Uptime
> 
> Worth grasping the concept of uptime I think. This is an easy-ish hack.
> 
> Before asking the next question - please attach your log of all of your
> notes from code-reading, fragments of log-file, and break-down of the
> problem description and so on so I can verify your work to date.
> 
> Thanks,
> 
> Michael.

Hey Michael,
I am not able to run online yet. So,it is very difficult to understand the flow. 
I asked at the IRC channel, but still running with alot many errors. :(
Comment 10 Michael Meeks 2019-03-25 13:12:42 UTC
Well - please grab  me on IRC: 'mmeeks' or 'kendy' can help too.