/ Check-in [3ad96dbe]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improvements to OS layer tracing on the unix backend. (CVS 3664)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3ad96dbe09b99bd5f623de0de3072a25e9e2bc17
User & Date: drh 2007-02-27 02:01:14
Context
2007-02-28
04:47
Add the undocumented and experimental I/O tracing interface. This interface is likely to change and may be completely abandoned in the near future. (CVS 3665) check-in: 007ca283 user: drh tags: trunk
2007-02-27
02:01
Improvements to OS layer tracing on the unix backend. (CVS 3664) check-in: 3ad96dbe user: drh tags: trunk
2007-02-24
15:29
Add comments to sqlite3ExprCompare() to clarify its operation. Ticket #2216. (CVS 3663) check-in: fba0a1e5 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/os_unix.c.

   997    997   /*
   998    998   ** Seek to the offset in id->offset then read cnt bytes into pBuf.
   999    999   ** Return the number of bytes actually read.  Update the offset.
  1000   1000   */
  1001   1001   static int seekAndRead(unixFile *id, void *pBuf, int cnt){
  1002   1002     int got;
  1003   1003     i64 newOffset;
         1004  +  TIMER_START;
  1004   1005   #ifdef USE_PREAD
  1005   1006     got = pread(id->h, pBuf, cnt, id->offset);
  1006   1007   #else
  1007   1008     newOffset = lseek(id->h, id->offset, SEEK_SET);
  1008   1009     if( newOffset!=id->offset ){
  1009   1010       return -1;
  1010   1011     }
  1011   1012     got = read(id->h, pBuf, cnt);
  1012   1013   #endif
         1014  +  TIMER_END;
         1015  +  TRACE5("READ    %-3d %5d %7lld %d\n", id->h, got, id->offset, TIMER_ELAPSED);
  1013   1016     if( got>0 ){
  1014   1017       id->offset += got;
  1015   1018     }
  1016   1019     return got;
  1017   1020   }
  1018   1021   
  1019   1022   /*
................................................................................
  1020   1023   ** Read data from a file into a buffer.  Return SQLITE_OK if all
  1021   1024   ** bytes were read successfully and SQLITE_IOERR if anything goes
  1022   1025   ** wrong.
  1023   1026   */
  1024   1027   static int unixRead(OsFile *id, void *pBuf, int amt){
  1025   1028     int got;
  1026   1029     assert( id );
  1027         -  TIMER_START;
  1028   1030     got = seekAndRead((unixFile*)id, pBuf, amt);
  1029         -  TIMER_END;
  1030         -  TRACE5("READ    %-3d %5d %7d %d\n", ((unixFile*)id)->h, got,
  1031         -          last_page, TIMER_ELAPSED);
  1032         -  SEEK(0);
  1033   1031     SimulateIOError( got = -1 );
  1034   1032     if( got==amt ){
  1035   1033       return SQLITE_OK;
  1036   1034     }else if( got<0 ){
  1037   1035       return SQLITE_IOERR_READ;
  1038   1036     }else{
  1039   1037       memset(&((char*)pBuf)[got], 0, amt-got);
................................................................................
  1044   1042   /*
  1045   1043   ** Seek to the offset in id->offset then read cnt bytes into pBuf.
  1046   1044   ** Return the number of bytes actually read.  Update the offset.
  1047   1045   */
  1048   1046   static int seekAndWrite(unixFile *id, const void *pBuf, int cnt){
  1049   1047     int got;
  1050   1048     i64 newOffset;
         1049  +  TIMER_START;
  1051   1050   #ifdef USE_PREAD
  1052   1051     got = pwrite(id->h, pBuf, cnt, id->offset);
  1053   1052   #else
  1054   1053     newOffset = lseek(id->h, id->offset, SEEK_SET);
  1055   1054     if( newOffset!=id->offset ){
  1056   1055       return -1;
  1057   1056     }
  1058   1057     got = write(id->h, pBuf, cnt);
  1059   1058   #endif
         1059  +  TIMER_END;
         1060  +  TRACE5("WRITE   %-3d %5d %7lld %d\n", id->h, got, id->offset, TIMER_ELAPSED);
  1060   1061     if( got>0 ){
  1061   1062       id->offset += got;
  1062   1063     }
  1063   1064     return got;
  1064   1065   }
  1065   1066   
  1066   1067   
................................................................................
  1068   1069   ** Write data from a buffer into a file.  Return SQLITE_OK on success
  1069   1070   ** or some other error code on failure.
  1070   1071   */
  1071   1072   static int unixWrite(OsFile *id, const void *pBuf, int amt){
  1072   1073     int wrote = 0;
  1073   1074     assert( id );
  1074   1075     assert( amt>0 );
  1075         -  TIMER_START;
  1076   1076     while( amt>0 && (wrote = seekAndWrite((unixFile*)id, pBuf, amt))>0 ){
  1077   1077       amt -= wrote;
  1078   1078       pBuf = &((char*)pBuf)[wrote];
  1079   1079     }
  1080         -  TIMER_END;
  1081         -  TRACE5("WRITE   %-3d %5d %7d %d\n", ((unixFile*)id)->h, wrote,
  1082         -          last_page, TIMER_ELAPSED);
  1083         -  SEEK(0);
  1084   1080     SimulateIOError(( wrote=(-1), amt=1 ));
  1085   1081     SimulateDiskfullError(( wrote=0, amt=1 ));
  1086   1082     if( amt>0 ){
  1087   1083       if( wrote<0 ){
  1088   1084         return SQLITE_IOERR_WRITE;
  1089   1085       }else{
  1090   1086         return SQLITE_FULL;
................................................................................
  1094   1090   }
  1095   1091   
  1096   1092   /*
  1097   1093   ** Move the read/write pointer in a file.
  1098   1094   */
  1099   1095   static int unixSeek(OsFile *id, i64 offset){
  1100   1096     assert( id );
  1101         -  SEEK(offset/1024 + 1);
  1102   1097   #ifdef SQLITE_TEST
  1103   1098     if( offset ) SimulateDiskfullError(return SQLITE_FULL);
  1104   1099   #endif
  1105   1100     ((unixFile*)id)->offset = offset;
  1106   1101     return SQLITE_OK;
  1107   1102   }
  1108   1103