Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » C / C++ (GNU/Linux, *NIX, *BSD und Co) » gcc profiling

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
000
02.03.2006, 09:42 Uhr
daxiaoaixad



Hi there,

Hope I am in the right place. I want to ask how to do profiling about system calls? More precisely, I have system calls like:

system("lp inputfile.txt\n")

How can know how much time are spend in this call?

--
daxiaoaixad

Gruesse
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
02.03.2006, 09:53 Uhr
Pler
Einer von Vielen
(Operator)


Hi.

Here is an example which compares the times taken by stdin -> stdout with different buffersizes:

C++:
#include  <sys/times.h>
#include  <sys/stat.h>
#include  <fcntl.h>
#include  "eighdr.h"

#define MAX_PUFFER_GROESSE  1<<20

static void
zeit_ausgabe(long int puff_groesse,
             clock_t realzeit, struct tms *start_zeit, struct tms *ende_zeit,
             long int schleiflaeufe);

int
main(void)
{
   char         puffer[MAX_PUFFER_GROESSE];
   ssize_t      n;
   long int     i, j=0, puffer_groesse;
   struct tms   start_zeit, ende_zeit;
   clock_t      uhr_start, uhr_ende;

   /*------- Ueberschrift fuer Zeittabelle ausgeben ------------------*/
   fprintf(stderr, "+------------+------------+------------"
                   "+------------+------------+\n");
   fprintf(stderr, "| %-10s | %-10s | %-10s | %-10s | %-10s |\n",
                   "Puffer-", "UserCPU", "SystemCPU",
                   "Gebrauchte", "Schleifen-");
   fprintf(stderr, "| %10s | %10s | %10s | %10s | %10s |\n",
                   " groesse", " (Sek)", " (Sek)",
                   " Uhrzeit", " laeufe");
   fprintf(stderr, "+------------+------------+------------"
                   "+------------+------------+\n");

   /*-------- Mit verschiedenen Puffergroessen die gleiche Datei von stdin ----*/
   /*-------- auf stdout kopieren. (Puffergroesse nimmt in Zweierpotenzen zu) -*/
   while (j <= 20) {
      i = 0;
      puffer_groesse = 1<<j;

      if (lseek(STDIN_FILENO, 0L, SEEK_SET) == -1)   /* Schreib/Lesezeiger in     */
         fehler_meld(FATAL_SYS, "Fehler bei lseek"); /* stdin auf Dateianf. setzen*/

      if ( (uhr_start = times(&start_zeit)) == -1)  /* Stoppuhr einschalten */
         fehler_meld(FATAL_SYS, "Fehler bei times");

      while ( (n = read(STDIN_FILENO, puffer, puffer_groesse)) > 0) {
         if (write(STDOUT_FILENO, puffer, n) != n)
            fehler_meld(FATAL_SYS, "Fehler bei write");
         i++;
      }
      if (n < 0)
         fehler_meld(FATAL_SYS, "Fehler bei read");
      
      if ( (uhr_ende = times(&ende_zeit)) == -1)   /* Stoppuhr ausschalten */
         fehler_meld(FATAL_SYS, "Fehler bei times");

      zeit_ausgabe(puffer_groesse, uhr_ende-uhr_start, &start_zeit, &ende_zeit, i);
      j++;
   }
   fprintf(stderr, "+------------+------------+------------"
                   "+------------+------------+\n");
   exit(0);
}

static void
zeit_ausgabe(long int puff_groesse,
             clock_t realzeit, struct tms *start_zeit, struct tms *ende_zeit,
             long int schleiflaeufe)
{
   static long   ticks=0;
  
   if (ticks == 0)
      if ( (ticks = sysconf(_SC_CLK_TCK)) < 0)
         fehler_meld(FATAL_SYS, "Fehler bei sysconf");

   fprintf(stderr, "| %10ld | %10.2lf | %10.2lf | %10.2lf | %10ld |\n",
                   puff_groesse,
                   (ende_zeit->tms_utime - start_zeit->tms_utime) / (double)ticks,
                   (ende_zeit->tms_stime - start_zeit->tms_stime) / (double)ticks,
                   realzeit / (double)ticks, schleiflaeufe);
   return;
}



Quell: Linux/Unix-Systemprogrammierung

Dieser Post wurde am 02.03.2006 um 09:54 Uhr von Pler editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
002
02.03.2006, 10:31 Uhr
daxiaoaixad



Hi,

I don't know whether my problem is clear. I have a c++ programm (say main.cc) in which I have some system calls. I did the profiling which gives me all the time information, except the system calls. Can I use your code to get that information? If yes, could you give me some more explainations? Thank you!



Zitat von Pler:
Hi.

Here is an example which compares the times taken by stdin -> stdout with different buffersizes:
Quell: Linux/Unix-Systemprogrammierung
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
003
02.03.2006, 14:26 Uhr
Pler
Einer von Vielen
(Operator)


I don't know how you are getting the time in your programm.
The Code can be used to get any time.
(real time, no system time)
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
004
02.03.2006, 17:42 Uhr
daxiaoaixad




Zitat von Pler:
I don't know how you are getting the time in your programm.
The Code can be used to get any time.
(real time, no system time)


where can I get the file eighdr.h?
test.cc:4:21: eighdr.h: No such file or directory

Suppose that I have a program main. Do you think it is possible that your programm can get time information of all the called functions if you run main? And how?

thank you
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
005
02.03.2006, 17:49 Uhr
Pler
Einer von Vielen
(Operator)



Zitat:

Suppose that I have a program main. Do you think it is possible that your programm can get time information of all the called functions if you run main? And how?


No
How should my programm know what kind of functions your Programm calls?
Your last post does not agree in your fist post !?


Zitat:

where can I get the file eighdr.h?
test.cc:4:21: eighdr.h: No such file or directory



This is an own collection of functions writen by the author of the book. You can substitute it by perror() and exit().

Dieser Post wurde am 02.03.2006 um 17:49 Uhr von Pler editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ C / C++ (GNU/Linux, *NIX, *BSD und Co) ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: