Can HttpMetric set time directly without calling start/stop? - firebase-performance

For a cleaner code style, I just want to know is there a way to set HttpMetric time attribute directly not using start() or stop().
Because I can get the time directly, and don't want to add any start/stop listener for it.
I've found HttpMetric has a putAttribute method, so I guess it is possible to set the time directly.

According to the documentation https://firebase.google.com/docs/perf-mon/get-started-android#manual-network, this is not possible. Using start() and stop() is the recommended way of using HTTPMetric.

Related

How to perform my actions sequentially with some sleep during it? (C++, winapi)

Dears, here I have a small program need to do below action/processes sequentially. now I do below in one function, seems not good:)
init user interface, clear EDIT box, Listview; init the buttons status and so on;
power supply my devices;
need 20seconds sleep or timer, because the device need time for startup;
connect with device, read some data from it;
need 3seconds to wait feedback from device;
got reply from device, decode the data and show them on user interface;
...
For now, I just use sleep() in my program, and do the above steps one by one.
Fortunately, know from stackoverflow that my current way is not good, the feedback and user interface update is very slow, and sometimes, the program even freeze, quite stupid.
And some senior guys told me, I should use timer instead of sleep.
So, my question is:
how to use timer in my current program? (just do it like the MSDN say?)
How can I improve it base on above requirement?
Do I need multithread for it?
Sorry for so many questions:)
Indeed I want to get everything better.
Thank you very much in advance.
You don't specify if you are using a specific framework so I am going to assume a windows application using the native windows API directly:
Call SetTimer passing it your window handle (HWND), and the desired timer interval, and NULL for the TimerProc.
Your window procedure will now periodically be posted WM_TIMER message - you can use the ID parameter you passed to SetTimer in the case you have initiated multiple timers - and to eventually KillTimer when you no longer need it.

postgresql query c++ callback

Is it possible with any existing c++ library to implement a callback that returns when a query is completed?
I've found this, but I'm not sure if that's what I want.
I'd like to wait the boost::thread writing to the database until the write is completed.
If this is possible, please link the library and an example.
I was looking for something like this too, ended up doing an async libpq wrapper: http://github.com/metherealone/postgrespp - It uses Boost.ASIO though, not threads. I hope this helps.
From the libpq docs about PQexec function:
Submits a command to the server and waits for the result.
Similar to that, the PQexecParams and PQexecPrepared also wait for the query to be executed. So, using those functions you don't need to worry about waiting, the API will do that for you.
If you need to asynchronously send query to the database, you can use the asynchronous functions.

sleep function inside QThread

Been doing quite a bit of research but can't find the answer to this. I have an application which is built up by creating instances derived from QObject that I move to different threads. In these "threads" I have a QNetworkAccessManager where I do rest request to azure. My issue now is that I have some retry logic that is happening way to quickly. For example, if a container doesn't exists, it needs to be created for the request to be retried (put blob). The issue is if the put blob request happens way too quickly after the container was created, it will fail to upload anything. Also, I would like to increase the time between the reties so that they dont happen to quickly after eachother. What is the best way to force a thread to sleep from within itself?
I'd probably end up using some combination of QTimer and signals/slots. For example:
// Slot
void retry() { ... }
...
// Execute retry code in 1 second:
QTimer::singleShot( 1000, this, SLOT(retry()) );
Use QThread::wait()

Inject sleep() into a function of an external process

I know how to inject a DLL into a running process and also how to utilize functions used internally by the process e.g.
void__stdcall remoteMethod(unsigned short id)
{
typedef void (__stdcall *pFunctionAddress)(unsigned short);
pFunctionAddress pMyFunction = (pFunctionAddress)(0xCAFEBABE);
pMyFunction(id);
}
Now i want to add a sleep() into an existing method in the running process - this is the main loop of the program and doesnt stop for a sec and uses up all processing power.
I know that with frameworks like detours i could make a trampoline function which calls my function and then the original one - however my problem is that the while(1) loop is somewhere within the function of the external process. So i know the offset where the loop starts - and after that i would like to first call sleep() and then continue with the normal route of the loop.
The only alternative i saw so far is binary editing the program but this is not a good solution.
Any suggestion? Thanks
I think you are trying to be too cute here. Just call SuspendThread/ResumeThread alternately on a timer. I know it's ugly, but you aren't going to enter your solution in any beauty pageant I suspect.
Post the name of the spin-waiting program.
Wait for SO-ers to send hate mail to the developer.
Install the update the developer sends you as a bribe to stop the hate mail.
In principle, as long as you've been executed once within the space of the other process, and you know that the loop isn't executing, then you could enabling writing to text pages and patch the actual loop code in situ. You'll need a few redundant bytes to write a call to your function over (extending the function will need a lot of rewriting as all relative offsets will break).
This is not, however, terribly easy nor terribly robust. Consider why you want to to this, and if you can achieve the goal another way.

How to send arbitrary download request to proper handler

I'm building a Qt application and using the QNetworkAccessManager to manager my http requests. Due to the asyncronous nature of QNetworkAccessManager you have to bind a slot to recieve the QNetworkReply when it's done.
I'm new to multithreaded design so I'm not sure how to handle this. I will have 3 seperate types of network replies which need to be parsed in the bound slot and then passed to the correct handler. One will extract a link, the 2nd will extract a picture, and the third will parse a post request's reply to verify that it was successful. All of this takes place within a QWidget subclass.
So, I'm wondering how this is normally handled. As I see it, based purely on intuition as I've done little reading on this specific subject, I would think there are two ways to handle this. One would be to rebind the network manager's finished() signal depending on the call and the other would be to use some sort of state flags and check those to see what the reply is expected to be. What is the preferred method, not necessarily between these two, that's just all I could think of myself, someone more experienced may well have a better solution.
Now, I'm also fairly new to c++, so if the later is the better way what's the best way to handle flags in this case? Would I use a bitset, an enum/flag setting function, or something else? Thanks guys!
If you know the type of reply you're going to get as a result of doing specific request you can connect void QNetworkReply::finished () signal to suitable handler.